Skip to content

Commit 0b78ec5

Browse files
committed
#1666 Added error message for cost and description of products on finance form
1 parent e0c4d0c commit 0b78ec5

1 file changed

Lines changed: 46 additions & 35 deletions

File tree

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

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Autocomplete,
77
Button,
88
FormLabel,
9+
FormHelperText,
910
IconButton,
1011
InputAdornment,
1112
Table,
@@ -97,41 +98,51 @@ const ReimbursementProductTable: React.FC<ReimbursementProductTableProps> = ({
9798
{uniqueWbsElementsWithProducts.get(key)?.map((product, index) => (
9899
<ListItem key={product.index}>
99100
<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-
/>
101+
<div style={{ display: 'flex', flexDirection: 'column', width: '50%', marginRight: '4px' }}>
102+
<Controller
103+
name={`reimbursementProducts.${product.index}.name`}
104+
control={control}
105+
render={({ field }) => (
106+
<TextField
107+
{...field}
108+
label={'Description'}
109+
autoComplete="off"
110+
size={'small'}
111+
variant={'outlined'}
112+
sx={{ width: '100%' }}
113+
error={!!errors.reimbursementProducts?.[product.index]?.name}
114+
/>
115+
)}
116+
/>
117+
<FormHelperText error>
118+
{errors.reimbursementProducts?.[product.index]?.name?.message}
119+
</FormHelperText>
120+
</div>
121+
<div style={{ display: 'flex', flexDirection: 'column', width: '50%' }}>
122+
<Controller
123+
name={`reimbursementProducts.${product.index}.cost`}
124+
control={control}
125+
render={({ field }) => (
126+
<TextField
127+
{...field}
128+
label={'Cost'}
129+
size={'small'}
130+
variant={'outlined'}
131+
type="number"
132+
autoComplete="off"
133+
InputProps={{
134+
startAdornment: <InputAdornment position="start">$</InputAdornment>
135+
}}
136+
onBlur={(e) => onCostBlurHandler(parseFloat(e.target.value), product.index)}
137+
sx={{ width: '100%' }}
138+
error={!!errors.reimbursementProducts?.[product.index]?.cost}
139+
/>
140+
)}
141+
/>
142+
<FormHelperText error>
143+
{errors.reimbursementProducts?.[product.index]?.cost?.message}
144+
</FormHelperText>
145+
</div>
135146
<IconButton onClick={() => removeProduct(product.index)}>
136147
<Delete />
137148
</IconButton>

0 commit comments

Comments
 (0)