-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormSelect.js
More file actions
106 lines (94 loc) · 3.17 KB
/
Copy pathFormSelect.js
File metadata and controls
106 lines (94 loc) · 3.17 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React, { useEffect, useState } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Input from '@material-ui/core/Input';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
import ListItemText from '@material-ui/core/ListItemText';
import Select from '@material-ui/core/Select';
import Checkbox from '@material-ui/core/Checkbox';
import API from './client/src/utils/API'
const useStyles = makeStyles((theme) => ({
formControl: {
margin: theme.spacing(1),
minWidth: 120,
maxWidth: 300,
},
chips: {
display: 'flex',
flexWrap: 'wrap',
},
chip: {
margin: 2,
},
noLabel: {
marginTop: theme.spacing(3),
},
}));
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
export default function FormSelect(props) {
const classes = useStyles();
//stores services retrieved from the API
const [services, setServices] = useState([])
//stores user selected services
const [selectedService, setSelectedService] = useState([]);
useEffect(() => {
API.getServices()
.then(res => {
if (res.data.status === "error") {
throw new Error(res.data.message);
}
if (res.data.length > 0) {
setServices(res.data)
// console.log(services)
}
})
.catch((err) => console.log(err))
}, []);
const handleChange = (event) => {
event.preventDefault();
setSelectedService(event.target.value);
console.log(selectedService)
};
return (
<div>
<FormControl className={classes.formControl}>
<InputLabel id="service-selector-label">Services</InputLabel>
<Select
labelId="service-selector-label"
id="service-selector"
multiple
value={selectedService}
onChange={handleChange, props.onChange}
className={props.className}
disabled={props.disabled}
defaultValue={props.defaultValue}
variant={props.variant}
input={<Input />}
renderValue={(selected) => selected.join(', ')}
MenuProps={MenuProps}
>
{/* {console.log(services)} */}
{services.map((service) => (
<div>
<MenuItem key={service._id} value={service._id}>
<Checkbox color="default" />
<ListItemText primary={service._id} />
</MenuItem>
</div>
))}
{console.log(selectedService)}
</Select>
</FormControl>
</div>
);
}