-
Notifications
You must be signed in to change notification settings - Fork 16
/
Form.jsx
224 lines (205 loc) · 8.52 KB
/
Form.jsx
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import React, { useState, useRef} from "react";
import {useNavigate} from 'react-router-dom';
// MUI
import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
import Checkbox from '@mui/material/Checkbox';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
// controllers
import { putForm } from '../controllers/actions'
import { useLocation } from 'react-router';
const skinToneValues = [1, 2, 3, 4, 5, 6]
const skinToneColors = ["rgb(249, 245, 236)",
"rgb(250, 245, 234)",
"rgb(240, 227, 171)",
"rgb(206, 172, 104)",
"rgb(105, 59, 41)",
"rgb(33, 28, 40)",
]
let data = {
tone: 5,
type: "Oily",
acne: "Moderate"
}
const skinTypes = ["All", "Oily", "Normal", "Dry"]
const acnes = ['Low', 'Moderate', 'Severe']
const otherConcerns = ['sensitive', 'fine lines', 'wrinkles', 'redness', 'pore', 'pigmentation', 'blackheads', 'whiteheads', 'blemishes', 'dark circles', 'eye bags', 'dark spots']
const Form = () => {
const {state} = useLocation();
if(state !== null) {
data = state.data;
console.log(data)
}
console.log("After the condtional : ", data)
const {type, tone, acne} = data;
console.log("Prefill : ", type, tone, acne)
const [currType, setCurrType] = useState(type)
const [currTone, setCurrTone] = useState(parseInt(tone))
const [currAcne, setAcne] = useState(acne)
const [features, setFeatures] = useState({
"normal": false, "dry": false, "oily": false, "combination": false,
"acne": false, "sensitive": false, "fine lines": false, "wrinkles": false,
"redness": false, "dull": false, "pore": false, "pigmentation": false,
"blackheads": false, "whiteheads": false, "blemishes": false, "dark circles": false,
"eye bags": false, "dark spots": false
});
const handleChange = (event) => {
setFeatures({
...features,
[event.target.name]: event.target.checked,
});
console.log(features)
};
const handleTone = (e) => {
setCurrTone(e.target.value)
}
const handleType = (e) => {
setCurrType(e.target.value)
}
const handleAcne = (e) => {
setAcne(e.target.value)
}
const navigate = useNavigate()
const handleSubmit = () => {
if (currType === 'All') {
features['normal'] = true;
features['dry'] = true;
features['oily'] = true;
features['combination'] = true;
}
else {
features[currType.toLowerCase()] = true;
}
if (currAcne != "Low") {
features['acne'] = true;
}
for (const [key, value] of Object.entries(features)) {
if (value === true) {
features[key] = 1;
}
else {
features[key] = 0;
}
}
console.log({"features": features, "type":currType, "tone":currTone})
putForm(features, currType, currTone, navigate)
}
return (
<>
<Container maxWidth="xs" sx={{ marginTop: "2vh" }} alignitems="center" width="inherit">
<Typography variant="h5" component="div" textAlign="center">
Results
</Typography>
{/*
<FormControl fullWidth>
</FormControl> */}
<FormControl component="fieldset" sx={{ marginTop: "3vh" }}>
<Grid container>
<Grid item xs={9}>
<InputLabel id="demo-simple-select-label">Tone</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={currTone}
label="Age"
onChange={handleTone}
fullWidth
defaultValue={tone}>
{skinToneValues.map((value) => {
return (<MenuItem value={value}>{value}</MenuItem>)
})}
</Select>
</Grid>
<Grid item xs={3}>
<div
style={{
height: "3rem",
width: "3rem",
backgroundColor: skinToneColors[tone-1],
margin: "0 auto",
justifySelf: "center",
borderRadius: "10%",
}}></div>
</Grid>
</Grid>
<Grid marginTop="2vh">
<FormLabel component="legend">Type</FormLabel>
<RadioGroup
row
name="row-radio-buttons-group"
defaultValue={type}
onChange={handleType}
value={currType}>
<Grid container>
{skinTypes.map((type) => {
return (
<Grid item xs={6}>
<FormControlLabel
value={type}
control={<Radio />}
label={type} />
</Grid>)
})}
</Grid>
</RadioGroup>
</Grid>
<Grid marginTop="2vh">
<FormLabel component="legend">Acne</FormLabel>
<RadioGroup
row
name="row-radio-buttons-group"
onChange={handleAcne}
defaultValue={acne}
value={currAcne}>
<Grid container>
{acnes.map((ac) => {
return (
<Grid item >
<FormControlLabel
value={ac}
control={<Radio />}
label={ac} />
</Grid>)
})}
</Grid>
</RadioGroup>
</Grid>
<Grid marginTop="2vh">
{/* <Typography variant="h6" component="div" textAlign="center">
Specify other skin concerns
</Typography> */}
<FormLabel component="legend">Specify other skin concerns</FormLabel>
<Grid container>
{otherConcerns.map((concern) => {
return (
<Grid item xs={6}>
<FormControlLabel control={<Checkbox checked={features[concern]} onChange={handleChange} name={concern} />}
value={concern}
label={concern.charAt(0).toUpperCase() + concern.slice(1)} />
</Grid>)
})}
</Grid>
</Grid>
<Grid marginTop="2vh" item xs={12}>
<Button
onClick={handleSubmit}
variant="contained"
fullWidth>
Submit
</Button>
</Grid>
</FormControl>
</Container>
</>
)
}
export default Form;