️ This Gitlab will be shut down at 2021-12-31 23:59:59.
Students and staff can migrate to gitlab.utwente.nl.
SNT members can migrate to gitlab.snt.utwente.nl.
Contact bestuur@snt.utwente.nl for more information.

Migrate your projects today!
Export your project using the webinterface or use a script.

Commit 4a1f0c55 authored by TJHeeringa's avatar TJHeeringa

Fix for study and country

parent 2bce1a53
......@@ -30,7 +30,7 @@ const CountryField = (props) => {
return (
<Autocomplete
id={"country-select-demo"}
style={{ width: 300 }}
style={{ width: "100%" }}
options={countries}
classes={{
option: classes.option,
......@@ -61,7 +61,7 @@ const CountryField = (props) => {
export default CountryField;
// From https://bitbucket.org/atlassian/atlaskit-mk-2/raw/4ad0e56649c3e6c973e226b7efaeb28cb240ccb0/packages/core/select/src/data/countries.js
const countries = [
export const countries = [
{ code: "AD", label: "Andorra", phone: "376" },
{ code: "AE", label: "United Arab Emirates", phone: "971" },
{ code: "AF", label: "Afghanistan", phone: "93" },
......
......@@ -5,7 +5,7 @@ import Typography from "@material-ui/core/Typography";
import { Osiris } from "App/Components/Forms/Osiris";
import { getBIC } from "bic-from-iban";
import PropTypes from "prop-types";
import React, {useEffect} from "react";
import React, {useEffect, useMemo} from "react";
import { ValidatorForm } from "react-material-ui-form-validator";
import { useGet } from "restful-react";
......@@ -19,7 +19,7 @@ import Wrapper from "../Fields/Wrapper";
import Block from "../PageLayout/Content/Block";
import isIban from "../ValidatorRules/isIban";
import isTruthy from "../ValidatorRules/isTruthy";
import CountryField from "../Fields/CountryField";
import CountryField, { countries } from "../Fields/CountryField";
const ProfileForm = ({container, ...rest}) => {
......@@ -135,6 +135,7 @@ const ProfileFormWithoutContainer = ({ update, profile, onSuccess, disabled, han
// };
//
console.log(studies, profile.study);
const country = useMemo(()=>countries.find(country=>profile.country === country.label),[profile.country])
return (
<ValidatorForm
......@@ -242,18 +243,13 @@ const ProfileFormWithoutContainer = ({ update, profile, onSuccess, disabled, han
/>
</Wrapper>
<Wrapper>
<TextField
name={"Country"}
value={profile.country}
onChange={(event) => handleProfileChange("country", event.target.value)}
<CountryField
label={"Country"}
value={country}
onChange={(event, value) => handleProfileChange("country", value ? value.label : "")}
disabled={disabled}
required
/>
{/*<CountryField*/}
{/* label={"Country"}*/}
{/* value={profile.country}*/}
{/* onChange={(event, value) => handleProfileChange("country", value.label)}*/}
{/*/>*/}
</Wrapper>
<Typography variant={"h5"}>Education</Typography>
<Wrapper>
......
......@@ -2,7 +2,7 @@ import Info from "App/Components/Info/Info";
import PropTypes from "prop-types";
import React, {useMemo} from "react";
import {useStudies} from "../../Contexts/Members";
import {useStudies} from "../../Contexts/Studies";
const ProfileInfo = ({ profile }) => {
const StudiesApi = useStudies();
......
......@@ -3,7 +3,8 @@ import ExtremeTable from "App/Components/Tables/ExtremeTable";
import PropTypes from "prop-types";
import React, {useMemo} from "react";
import {useDataFields, useMembers, useMemberTypes, useStudies} from "../../Contexts/Members";
import {useDataFields, useMembers, useMemberTypes} from "../../Contexts/Members";
import {useStudies} from "../../Contexts/Studies";
import {
deriveColumnBoundsFromDataFields,
deriveMemberTableHeadersFromDataFields,
......
......@@ -15,10 +15,8 @@ export function useAlertHandler() {
return useContext(AlertHandlerContext);
}
const AlertHandlerProvider = (props) => {
// eslint-disable-next-line react/prop-types
const { children } = props;
// eslint-disable-next-line react/prop-types
const AlertHandlerProvider = ({ children }) => {
const [alertState, setAlertState] = useState({color: undefined, message: "", visible: false});
const handleAlertHandler = (color, message) => {
......
......@@ -7,12 +7,10 @@ import useContextHook from "../Components/Hooks/useContextHook";
const MembersContext = createContext({});
const DataFieldsContext = createContext({});
const MemberTypesContext = createContext({});
const StudiesContext = createContext({});
export const useMembers = () => useContextHook(MembersContext, "useMembers() hook must be used within a Members block");
export const useDataFields = () => useContextHook(DataFieldsContext, "useDataFields() hook must be used within a Members block");
export const useMemberTypes = () => useContextHook(MemberTypesContext, "useMemberTypes() hook must be used within a Members block");
export const useStudies = () => useContextHook(StudiesContext, "useStudies() hook must be used within a Members block");
const Members = ({ children, association, queryParam, immediatelyLoadMembers }) => {
const membersContextValue = useCollectionAPI("/memberships",
......@@ -25,20 +23,15 @@ const Members = ({ children, association, queryParam, immediatelyLoadMembers })
const memberTypesContextValue = useCollectionAPI("/membertypes",
{ association__slug: association.slug, limit: 100 }
);
const StudiesContextValue = useCollectionAPI("/studies",
{ limit: 10000 }
);
return (
<StudiesContext.Provider value={StudiesContextValue}>
<MembersContext.Provider value={membersContextValue}>
<DataFieldsContext.Provider value={dataFieldsContextValue}>
<MemberTypesContext.Provider value={memberTypesContextValue}>
{ children }
</MemberTypesContext.Provider>
</DataFieldsContext.Provider>
</MembersContext.Provider>
</StudiesContext.Provider>
<MembersContext.Provider value={membersContextValue}>
<DataFieldsContext.Provider value={dataFieldsContextValue}>
<MemberTypesContext.Provider value={memberTypesContextValue}>
{ children }
</MemberTypesContext.Provider>
</DataFieldsContext.Provider>
</MembersContext.Provider>
);
};
......
import PropTypes from "prop-types";
import React, {createContext} from "react";
import useCollectionAPI from "../Components/Hooks/useCollectionAPI";
import useContextHook from "../Components/Hooks/useContextHook";
const StudiesContext = createContext({});
export const useStudies = () => useContextHook(StudiesContext, "useStudies() hook must be used within a Members block");
const Studies = ({ children }) => {
const StudiesContextValue = useCollectionAPI("/studies", { limit: 10000 });
return (
<StudiesContext.Provider value={StudiesContextValue}>
{ children }
</StudiesContext.Provider>
);
};
Studies.propTypes = {
// eslint-disable-next-line react/require-default-props
children: PropTypes.node
};
Studies.defaultProps = {
};
export default Studies;
\ No newline at end of file
......@@ -6,12 +6,11 @@ import React from "react";
import { Redirect, Route, Switch } from "react-router-dom";
import { useAPI } from "../../Contexts/API";
import CollectiveCalendar from "../../Pages/Calendar/Old/CollectiveCalendar";
import CampusCard from "../../Pages/Home/CampusCard";
import Studies from "../../Contexts/Studies";
import Home from "../../Pages/Home/Home";
import Settings from "../../Pages/Profile/Settings";
import SharedProfile from "../../Pages/Profile/SharedProfile";
import {Associations} from "../../Pages/Search/Associations";
import { Associations } from "../../Pages/Search/Associations";
import AssociationRoutes from "./MyAssociations/Association";
......@@ -22,11 +21,10 @@ import AssociationRoutes from "./MyAssociations/Association";
* visit when authenticated. Based on the data of the logged in sunmember,
* redirects are done in order to force the user to set mandatory data.
*
* @param props
* @returns {JSX.Element|null}
* @constructor
*/
export const AuthorizedRoutes = (props) => {
export const AuthorizedRoutes = () => {
const { sunmember, refetch } = useAPI();
const url = "/protected";
......@@ -36,14 +34,13 @@ export const AuthorizedRoutes = (props) => {
const number_of_profiles = sunmember.profiles.length;
const preferred_profile_set = sunmember.preferred_profile !== null;
// let claimed_memberships = sunmember.association_memberships.map(membership => ({...membership, status: "Claimed"}));
const claimed_memberships = sunmember.association_memberships.filter(membership => membership.status === "Claimed");
const gotClaimedMemberships = claimed_memberships.length > 0;
const needToMergeProfiles = !preferred_profile_set && number_of_profiles > 0;
const needToCreateProfile = number_of_profiles === 0;
return (
<>
<Studies>
<Switch>
{ gotClaimedMemberships
? <Redirect to={"/protected/memberships/resolve"}/>
......@@ -125,6 +122,6 @@ export const AuthorizedRoutes = (props) => {
/>}
/>
</Switch>
</>
</Studies>
);
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment