Skip to content

Commit 1c9e3bb

Browse files
authored
Merge pull request #1669 from Northeastern-Electric-Racing/#1666-error-message-cost-description
#1666 Added error message for cost and description of products on finance form
2 parents dba366b + dde1fcf commit 1c9e3bb

2 files changed

Lines changed: 52 additions & 36 deletions

File tree

src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementProductTable.tsx

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import {
66
Autocomplete,
77
Button,
8+
FormControl,
89
FormLabel,
10+
FormHelperText,
911
IconButton,
1012
InputAdornment,
1113
Table,
@@ -97,41 +99,51 @@ const ReimbursementProductTable: React.FC<ReimbursementProductTableProps> = ({
9799
{uniqueWbsElementsWithProducts.get(key)?.map((product, index) => (
98100
<ListItem key={product.index}>
99101
<Box sx={{ display: 'flex', flexDirection: 'row' }}>
100-
<Controller
101-
name={`reimbursementProducts.${product.index}.name`}
102-
control={control}
103-
render={({ field }) => (
104-
<TextField
105-
{...field}
106-
label={'Description'}
107-
autoComplete="off"
108-
size={'small'}
109-
variant={'outlined'}
110-
sx={{ width: '50%', marginRight: '4px' }}
111-
error={!!errors.reimbursementProducts?.[product.index]?.name}
112-
/>
113-
)}
114-
/>
115-
<Controller
116-
name={`reimbursementProducts.${product.index}.cost`}
117-
control={control}
118-
render={({ field }) => (
119-
<TextField
120-
{...field}
121-
label={'Cost'}
122-
size={'small'}
123-
variant={'outlined'}
124-
type="number"
125-
autoComplete="off"
126-
InputProps={{
127-
startAdornment: <InputAdornment position="start">$</InputAdornment>
128-
}}
129-
onBlur={(e) => onCostBlurHandler(parseFloat(e.target.value), product.index)}
130-
sx={{ width: '50%' }}
131-
error={!!errors.reimbursementProducts?.[product.index]?.cost}
132-
/>
133-
)}
134-
/>
102+
<FormControl sx={{ width: '50%', marginRight: '4px' }}>
103+
<Controller
104+
name={`reimbursementProducts.${product.index}.name`}
105+
control={control}
106+
render={({ field }) => (
107+
<TextField
108+
{...field}
109+
label={'Description'}
110+
autoComplete="off"
111+
size={'small'}
112+
variant={'outlined'}
113+
sx={{ width: '100%' }}
114+
error={!!errors.reimbursementProducts?.[product.index]?.name}
115+
/>
116+
)}
117+
/>
118+
<FormHelperText error>
119+
{errors.reimbursementProducts?.[product.index]?.name?.message}
120+
</FormHelperText>
121+
</FormControl>
122+
<FormControl sx={{ width: '50%' }}>
123+
<Controller
124+
name={`reimbursementProducts.${product.index}.cost`}
125+
control={control}
126+
render={({ field }) => (
127+
<TextField
128+
{...field}
129+
label={'Cost'}
130+
size={'small'}
131+
variant={'outlined'}
132+
type="number"
133+
autoComplete="off"
134+
InputProps={{
135+
startAdornment: <InputAdornment position="start">$</InputAdornment>
136+
}}
137+
onBlur={(e) => onCostBlurHandler(parseFloat(e.target.value), product.index)}
138+
sx={{ width: '100%' }}
139+
error={!!errors.reimbursementProducts?.[product.index]?.cost}
140+
/>
141+
)}
142+
/>
143+
<FormHelperText error>
144+
{errors.reimbursementProducts?.[product.index]?.cost?.message}
145+
</FormHelperText>
146+
</FormControl>
135147
<IconButton onClick={() => removeProduct(product.index)}>
136148
<Delete />
137149
</IconButton>

src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementRequestForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const schema = yup.object().shape({
4747
yup.object().shape({
4848
wbsNum: yup.object().required('WBS Number is required'),
4949
name: yup.string().required('Description is required'),
50-
cost: yup.number().required('Amount is required').min(0.01, 'Amount must be greater than 0')
50+
cost: yup
51+
.number()
52+
.typeError('Amount is required')
53+
.required('Amount is required')
54+
.min(0.01, 'Amount must be greater than 0')
5155
})
5256
)
5357
.required('reimbursement products required')

0 commit comments

Comments
 (0)