Skip to content

Commit b6f6013

Browse files
committed
#2131 - rearrange create modal
1 parent 1a05e9b commit b6f6013

1 file changed

Lines changed: 96 additions & 112 deletions

File tree

src/frontend/src/pages/CalendarPage/DesignReviewCreateModal.tsx

Lines changed: 96 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import { DatePicker } from '@mui/x-date-pickers';
1818
import { useToast } from '../../hooks/toasts.hooks';
1919
import { useState } from 'react';
2020
import { meetingStartTimePipe, wbsNamePipe } from '../../utils/pipes';
21-
import { Project, TeamType, WbsNumber, WorkPackage, validateWBS, wbsPipe } from 'shared';
21+
import { TeamType, WbsNumber, WorkPackage, validateWBS, wbsPipe } from 'shared';
2222
import { useCreateDesignReviews } from '../../hooks/design-reviews.hooks';
2323
import { useAllUsers } from '../../hooks/users.hooks';
2424
import ErrorPage from '../ErrorPage';
2525
import LoadingIndicator from '../../components/LoadingIndicator';
2626
import { userToAutocompleteOption } from '../../utils/teams.utils';
2727
import { useQuery } from '../../hooks/utils.hooks';
2828
import NERAutocomplete from '../../components/NERAutocomplete';
29-
import { useAllProjects } from '../../hooks/projects.hooks';
29+
import { useAllWorkPackages } from '../../hooks/work-packages.hooks';
3030

