forked from Ayushgupta0207/HacktoberFest-2023
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsignup.js
206 lines (199 loc) · 5.49 KB
/
signup.js
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
import {
Avatar,
Button,
Grid,
Paper,
TextField,
Typography,
} from "@material-ui/core";
import AddCircleIcon from "@material-ui/icons/AddCircle";
import React from "react";
import Radio from "@material-ui/core/Radio";
import RadioGroup from "@material-ui/core/RadioGroup";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import FormControl from "@material-ui/core/FormControl";
import FormLabel from "@material-ui/core/FormLabel";
import {FormHelperText} from "@material-ui/core";
import {Formik, Form, Field, ErrorMessage} from "formik";
import * as Yup from "yup";
import {useHistory} from "react-router-dom";
const SignUp = () => {
const paperStyle = {padding: "20px", width: "300px", margin: "0 auto"};
const avatarStyle = {backgroundColor: "#1c8f98"};
const captionStyle = {fontSize: "10px"};
const headerStyle = {margin: 0, fontFamily: "Urbanist"};
const elementStyle = {margin: "5px 0"};
const initialValues = {
name: "",
username: "",
email: "",
gender: "",
contactNumber: "",
password: "",
confirmPassword: "",
};
let history = useHistory();
const onSubmit = (values, props) => {
console.log(values);
setTimeout(() => {
props.resetForm();
props.setSubmitting(false);
}, 1000);
console.log(props);
history.push("/home");
};
const validationSchema = Yup.object().shape({
name: Yup.string().min(3, "Too short").required("Required"),
username: Yup.string().min(3, "Too short").required("Required"),
email: Yup.string()
.email("Enter a valid mail address")
.required("Required"),
gender: Yup.string()
.oneOf(["male", "female", "other"], "Required")
.required("Required"),
contactNumber: Yup.number()
.typeError("Enter valid phone number")
.required("Required"),
password: Yup.string()
.min(6, "Minimum 6 characters required")
.required("Required"),
confirmPassword: Yup.string()
.oneOf([Yup.ref("password")], "Password doesn't match")
.required("Required"),
});
return (
<Grid>
<Paper style={paperStyle}>
<Grid align="center">
<Avatar style={avatarStyle}>
<AddCircleIcon />
</Avatar>
<h2 style={headerStyle}> Sign up </h2>
<Typography variant="caption" style={captionStyle}>
Create an Account here!
</Typography>
</Grid>
<Formik
initialValues={initialValues}
onSubmit={onSubmit}
validationSchema={validationSchema}
>
{(props) => (
<Form>
<Field
as={TextField}
label="Name"
name="name"
placeholder="Enter your name"
helperText={<ErrorMessage name="name" />}
variant="outlined"
fullWidth
style={elementStyle}
required
// value={data.Name}
// onChange={(value) => setData({...data, Name: value})}
/>
<Field
as={TextField}
label="Username"
name="username"
helperText={<ErrorMessage name="username" />}
placeholder="Enter your username"
variant="outlined"
fullWidth
style={elementStyle}
required
/>
<Field
as={TextField}
label="Email"
name="email"
type="email"
helperText={<ErrorMessage name="email" />}
placeholder="Enter your email-id"
variant="outlined"
fullWidth
style={elementStyle}
required
/>
<FormControl component="fieldset" style={elementStyle} required>
<FormLabel component="legend">Gender</FormLabel>
<Field
as={RadioGroup}
aria-label="gender"
name="gender"
style={{display: "initial"}}
>
<FormControlLabel
value="male"
control={<Radio />}
label="Male"
/>
<FormControlLabel
value="female"
control={<Radio />}
label="Female"
/>
<FormControlLabel
value="other"
control={<Radio />}
label="Other"
/>
</Field>
</FormControl>
<FormHelperText>
<ErrorMessage name="gender" />
</FormHelperText>
<Field
as={TextField}
label="Contact No."
name="contactNumber"
helperText={<ErrorMessage name="contactNumber" />}
placeholder="Enter your contact no."
variant="outlined"
fullWidth
style={elementStyle}
required
/>
<Field
as={TextField}
label="Password"
name="password"
type="password"
helperText={<ErrorMessage name="password" />}
placeholder="Enter your password"
variant="outlined"
fullWidth
style={elementStyle}
required
/>
<Field
as={TextField}
label="Confirm Password"
name="confirmPassword"
type="password"
helperText={<ErrorMessage name="confirmPassword" />}
placeholder="Re-enter your password"
variant="outlined"
fullWidth
style={elementStyle}
required
/>
<Button
type="submit"
color="primary"
variant="contained"
disabled={props.isSubmitting}
fullWidth
style={elementStyle}
>
{props.isSubmitting ? "Loading" : "Sign Up"}
</Button>
</Form>
)}
</Formik>
</Paper>
</Grid>
);
};
export default SignUp;