Skip to content

Commit 43cffe6

Browse files
committed
#1578: Implemented nicer looking button and multi file selection
1 parent 08f2649 commit 43cffe6

1 file changed

Lines changed: 37 additions & 20 deletions

File tree

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

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
TextField,
1212
Typography,
1313
Snackbar,
14-
Alert
14+
Alert,
15+
Button
1516
} from '@mui/material';
1617
import { Box, Stack } from '@mui/system';
1718
import { Control, Controller, FieldErrors, UseFormHandleSubmit, UseFormSetValue, UseFormWatch } from 'react-hook-form';
@@ -37,6 +38,7 @@ import { routes } from '../../../utils/routes';
3738
import { wbsNumComparator } from 'shared/src/validate-wbs';
3839
import { codeAndRefundSourceName, expenseTypePipe } from '../../../utils/pipes';
3940
import NERAutocomplete from '../../../components/NERAutocomplete';
41+
import FileUploadIcon from '@mui/icons-material/FileUpload';
4042

4143
interface ReimbursementRequestFormViewProps {
4244
allVendors: Vendor[];
@@ -251,27 +253,42 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps>
251253
<Grid item xs={6}>
252254
<FormControl fullWidth>
253255
<ReceiptFileInput />
254-
<input
255-
onChange={(e) => {
256-
if (e.target.files) {
257-
const file = e.target.files[0];
258-
if (file.size < 1000000) {
259-
receiptAppend({
260-
file: e.target.files[0],
261-
name: e.target.files[0].name,
262-
googleFileId: ''
256+
<Button
257+
variant="contained"
258+
color="success"
259+
component="label"
260+
startIcon={<FileUploadIcon />}
261+
sx={{
262+
width: 'fit-content',
263+
textTransform: 'none'
264+
}}
265+
>
266+
Upload
267+
<input
268+
onChange={(e) => {
269+
if (e.target.files) {
270+
[...e.target.files].forEach((file) => {
271+
if (file.size < 1000000) {
272+
receiptAppend({
273+
file: file,
274+
name: file.name,
275+
googleFileId: ''
276+
});
277+
} else {
278+
toast.error(`Error uploading ${file.name}; file must be less than 1 MB`, 5000);
279+
document.getElementById('receipt-image')!.innerHTML = '';
280+
}
263281
});
264-
} else {
265-
toast.error('File must be less than 1 MB', 5000);
266-
document.getElementById('receipt-image')!.innerHTML = '';
267282
}
268-
}
269-
}}
270-
type="file"
271-
id="receipt-image"
272-
accept="image/png, image/jpeg, .pdf"
273-
name="receiptFiles"
274-
/>
283+
}}
284+
type="file"
285+
id="receipt-image"
286+
accept="image/png, image/jpeg, .pdf"
287+
name="receiptFiles"
288+
multiple
289+
hidden
290+
/>
291+
</Button>
275292
<FormHelperText error>{errors.receiptFiles?.message}</FormHelperText>
276293
</FormControl>
277294
</Grid>

0 commit comments

Comments
 (0)