1
|
import { Button, Link, Stack, Typography } from '@mui/material'
|
2
|
import { Fragment, FunctionComponent } from 'react'
|
3
|
import AttachmentIcon from '@mui/icons-material/Attachment'
|
4
|
import DeleteIcon from '@mui/icons-material/Delete'
|
5
|
import SendIcon from '@mui/icons-material/Send'
|
6
|
|
7
|
export interface SingleFileSelectionFormProps {
|
8
|
filename?: string
|
9
|
onFileSelected: (event: any) => void
|
10
|
formik: any
|
11
|
onClearSelectedFile: () => void
|
12
|
loading?: boolean
|
13
|
}
|
14
|
|
15
|
const SingleFileSelectionForm: FunctionComponent<
|
16
|
SingleFileSelectionFormProps
|
17
|
> = ({ filename, onFileSelected, formik, onClearSelectedFile, loading }) => {
|
18
|
return (
|
19
|
<form onSubmit={formik.handleSubmit}>
|
20
|
{!filename ? (
|
21
|
<Fragment>
|
22
|
<Stack
|
23
|
direction="row"
|
24
|
justifyContent="flex-end"
|
25
|
alignItems="center"
|
26
|
>
|
27
|
<Button
|
28
|
variant="contained"
|
29
|
color="primary"
|
30
|
component="label"
|
31
|
// size="small"
|
32
|
startIcon={<AttachmentIcon />}
|
33
|
>
|
34
|
Select File
|
35
|
<input
|
36
|
id="file"
|
37
|
name="file"
|
38
|
type="file"
|
39
|
hidden
|
40
|
onChange={onFileSelected}
|
41
|
/>
|
42
|
</Button>
|
43
|
</Stack>
|
44
|
</Fragment>
|
45
|
) : (
|
46
|
<Fragment>
|
47
|
<Stack direction="row" spacing={1}>
|
48
|
<Typography variant="body1">Selected File: </Typography>
|
49
|
<Typography
|
50
|
sx={{
|
51
|
textOverflow: 'ellipsis',
|
52
|
overflow: 'hidden',
|
53
|
}}
|
54
|
component={Link}
|
55
|
>
|
56
|
{filename}
|
57
|
</Typography>
|
58
|
</Stack>
|
59
|
<Stack
|
60
|
direction="row"
|
61
|
justifyContent="flex-end"
|
62
|
alignItems="center"
|
63
|
spacing={2}
|
64
|
sx={{ mt: 2 }}
|
65
|
>
|
66
|
<Button
|
67
|
// sx={{ mb: 2, mt: 1 }}
|
68
|
variant="contained"
|
69
|
size="small"
|
70
|
endIcon={<DeleteIcon />}
|
71
|
onClick={onClearSelectedFile}
|
72
|
>
|
73
|
Remove Selection
|
74
|
</Button>
|
75
|
<Button
|
76
|
size="small"
|
77
|
type="submit"
|
78
|
variant="contained"
|
79
|
startIcon={<SendIcon />}
|
80
|
disabled={loading}
|
81
|
>
|
82
|
Submit
|
83
|
</Button>
|
84
|
</Stack>
|
85
|
</Fragment>
|
86
|
)}
|
87
|
</form>
|
88
|
)
|
89
|
}
|
90
|
|
91
|
export default SingleFileSelectionForm
|