Skip to content

Commit c0356df

Browse files
authored
Merge pull request #1439 from Northeastern-Electric-Racing/#1289-change-expense-type-to-autocomplete
#1289 change expense type to autocomplete
2 parents 474531a + f0b9847 commit c0356df

2 files changed

Lines changed: 23 additions & 39 deletions

File tree

src/frontend/src/components/NERAutocomplete.tsx

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import {
7-
Autocomplete,
8-
AutocompleteRenderInputParams,
9-
InputAdornment,
10-
SxProps,
11-
TextField,
12-
Theme,
13-
useTheme
14-
} from '@mui/material';
15-
import SearchIcon from '@mui/icons-material/Search';
6+
import { Autocomplete, AutocompleteRenderInputParams, SxProps, TextField, Theme, useTheme } from '@mui/material';
167
import { HTMLAttributes } from 'react';
178

189
interface NERAutocompleteProps {
@@ -44,15 +35,8 @@ const NERAutocomplete: React.FC<NERAutocompleteProps> = ({
4435
height: '40px',
4536
backgroundColor: theme.palette.background.default,
4637
width: '100%',
47-
borderRadius: '25px',
4838
border: 0,
49-
'.MuiOutlinedInput-notchedOutline': {
50-
borderColor: 'black',
51-
borderRadius: '25px'
52-
},
53-
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
54-
borderColor: 'red'
55-
},
39+
borderColor: 'black',
5640
...sx
5741
};
5842

@@ -61,12 +45,7 @@ const NERAutocomplete: React.FC<NERAutocompleteProps> = ({
6145
<TextField
6246
{...params}
6347
InputProps={{
64-
...params.InputProps,
65-
startAdornment: (
66-
<InputAdornment position="start">
67-
<SearchIcon />
68-
</InputAdornment>
69-
)
48+
...params.InputProps
7049
}}
7150
placeholder={placeholder}
7251
required

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import NERSuccessButton from '../../../components/NERSuccessButton';
3232
import { ReimbursementRequestFormInput } from './ReimbursementRequestForm';
3333
import { useState } from 'react';
3434
import { useToast } from '../../../hooks/toasts.hooks';
35+
import NERAutocomplete from '../../../components/NERAutocomplete';
3536
import { Link as RouterLink } from 'react-router-dom';
3637
import { routes } from '../../../utils/routes';
3738
import { codeAndRefundSourceName, expenseTypePipe } from '../../../utils/pipes';
@@ -111,6 +112,10 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps>
111112
</FormControl>
112113
);
113114

115+
const expenseTypesToAutocomplete = (expenseType: ExpenseType): { label: string; id: string } => {
116+
return { label: expenseTypePipe(expenseType), id: expenseType.expenseTypeId };
117+
};
118+
114119
return (
115120
<form
116121
onSubmit={(e) => {
@@ -212,21 +217,21 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps>
212217
<Controller
213218
name="expenseTypeId"
214219
control={control}
215-
render={({ field: { onChange, value } }) => (
216-
<Select
217-
onChange={(newValue) => onChange(newValue.target.value)}
218-
value={value}
219-
error={!!errors.expenseTypeId}
220-
>
221-
{allExpenseTypes
222-
.filter((expenseType) => expenseType.allowed)
223-
.map((expenseType) => (
224-
<MenuItem key={expenseType.expenseTypeId} value={expenseType.expenseTypeId}>
225-
{expenseTypePipe(expenseType)}
226-
</MenuItem>
227-
))}
228-
</Select>
229-
)}
220+
render={({ field: { onChange, value } }) => {
221+
const mappedExpenseTypes = allExpenseTypes.map(expenseTypesToAutocomplete);
222+
return (
223+
<NERAutocomplete
224+
id={'expenseType'}
225+
size="medium"
226+
options={mappedExpenseTypes}
227+
value={mappedExpenseTypes.find((expenseType) => expenseType.id === value) || null}
228+
placeholder="Expense Type"
229+
onChange={(_event, newValue) => {
230+
newValue ? onChange(newValue.id) : onChange('');
231+
}}
232+
/>
233+
);
234+
}}
230235
/>
231236
<FormHelperText error>{errors.expenseTypeId?.message}</FormHelperText>
232237
</FormControl>

0 commit comments

Comments
 (0)