3131
const schema = yup.object().shape({
3232
date: yup.date().required('Date is required'),
@@ -61,18 +61,21 @@ export const DesignReviewCreateModal: React.FC<DesignReviewCreateModalProps> = (
6161
const [optionalMembers, setOptionalMembers] = useState([].map(userToAutocompleteOption));
6262
const [wbsNum, setWbsNum] = useState(query.get('wbsNum') || '');
6363
const { isLoading: allUsersIsLoading, isError: allUsersIsError, error: allUsersError, data: users } = useAllUsers();
64-
const { data: projects } = useAllProjects();
64+
const {
65+
isLoading: allWorkPackagesIsLoading,
66+
isError: allWorkPackagesIsError,
67+
error: allWorkPackagesError,
68+
data: allWorkPackages
69+
} = useAllWorkPackages();
6570

6671
const { mutateAsync } = useCreateDesignReviews();
6772

6873
const onSubmit = async (data: CreateDesignReviewFormInput) => {
6974
const day = data.date.getDay();
70-
console.log('Day: ' + day);
7175
const times = [];
7276
for (let i = day * 12 + data.startTime; i <= day * 12 + data.endTime; i++) {
7377
times.push(i);
7478
}
75-
console.log('times: ' + times);
7679
try {
7780
await mutateAsync({
7881
dateScheduled: data.date,
@@ -105,29 +108,18 @@ export const DesignReviewCreateModal: React.FC<DesignReviewCreateModalProps> = (
105108
}
106109
});
107110

108-
if (allUsersIsError) return <ErrorPage message={allUsersError?.message} />;
109-
if (allUsersIsLoading || !users || !projects) return <LoadingIndicator />;
111+
if (allUsersIsError) return <ErrorPage error={allUsersError} message={allUsersError?.message} />;
112+
if (allWorkPackagesIsError) return <ErrorPage error={allWorkPackagesError} message={allWorkPackagesError?.message} />;
113+
if (allUsersIsLoading || !users || allWorkPackagesIsLoading || !allWorkPackages) return <LoadingIndicator />;
110114

111115
const memberOptions = users.map(userToAutocompleteOption);
112116

113-
const projectOptions: { label: string; id: string }[] = [];
114-
115117
const wbsDropdownOptions: { label: string; id: string }[] = [];
116118

117-
projects.forEach((project: Project) => {
119+
allWorkPackages.forEach((workPackage: WorkPackage) => {
118120
wbsDropdownOptions.push({
119-
label: `${wbsNamePipe(project)}`,
120-
id: wbsPipe(project.wbsNum)
121-
});
122-
projectOptions.push({
123-
label: `${wbsNamePipe(project)}`,
124-
id: wbsPipe(project.wbsNum)
125-
});
126-
project.workPackages.forEach((workPackage: WorkPackage) => {
127-
wbsDropdownOptions.push({
128-
label: `${wbsNamePipe(workPackage)}`,
129-
id: wbsPipe(workPackage.wbsNum)
130-
});
121+
label: `${wbsNamePipe(workPackage)}`,
122+
id: wbsPipe(workPackage.wbsNum)
131123
});
132124
});
133125

@@ -184,50 +176,7 @@ export const DesignReviewCreateModal: React.FC<DesignReviewCreateModalProps> = (
184176
)}
185177
/>
186178
</FormControl>
187-
<FormControl>
188-
<FormLabel sx={{ alignSelf: 'start', paddingTop: '10px' }}>Team</FormLabel>
189-
<Controller
190-
name={'teamTypeId'}
191-
control={control}
192-
render={({ field: { onChange, value } }) => (
193-
<Select
194-
id="teamType-select"
195-
value={value}
196-
displayEmpty
197-
renderValue={() => {
198-
console.log(value);
199-
return value ? (
200-
<Typography>{teamTypes.find((teamType) => teamType.teamTypeId === value)?.name} </Typography>
201-
) : (
202-
<Typography style={{ color: 'gray' }}>Select Subteam</Typography>
203-
);
204-
}}
205-
onChange={(event: SelectChangeEvent<string>) => onChange(event.target.value)}
206-
sx={{ height: 56, width: '100%', textAlign: 'left' }}
207-
MenuProps={{
208-
anchorOrigin: {
209-
vertical: 'bottom',
210-
horizontal: 'right'
211-
},
212-
transformOrigin: {
213-
vertical: 'top',
214-
horizontal: 'right'
215-
}
216-
}}
217-
>
218-
{teamTypes.map((teamType) => {
219-
return (
220-
<MenuItem key={teamType.teamTypeId} value={teamType.teamTypeId}>
221-
{teamType.name}
222-
</MenuItem>
223-
);
224-
})}
225-
</Select>
226-
)}
227-
/>
228-
</FormControl>
229-
</Box>
230-
<Box display="flex" flexDirection={'row'} gap={2}>
179+
231180
<FormControl>
232181
<FormLabel sx={{ alignSelf: 'start', paddingTop: '10px' }}>Meeting Start Time</FormLabel>
233182
<Controller
@@ -303,57 +252,92 @@ export const DesignReviewCreateModal: React.FC<DesignReviewCreateModalProps> = (
303252
/>
304253
</FormControl>
305254
</Box>
306-
<Box>
307-
<Typography sx={{ fontWeight: 'bold' }} display="inline">
308-
Required Members:
309-
</Typography>
310-
<Grid container direction={'row'}>
311-
<Grid item xs={9} md={10} lg={11}>
312-
<Autocomplete
313-
isOptionEqualToValue={(option, value) => option.id === value.id}
314-
filterSelectedOptions
315-
multiple
316-
id="tags-standard"
317-
options={memberOptions}
318-
value={requiredMembers}
319-
onChange={(_event, newValue) => setRequiredMembers(newValue)}
320-
getOptionLabel={(option) => option.label}
321-
renderInput={(params) => <TextField {...params} variant="standard" placeholder="Select A User" />}
322-
/>
323-
</Grid>
255+
<Grid container gap={1}>
256+
<Grid item xs={8} sx={{ alignSelf: 'start', paddingTop: '10px', width: '100%' }}>
257+
<FormLabel>Work Package</FormLabel>
258+
<NERAutocomplete
259+
id="wbs-autocomplete"
260+
sx={{ bgcolor: 'inherit' }}
261+
onChange={wbsAutocompleteOnChange}
262+
options={wbsDropdownOptions}
263+
size="medium"
264+
placeholder="Select a work package"
265+
value={wbsDropdownOptions.find((element) => element.id === wbsNum) || null}
266+
/>
324267
</Grid>
325-
</Box>
326-
<Box>
327-
<Typography sx={{ fontWeight: 'bold' }} display="inline">
328-
Optional Members:
329-
</Typography>
330-
<Grid container direction={'row'}>
331-
<Grid item xs={9} md={10} lg={11}>
332-
<Autocomplete
333-
isOptionEqualToValue={(option, value) => option.id === value.id}
334-
filterSelectedOptions
335-
multiple
336-
id="tags-standard"
337-
options={memberOptions}
338-
value={optionalMembers}
339-
onChange={(_event, newValue) => setOptionalMembers(newValue)}
340-
getOptionLabel={(option) => option.label}
341-
renderInput={(params) => <TextField {...params} variant="standard" placeholder="Select A User" />}
268+
<Grid item xs={3}>
269+
<FormControl>
270+
<FormLabel sx={{ alignSelf: 'start', paddingTop: '10px' }}>Team</FormLabel>
271+
<Controller
272+
name={'teamTypeId'}
273+
control={control}
274+
render={({ field: { onChange, value } }) => (
275+
<Select
276+
id="teamType-select"
277+
value={value}
278+
displayEmpty
279+
renderValue={() => {
280+
console.log(value);
281+
return value ? (
282+
<Typography>{teamTypes.find((teamType) => teamType.teamTypeId === value)?.name} </Typography>
283+
) : (
284+
<Typography style={{ color: 'gray' }}>Select Subteam</Typography>
285+
);
286+
}}
287+
onChange={(event: SelectChangeEvent<string>) => onChange(event.target.value)}
288+
sx={{ height: 56, width: '100%', textAlign: 'left' }}
289+
MenuProps={{
290+
anchorOrigin: {
291+
vertical: 'bottom',
292+
horizontal: 'right'
293+
},
294+
transformOrigin: {
295+
vertical: 'top',
296+
horizontal: 'right'
297+
}
298+
}}
299+
>
300+
{teamTypes.map((teamType) => {
301+
return (
302+
<MenuItem key={teamType.teamTypeId} value={teamType.teamTypeId}>
303+
{teamType.name}
304+
</MenuItem>
305+
);
306+
})}
307+
</Select>
308+
)}
342309
/>
343-
</Grid>
310+
</FormControl>
344311
</Grid>
312+
</Grid>
313+
<Box sx={{ alignSelf: 'start', paddingTop: '10px' }}>
314+
<FormLabel> Required Members</FormLabel>
315+
<Autocomplete
316+
isOptionEqualToValue={(option, value) => option.id === value.id}
317+
filterSelectedOptions
318+
multiple
319+
id="tags-standard"
320+
options={memberOptions}
321+
value={requiredMembers}
322+
onChange={(_event, newValue) => setRequiredMembers(newValue)}
323+
getOptionLabel={(option) => option.label}
324+
renderInput={(params) => <TextField {...params} variant="standard" placeholder="Select A User" />}
325+
/>
345326
</Box>
346-
<Grid item xs={12}>
347-
<FormLabel>WBS</FormLabel>
348-
<NERAutocomplete
349-
id="wbs-autocomplete"
350-
onChange={wbsAutocompleteOnChange}
351-
options={wbsDropdownOptions}
352-
size="small"
353-
placeholder="Select a project or work package"
354-
value={wbsDropdownOptions.find((element) => element.id === wbsNum) || null}
327+
<Box sx={{ alignSelf: 'start', paddingTop: '10px' }}>
328+
<FormLabel> Optional Members</FormLabel>
329+
<Autocomplete
330+
isOptionEqualToValue={(option, value) => option.id === value.id}
331+
filterSelectedOptions
332+
multiple
333+
id="tags-standard"
334+
options={memberOptions}
335+
value={optionalMembers}
336+
onChange={(_event, newValue) => setOptionalMembers(newValue)}
337+
getOptionLabel={(option) => option.label}
338+
renderInput={(params) => <TextField {...params} variant="standard" placeholder="Select A User" />}
355339
/>
356-
</Grid>
340+
</Box>
357341
</NERFormModal>
358342
);
359343
};

0 commit comments

Comments
 (0)