Skip to content

Commit 1179d95

Browse files
authored
Merge pull request #3912 from Northeastern-Electric-Racing/#3879-Reorganize-Material-Form
#3879 reorganize material form
2 parents e9eef79 + bf00b51 commit 1179d95

4 files changed

Lines changed: 53 additions & 67 deletions

File tree

src/backend/src/controllers/projects.controllers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export default class ProjectsController {
226226
subtotal,
227227
notes,
228228
assemblyId,
229-
pdmFileName === '' ? undefined : pdmFileName,
229+
pdmFileName,
230230
unitName,
231231
reimbursementRequestId
232232
);
@@ -389,7 +389,7 @@ export default class ProjectsController {
389389
notes,
390390
unitName,
391391
assemblyId,
392-
pdmFileName === '' ? undefined : pdmFileName,
392+
pdmFileName,
393393
reimbursementRequestId
394394
);
395395
res.status(200).json(updatedMaterial);

src/backend/src/utils/validation.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ export const materialValidators = [
198198
nonEmptyString(body('assemblyId').optional()),
199199
isMaterialStatus(body('status')),
200200
nonEmptyString(body('materialTypeName')),
201-
nonEmptyString(body('manufacturerName')).optional(),
202-
nonEmptyString(body('manufacturerPartNumber')).optional(),
201+
body('manufacturerName').optional().isString(),
202+
body('manufacturerPartNumber').optional().isString(),
203203
body('pdmFileName').optional().isString(),
204204
decimalMinZero(body('quantity')).optional(),
205205
nonEmptyString(body('unitName')).optional(),
206206
intMinZero(body('price')).optional(), // in cents
207207
intMinZero(body('subtotal')).optional(), // in cents
208-
nonEmptyString(body('linkUrl')),
208+
body('linkUrl').optional().isString(),
209209
nonEmptyString(body('reimbursementRequestId')).optional(),
210210
body('notes').isString().optional()
211211
];

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/MaterialForm/MaterialForm.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const schema = yup.object().shape({
2626
quantity: yup.number().optional(),
2727
price: yup.number().optional(),
2828
unitName: yup.string().optional(),
29-
linkUrl: yup.string().required('URL is required!'),
29+
linkUrl: yup.string().optional(),
3030
notes: yup.string().optional(),
3131
pdmFileName: yup.string().optional(),
3232
assemblyId: yup.string().optional(),
@@ -43,7 +43,7 @@ export interface MaterialFormInput {
4343
price?: number;
4444
quantity?: number;
4545
unitName?: string;
46-
linkUrl: string;
46+
linkUrl?: string;
4747
notes?: string;
4848
assemblyId?: string;
4949
reimbursementRequestId?: string;
@@ -59,7 +59,7 @@ export interface MaterialDataSubmission {
5959
price?: number;
6060
quantity?: Decimal;
6161
unitName?: string;
62-
linkUrl: string;
62+
linkUrl?: string;
6363
notes?: string;
6464
assemblyId?: string;
6565
subtotal?: number;
@@ -139,8 +139,12 @@ const MaterialForm: React.FC<MaterialFormProps> = ({ submitText, assemblies, onS
139139

140140
const onSubmitWrapper = (data: MaterialFormInput): void => {
141141
const price = data.price ? Math.round(data.price * 100) : undefined;
142-
const subtotal = price ? (data.quantity ? parseFloat((data.quantity * price).toFixed(2)) : undefined) : undefined;
143-
onSubmit({ ...data, subtotal, price, quantity: data.quantity ? new Decimal(data.quantity) : undefined });
142+
const subtotal = price
143+
? data.quantity != null
144+
? parseFloat((data.quantity * price).toFixed(2))
145+
: undefined
146+
: undefined;
147+
onSubmit({ ...data, subtotal, price, quantity: data.quantity != null ? new Decimal(data.quantity) : undefined });
144148
};
145149

146150
const createManufacturerWrapper = async (manufacturerName: string): Promise<void> => {

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/MaterialForm/MaterialFormView.tsx

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
8484
showCloseButton
8585
>
8686
<Grid container spacing={2}>
87-
<Grid item xs={7}>
87+
<Grid item xs={12}>
8888
<FormControl fullWidth>
8989
<Typography
9090
sx={{
@@ -104,51 +104,6 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
104104
/>
105105
</FormControl>
106106
</Grid>
107-
<Grid item xs={5}>
108-
<FormControl fullWidth>
109-
<Typography
110-
sx={{
111-
fontWeight: 'bold',
112-
fontSize: '1.75rem',
113-
color: '#EF4345'
114-
}}
115-
variant="h5"
116-
>
117-
Reimbursement #:
118-
</Typography>
119-
<Controller
120-
name="reimbursementRequestId"
121-
control={control}
122-
defaultValue={control._defaultValues.reimbursementRequestId}
123-
render={({ field }) => (
124-
<TextField
125-
{...field}
126-
select
127-
variant="outlined"
128-
error={!!errors.reimbursementRequestId}
129-
helperText={errors.reimbursementRequestId?.message}
130-
SelectProps={{
131-
displayEmpty: true,
132-
renderValue: (selected) =>
133-
selected ? (
134-
reimbursementRequests.find((rr) => rr.reimbursementRequestId === selected)?.identifier
135-
) : (
136-
<Typography sx={{ fontSize: '1rem', color: 'lightgray', opacity: 0.6 }}>
137-
Select Corresponding RR
138-
</Typography>
139-
)
140-
}}
141-
>
142-
{reimbursementRequests.map((rr: ReimbursementRequest) => (
143-
<MenuItem key={rr.reimbursementRequestId} value={rr.reimbursementRequestId}>
144-
{rr.identifier}
145-
</MenuItem>
146-
))}
147-
</TextField>
148-
)}
149-
/>
150-
</FormControl>
151-
</Grid>
152107
<Grid item xs={6}>
153108
<FormControl fullWidth>
154109
<Typography
@@ -208,7 +163,6 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
208163
setValue('materialTypeName', '');
209164
onChange('');
210165
};
211-
212166
return (
213167
<Box sx={{ alignItems: 'center' }}>
214168
<NERAutocomplete
@@ -241,7 +195,7 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
241195
}}
242196
variant="h5"
243197
>
244-
Manufacturer:*
198+
Manufacturer:
245199
</Typography>
246200
<Tooltip
247201
title={'Make sure not to enter the distributor (e.g. Amazon)'}
@@ -321,17 +275,10 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
321275
}}
322276
variant="h5"
323277
>
324-
Part Details:*
278+
Part Details:
325279
</Typography>
326280
<Tooltip title={"Enter 'N/A' if no Manufacturer Part Number"} placement="right">
327-
<HelpIcon
328-
sx={{
329-
fontSize: 'medium',
330-
ml: 1,
331-
color: 'lightgray',
332-
cursor: 'pointer'
333-
}}
334-
/>
281+
<HelpIcon sx={{ marginBottom: '-1.2em', fontSize: 'medium', marginLeft: '5px', color: 'lightgray' }} />
335282
</Tooltip>
336283
</Box>
337284
</Grid>
@@ -460,6 +407,41 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
460407
</Grid>
461408
</Grid>
462409
<Grid item xs={12}>
410+
<Grid item xs={12} mt={2}>
411+
<FormControl fullWidth>
412+
<Controller
413+
name="reimbursementRequestId"
414+
control={control}
415+
defaultValue={control._defaultValues.reimbursementRequestId}
416+
render={({ field }) => (
417+
<TextField
418+
{...field}
419+
select
420+
variant="outlined"
421+
error={!!errors.reimbursementRequestId}
422+
helperText={errors.reimbursementRequestId?.message}
423+
SelectProps={{
424+
displayEmpty: true,
425+
renderValue: (selected) =>
426+
selected ? (
427+
reimbursementRequests.find((rr) => rr.reimbursementRequestId === selected)?.identifier
428+
) : (
429+
<Typography sx={{ fontSize: '1rem', color: 'lightgray', opacity: 0.6 }}>
430+
Select Corresponding Reimbursement Request Number
431+
</Typography>
432+
)
433+
}}
434+
>
435+
{reimbursementRequests.map((rr: ReimbursementRequest) => (
436+
<MenuItem key={rr.reimbursementRequestId} value={rr.reimbursementRequestId}>
437+
{rr.identifier}
438+
</MenuItem>
439+
))}
440+
</TextField>
441+
)}
442+
/>
443+
</FormControl>
444+
</Grid>
463445
<Box display={'flex'} justifyContent={'flex-end'} mt={2}>
464446
<FormControl fullWidth>
465447
<Controller

0 commit comments

Comments
 (0)