aboutsummaryrefslogtreecommitdiffstats
path: root/src/views/Modals/Inputs/SelectModal.jsx
blob: 61e7ae93f421b8599dc643194df1e5f7f3e3c864 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {
  Box,
  Button,
  Modal,
  ModalDialog,
  Option,
  Select,
  Typography,
} from '@mui/joy'
import React from 'react'

function SelectModal({ isOpen, onClose, onSave, options, title, displayKey }) {
  const [selected, setSelected] = React.useState(null)
  const handleSave = () => {
    onSave(options.find(item => item.id === selected))
    onClose()
  }

  return (
    <Modal open={isOpen} onClose={onClose}>
      <ModalDialog>
        <Typography variant='h4'>{title}</Typography>
        <Select>
          {options.map((item, index) => (
            <Option
              value={item.id}
              key={item[displayKey]}
              onClick={() => {
                setSelected(item.id)
              }}
            >
              {item[displayKey]}
            </Option>
          ))}
        </Select>

        <Box display={'flex'} justifyContent={'space-around'} mt={1}>
          <Button onClick={handleSave} fullWidth sx={{ mr: 1 }}>
            Save
          </Button>
          <Button onClick={onClose} variant='outlined'>
            Cancel
          </Button>
        </Box>
      </ModalDialog>
    </Modal>
  )
}
export default SelectModal