aboutsummaryrefslogtreecommitdiffstats
path: root/src/views/Modals/Inputs/SelectModal.jsx
blob: f879bf0210afc4d580fbed3d1f4ac6f20ba8c35f (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,placeholder }) {
  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 placeholder={placeholder}>
          {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