|
1 | 1 | import { Delete } from '@mui/icons-material'; |
2 | 2 | import { |
3 | | - Autocomplete, |
4 | 3 | FormControl, |
5 | 4 | FormHelperText, |
6 | 5 | FormLabel, |
@@ -30,6 +29,8 @@ import NERSuccessButton from '../../../components/NERSuccessButton'; |
30 | 29 | import { ReimbursementRequestFormInput } from './ReimbursementRequestForm'; |
31 | 30 | import { useState } from 'react'; |
32 | 31 | import { useToast } from '../../../hooks/toasts.hooks'; |
| 32 | +import NERAutocomplete from '../../../components/NERAutocomplete'; |
| 33 | +import { fullNamePipe } from '../../../utils/pipes'; |
33 | 34 |
|
34 | 35 | interface ReimbursementRequestFormViewProps { |
35 | 36 | allVendors: Vendor[]; |
@@ -101,6 +102,10 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps> |
101 | 102 | </FormControl> |
102 | 103 | ); |
103 | 104 |
|
| 105 | + const expenseTypesToAutocomplete = (expense: ExpenseType): { label: string; id: string } => { |
| 106 | + return { label: expense.name, id: expense.toString() }; |
| 107 | + }; |
| 108 | + |
104 | 109 | return ( |
105 | 110 | <form |
106 | 111 | onSubmit={(e) => { |
@@ -188,19 +193,27 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps> |
188 | 193 | <Controller |
189 | 194 | name="expenseTypeId" |
190 | 195 | control={control} |
191 | | - render={({ field: { onChange, value } }) => ( |
192 | | - <Autocomplete |
193 | | - options={allExpenseTypes} |
194 | | - getOptionLabel={(expenseType) => expenseType.name} |
195 | | - value={allExpenseTypes.find((expenseType) => expenseType.expenseTypeId === value)} |
196 | | - onChange={(_event, newValue) => { |
197 | | - if (newValue) { |
198 | | - onChange(newValue.expenseTypeId); |
| 196 | + render={({ field: { onChange, value } }) => { |
| 197 | + const selectedExpenseType = allExpenseTypes.find((expenseType) => expenseType.expenseTypeId === value); |
| 198 | + return ( |
| 199 | + <NERAutocomplete |
| 200 | + options={allExpenseTypes.map(expenseTypesToAutocomplete)} |
| 201 | + value={ |
| 202 | + allExpenseTypes |
| 203 | + .map(expenseTypesToAutocomplete) |
| 204 | + .find((expenseType) => expenseType.label === value) || null |
199 | 205 | } |
200 | | - }} |
201 | | - renderInput={(params) => <TextField {...params} placeholder="Expense Type" />} |
202 | | - /> |
203 | | - )} |
| 206 | + placeholder="Expense Type" |
| 207 | + onChange={(_event, newValue) => { |
| 208 | + if (newValue) { |
| 209 | + onChange(newValue.label); |
| 210 | + } |
| 211 | + }} |
| 212 | + id={'expenseType'} |
| 213 | + size={undefined} |
| 214 | + /> |
| 215 | + ); |
| 216 | + }} |
204 | 217 | /> |
205 | 218 | <FormHelperText error>{errors.expenseTypeId?.message}</FormHelperText> |
206 | 219 | </FormControl> |
|
0 commit comments