️ 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 6617fd68 authored by TJHeeringa's avatar TJHeeringa

Cleaned up some left over/unused components/files

parent 2d0aca2c
......@@ -3,7 +3,7 @@ import TextField from "@material-ui/core/TextField";
import Autocomplete from "@material-ui/lab/Autocomplete";
import React, {useMemo} from "react";
import {useLoadedMembers} from "../../Contexts/Members";
import {useGetCurrentMembersByAssociationQuery} from "../../Store/services/members";
const useStyles = makeStyles({
option: {
......@@ -15,9 +15,9 @@ const useStyles = makeStyles({
},
});
const MemberField = (props) => {
const MemberField = ({ association, ...props }) => {
const classes = useStyles();
const { collection: memberships } = useLoadedMembers();
const { data: memberships } = useGetCurrentMembersByAssociationQuery(association.slug);
const profiles = useMemo(()=>memberships.map(membership=>({
url: membership.profile.url,
......
import Button from "@material-ui/core/Button";
import MenuItem from "@material-ui/core/MenuItem";
import CalendarToday from "@material-ui/icons/CalendarToday";
import DirectionsWalkIcon from "@material-ui/icons/DirectionsWalk";
import TransferWithinAStationIcon from "@material-ui/icons/TransferWithinAStation";
import { pick } from "lodash";
import * as moment from "moment";
import PropTypes from "prop-types";
import React, {useEffect, useMemo} from "react";
import {ValidatorForm} from "react-material-ui-form-validator";
import {useAlertHandler} from "../../Contexts/AlertHandler";
import {useAPI} from "../../Contexts/API";
import {useMemberTypes} from "../../Contexts/Members";
import {useGetMemberTypesByAssociationQuery} from "../../Store/services/memberTypes";
import {DateFieldV2, DateFieldV3} from "../Fields/DateField";
import IconHolder from "../Fields/IconHolder";
import SelectField from "../Fields/SelectField";
import Wrapper from "../Fields/Wrapper";
import useAddValidationRule from "../Hooks/useAddValidationRule";
import isAfterDate from "../ValidatorRules/isAfterDate";
const dataFields = ["date_joined", "date_left", "type", "new_type"];
const membershipWithDatesToApi = (membership) => pick({
...membership,
date_joined: membership.date_joined && moment(membership.date_joined).format("YYYY-MM-DD"),
date_left: membership.date_left && moment(membership.date_left).format("YYYY-MM-DD"),
}, dataFields);
export const MembershipForm = ({ association, membership, handleMembershipChange, onCancel, afterAPIcall }) => {
const alerthandler = useAlertHandler();
const API = useAPI();
const { data: membertypes } = useGetMemberTypesByAssociationQuery(association.slug);
useAddValidationRule(ValidatorForm, isAfterDate.name, isAfterDate.validate(membership.date_joined));
const handleSubmit = () => {
const toBePatchedMembership = membershipWithDatesToApi(membership, dataFields);
API.callv4({
url: membership.url,
queryParams: {expand: "type,new_type"},
method: "PATCH",
object: toBePatchedMembership,
on_succes: (patchedMembership) => {
afterAPIcall(pick(patchedMembership, dataFields));
alerthandler.handleAlertHandler("green", "Saved membership");
},
on_failure: (err) => {
alerthandler.handleAlertHandler("red", "Saving of membership went wrong");
console.error(err);
},
});
};
const dateLeftHelperText = association.is_board && "You cannot change this to a value in the past to prevent " +
"inconstistencies. If you really want to have this at a date in the past contact the helpdesk.";
const currentMembertypeHelperText = useMemo(()=>association.is_board
? "Be careful when changing this. If you have added the membership fee for this member already in a debt " +
"collection it will not be recomputed."
: "Only the board can change this.",
[association.is_board]);
const newMembertypeHelperText = useMemo(()=>membership.date_left
? "What membertype do you want to be next year?"
: "Disabled because you have ended your membership",
[association.date_left]);
const chooseableMemberTypes = useMemo(()=>association.is_board
? membertypes
: membertypes.filter(membertype=>!membertype.only_chooseable_by_board),
[association.is_board, membertypes]);
return (
<ValidatorForm
onSubmit={handleSubmit}
onError={errors => console.log(errors)}
>
<Wrapper>
<IconHolder Icon={CalendarToday}/>
<DateFieldV2
name={"date_joined"}
label={"Date joined"}
value={membership.date_joined}
onChange={date=>handleMembershipChange("date_joined", date)}
disabled
/>
</Wrapper>
<Wrapper>
<IconHolder Icon={CalendarToday}/>
<DateFieldV3
label={"Date left"}
name={"date_left"}
value={membership.date_left}
onChange={date=>handleMembershipChange("date_left", date)}
disabled={!association.is_board}
helperText={dateLeftHelperText}
validators={[isAfterDate.name]}
errorMessages={["Must be a later date than the date the member joined"]}
/>
</Wrapper>
<Wrapper>
<IconHolder Icon={DirectionsWalkIcon}/>
<SelectField
name={"Current Membertype"}
value={membership.type}
onChange={event=>handleMembershipChange("type", event.target.value)}
disabled={!association.is_board}
helperText={currentMembertypeHelperText}
>
{ chooseableMemberTypes && chooseableMemberTypes.map((membertype, m)=>(
<MenuItem key={m} value={membertype.url}>{ membertype.type }</MenuItem>
)) }
</SelectField>
</Wrapper>
<Wrapper>
<IconHolder Icon={TransferWithinAStationIcon}/>
<SelectField
name={"New Membertype"}
value={membership.new_type}
onChange={event=>handleMembershipChange("new_type", event.target.value)}
disabled={membership.date_left !== null}
helperText={newMembertypeHelperText}
>
{ chooseableMemberTypes && chooseableMemberTypes.map((membertype, m)=>(
<MenuItem key={m} value={membertype.url}>{ membertype.type }</MenuItem>
)) }
</SelectField>
</Wrapper>
{ /*<Wrapper>*/ }
{ /* <IconHolder Icon={VisibilityIcon}/>*/ }
{ /* <SelectField*/ }
{ /* name={"Data after end of membership"}*/ }
{ /* value={membership.visible_after_date_left}*/ }
{ /* onChange={event=>handleMembershipChange("visible_after_date_left", event.target.value)}*/ }
{ /* helperText={"What should happen to your data after your membership has ended?"}*/ }
{ /* >*/ }
{ /* <MenuItem value={true}>visible</MenuItem>*/ }
{ /* <MenuItem value={false}>gone</MenuItem>*/ }
{ /* </SelectField>*/ }
{ /*</Wrapper>*/ }
<Wrapper>
<div/>
<div>
<Button type={"submit"} variant={"contained"} color={"primary"}>Save</Button>
&nbsp;
<Button variant={"contained"} onClick={onCancel}>Cancel</Button>
</div>
</Wrapper>
</ValidatorForm>
);
};
MembershipForm.propTypes = {
membership: PropTypes.object.isRequired,
association: PropTypes.object.isRequired,
handleMembershipChange: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
afterAPIcall: PropTypes.func.isRequired
};
import moment from "moment/moment";
import PropTypes from "prop-types";
import React, {useMemo} from "react";
import {useMemberTypes} from "../../Contexts/Members";
import {useGetMemberTypesByAssociationQuery} from "../../Store/services/memberTypes";
import Info from "./Info";
const MembershipInfo = ({ association, membership }) => {
const { data: membertypes, loading } = useGetMemberTypesByAssociationQuery(association.slug);
const morphMembershipToData = (membership) => {
let data = {
"Date Joined:": moment(membership.date_joined).format("L")
};
if (membership.date_left) {
const date_left_or_leaving_text = moment(membership.date_left) <= moment() ? "Date Left:" : "Date Leaving";
data[date_left_or_leaving_text] = moment(membership.date_left).format("L");
}
data["Status"] = membership.status;
if (!loading) {
if (membership.new_type !== null) {
data = {...data,
"Current Membertype:": membertypes?.find(membertype=>membertype.url === membership.type)?.type || "",
"Upcoming Membertype:": membertypes?.find(membertype=>membertype.url === membership.new_type)?.type || ""
};
} else {
data = {...data,
"Membertype:": membertypes?.find(membertype=>membertype.url === membership.type)?.type || "",
};
}
}
return data;
};
const data = useMemo(() => morphMembershipToData(membership), [membership, loading]);
return (
<Info
headerless={true}
data={data}
/>
);
};
MembershipInfo.propTypes = {
membership: PropTypes.object.isRequired
};
export default MembershipInfo;
\ No newline at end of file
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
import PropTypes from "prop-types";
import React from "react";
export const ShortProfile = ({ profile }) => {
return (
<Grid container spacing={3}>
<Grid item>
<Typography>{ profile.given_name } { profile.surname }</Typography>
</Grid>
<Grid item>
<Typography>{ profile.email }</Typography>
</Grid>
</Grid>
);
};
ShortProfile.propTypes = {
profile: PropTypes.object.isRequired
};
\ No newline at end of file
import PropTypes from "prop-types";
import React, {useMemo} from "react";
import {useDataFields} from "../../Contexts/Members";
import {useGetDataFieldsByAssociationQuery} from "../../Store/services/dataFields";
import Info from "./Info";
const SpecificData = ({ specific_data, association }) => {
const { data: dataFields } = useGetDataFieldsByAssociationQuery(association.slug);
const dataFieldToTypeDict = Object.fromEntries(dataFields?.map(dataField=>[dataField.name, dataField.type]) || []);
const data = useMemo(()=>
Object.fromEntries(specific_data.map(sp=>[sp.name, dataFieldToTypeDict[sp.name] === "Boolean"
? (sp.value === "True" ? "Yes" : "No")
: sp.value
]))
,[specific_data, dataFieldToTypeDict]);
return (
<Info
headerless={true}
data={data}
/>
);
};
SpecificData.propTypes = {
specific_data: PropTypes.array.isRequired,
association: PropTypes.object.isRequired
};
export default SpecificData;
\ No newline at end of file
......@@ -2,7 +2,7 @@ import React from "react";
import {useAlertHandler} from "../../Contexts/AlertHandler";
import {useAPI} from "../../Contexts/API";
import InfoForm from "../../InfoForms/InfoForm";
import InfoForm from "../../Forms/InfoForms/InfoForm";
import AssociationForm from "../Forms/AssociationForm";
import AssociationInfo from "../Info/AssociationInfo";
import AssociationType from "../Types/Association";
......
import PropTypes from "prop-types";
import React, {useState} from "react";
import {MembershipForm} from "../Forms/MembershipForm";
import MembershipInfo from "../Info/MembershipInfo";
export const Membership = ({association, membership: propMembership, infoOrForm, toggleInfoOrForm, ...props}) => {
const [membershipChanges, setMembershipChanges] = useState({});
const membership = {...propMembership, ...membershipChanges};
const handleMembershipChange = (field, value) => {
setMembershipChanges(prevState =>({...prevState, [field]: value}));
};
const cancelChanges = () => {
setMembershipChanges({});
toggleInfoOrForm();
};
if (infoOrForm === "info") {
return (
<MembershipInfo
association={association}
membership={membership}
/>
);
} else {
return (
<MembershipForm
association={association}
membership={membership}
handleMembershipChange={handleMembershipChange}
onCancel={cancelChanges}
{...props}
/>
);
}
};
Membership.propTypes = {
infoOrForm: PropTypes.string.isRequired,
membership: PropTypes.object,
toggleInfoOrForm: PropTypes.func
};
Membership.defaultProps = {
membership: {
},
toggleInfoOrForm: ()=>{},
};
\ No newline at end of file
......@@ -19,13 +19,13 @@ import PropTypes from "prop-types";
import React from "react";
import { ValidatorForm } from "react-material-ui-form-validator";
import DateField, {DateFieldV2} from "../../Components/Fields/DateField";
import FileField from "../../Components/Fields/FileField";
import IconHolder from "../../Components/Fields/IconHolder";
import NumberField from "../../Components/Fields/NumberField";
import SelectField from "../../Components/Fields/SelectField";
import TextField from "../../Components/Fields/TextField";
import Wrapper from "../../Components/Fields/Wrapper";
import DateField, {DateFieldV2} from "../../../Components/Fields/DateField";
import FileField from "../../../Components/Fields/FileField";
import IconHolder from "../../../Components/Fields/IconHolder";
import NumberField from "../../../Components/Fields/NumberField";
import SelectField from "../../../Components/Fields/SelectField";
import TextField from "../../../Components/Fields/TextField";
import Wrapper from "../../../Components/Fields/Wrapper";
const GroupForm = ({ onSubmit, onDelete, onCancel, enableDelete, group, parentable_groups, handleGroupChange }) => {
......
......@@ -2,7 +2,7 @@ import * as moment from "moment/moment";
import PropTypes from "prop-types";
import React from "react";
import Info from "../../Components/Info/Info";
import Info from "../../../Components/Info/Info";
const GroupInfo = ({ group }) => {
......
......@@ -2,9 +2,9 @@ import * as moment from "moment";
import PropTypes from "prop-types";
import React from "react";
import withExtraProps from "../../Components/HOC/withExtraProps";
import withPropMap from "../../Components/HOC/withPropMap";
import {useAddGroupMutation, useDeleteGroupMutation,usePatchGroupMutation} from "../../Store/services/groups";
import withExtraProps from "../../../Components/HOC/withExtraProps";
import withPropMap from "../../../Components/HOC/withPropMap";
import {useAddGroupMutation, useDeleteGroupMutation,usePatchGroupMutation} from "../../../Store/services/groups";
import InfoForm from "../InfoForm";
import GroupForm from "./GroupForm";
import GroupInfo from "./GroupInfo";
......
......@@ -3,9 +3,9 @@ import Typography from "@material-ui/core/Typography";
import PropTypes from "prop-types";
import React, {useCallback, useState} from "react";
import Wrapper from "../Components/Fields/Wrapper";
import useInfoFormState from "../Components/Hooks/useInfoFormState";
import Block from "../Components/PageLayout/Content/Block";
import Wrapper from "../../Components/Fields/Wrapper";
import useInfoFormState from "../../Components/Hooks/useInfoFormState";
import Block from "../../Components/PageLayout/Content/Block";
const dummyFunction = () => {};
const defaultFieldAndValueToStateChanges = (field, value, prevState) => ({...prevState, [field]: value});
......
......@@ -7,13 +7,13 @@ import PropTypes from "prop-types";
import React, {useMemo} from "react";
import {ValidatorForm} from "react-material-ui-form-validator";
import {DateFieldV2, DateFieldV3} from "../../Components/Fields/DateField";
import IconHolder from "../../Components/Fields/IconHolder";
import SelectField from "../../Components/Fields/SelectField";
import Wrapper from "../../Components/Fields/Wrapper";
import useAddValidationRule from "../../Components/Hooks/useAddValidationRule";
import isAfterDate from "../../Components/ValidatorRules/isAfterDate";
import {useGetMemberTypesByAssociationQuery} from "../../Store/services/memberTypes";
import {DateFieldV2, DateFieldV3} from "../../../Components/Fields/DateField";
import IconHolder from "../../../Components/Fields/IconHolder";
import SelectField from "../../../Components/Fields/SelectField";
import Wrapper from "../../../Components/Fields/Wrapper";
import useAddValidationRule from "../../../Components/Hooks/useAddValidationRule";
import isAfterDate from "../../../Components/ValidatorRules/isAfterDate";
import {useGetMemberTypesByAssociationQuery} from "../../../Store/services/memberTypes";
const MembershipForm = ({ association, membership, handleMembershipChange, onSubmit, onCancel }) => {
const { data: membertypes } = useGetMemberTypesByAssociationQuery(association.slug);
......
......@@ -2,8 +2,8 @@ import moment from "moment/moment";
import PropTypes from "prop-types";
import React, {useMemo} from "react";
import Info from "../../Components/Info/Info";
import {useGetMemberTypesByAssociationQuery} from "../../Store/services/memberTypes";
import Info from "../../../Components/Info/Info";
import {useGetMemberTypesByAssociationQuery} from "../../../Store/services/memberTypes";
const MembershipInfo = ({ association, membership }) => {
const { data: membertypes, loading } = useGetMemberTypesByAssociationQuery(association.slug);
......
......@@ -2,10 +2,10 @@ import * as moment from "moment";
import PropTypes from "prop-types";
import React from "react";
import withExtraProps from "../../Components/HOC/withExtraProps";
import withPropMap from "../../Components/HOC/withPropMap";
import {usePatchMembershipMutation} from "../../Store/services/members";
import {usePatchMyMembershipMutation} from "../../Store/services/user";
import withExtraProps from "../../../Components/HOC/withExtraProps";
import withPropMap from "../../../Components/HOC/withPropMap";
import {usePatchMembershipMutation} from "../../../Store/services/members";
import {usePatchMyMembershipMutation} from "../../../Store/services/user";
import InfoForm from "../InfoForm";
import MembershipForm from "./MembershipForm";
import MembershipInfo from "./MembershipInfo";
......
......@@ -4,9 +4,9 @@ import PropTypes from "prop-types";
import React from "react";
import {ValidatorForm} from "react-material-ui-form-validator";
import SpecificDataField from "../../Components/Fields/SpecificDataField";
import Wrapper from "../../Components/Fields/Wrapper";
import {useGetDataFieldsByAssociationQuery} from "../../Store/services/dataFields";
import SpecificDataField from "../../../Components/Fields/SpecificDataField";
import Wrapper from "../../../Components/Fields/Wrapper";
import {useGetDataFieldsByAssociationQuery} from "../../../Store/services/dataFields";
export const SpecificDataForm = ({ specificData, handleSpecificDataChange, association, onSubmit, onCancel}) => {
......
import PropTypes from "prop-types";
import React, {useMemo} from "react";
import Info from "../../Components/Info/Info";
import {useGetDataFieldsByAssociationQuery} from "../../Store/services/dataFields";
import Info from "../../../Components/Info/Info";
import {useGetDataFieldsByAssociationQuery} from "../../../Store/services/dataFields";
const SpecificData = ({ specificData, association }) => {
const { data: dataFields } = useGetDataFieldsByAssociationQuery(association.slug);
......
import * as moment from "moment";
import PropTypes from "prop-types";
import React from "react";
import withExtraProps from "../../Components/HOC/withExtraProps";
import withPropMap from "../../Components/HOC/withPropMap";
import {usePatchSpecificDataMutation} from "../../Store/services/members";
import {usePatchMySpecificDataMutation} from "../../Store/services/user";
import withExtraProps from "../../../Components/HOC/withExtraProps";
import withPropMap from "../../../Components/HOC/withPropMap";
import {usePatchSpecificDataMutation} from "../../../Store/services/members";
import {usePatchMySpecificDataMutation} from "../../../Store/services/user";
import InfoForm from "../InfoForm";
import SpecificDataForm from "./SpecificDataForm";
import SpecificDataInfo from "./SpecificDataInfo";
......@@ -25,9 +24,7 @@ const SpecificDataInfoForm = ({ specificData, showInfoFormStateButton, initialIn
return { [index]: { ...specificData[index], value: value, hasBeenChanged: true} };
};
const onSubmit = (submittedSpecificData) => {
console.log("Submitting!", submittedSpecificData);
const changedSpecificData = Object.values(submittedSpecificData).filter(data=> data.hasBeenChanged);
console.log("Actually only: ", changedSpecificData, is_you);
if (is_you) {
changedSpecificData.forEach(changedData=>patchMySpecificData(changedData));
} else {
......@@ -42,8 +39,6 @@ const SpecificDataInfoForm = ({ specificData, showInfoFormStateButton, initialIn
is_you: is_you
});
console.log("specificData", specificData);
return (
<InfoForm
onSubmit={onSubmit}
......
......@@ -37,14 +37,14 @@ import ImportModal from "../Calendar/ImportModal";
/* eslint-disable no-shadow */
const Popup = ({ row, onChange, onApplyChanges, onCancelChanges, open }) => {
const { collection: memberships } = useLoadedMembers();
const profiles = useMemo(()=>memberships.map(membership=>({
url: membership.profile.url,
label: membership.profile.given_name + " " + membership.profile.surname + " (" + membership.profile.student_number + ")"
})), [memberships]);
const profile = useMemo(()=>profiles.find(profile=>profile.url === row.profile),[row.profile]);
// const { collection: memberships } = useLoadedMembers();
//
// const profiles = useMemo(()=>memberships.map(membership=>({
// url: membership.profile.url,
// label: membership.profile.given_name + " " + membership.profile.surname + " (" + membership.profile.student_number + ")"
// })), [memberships]);
//
// const profile = useMemo(()=>profiles.find(profile=>profile.url === row.profile),[row.profile]);
return (
<Dialog open={open} onClose={onCancelChanges} aria-labelledby={"form-dialog-title"} fullWidth={true}>
......@@ -54,15 +54,16 @@ const Popup = ({ row, onChange, onApplyChanges, onCancelChanges, open }) => {
>
<DialogTitle id={"form-dialog-title"}>Invoice Details</DialogTitle>
<DialogContent>
<Wrapper>
<IconHolder Icon={PersonIcon}/>
<MemberField
label={"Member"}
value={profile}
onChange={(event, value)=>onChange({target: {name: "profile", value: value ? value.url : ""}})}
required
/>
</Wrapper>
{ /*<Wrapper>*/ }
{ /* <IconHolder Icon={PersonIcon}/>*/ }
{ /* <MemberField*/ }
{ /* name={"profile"}*/ }
{ /* label={"Member"}*/ }
{ /* value={profile}*/ }
{ /* onChange={(event, value)=>onChange({target: {name: "profile", value: value ? value.url : ""}})}*/ }
{ /* required*/ }
{ /* />*/ }
{ /*</Wrapper>*/ }
<Wrapper>
<IconHolder Icon={EventIcon}/>