This repository was archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathVolunteerForm.js
More file actions
226 lines (211 loc) · 6.15 KB
/
VolunteerForm.js
File metadata and controls
226 lines (211 loc) · 6.15 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
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
225
226
import React, { useState } from 'react';
import {
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
Button,
Typography
} from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import CircularProgress from '@material-ui/core/CircularProgress';
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator';
import { useSnackbar } from 'notistack';
import axios from 'axios';
const useStyles = makeStyles(theme => ({
btn: {
backgroundColor: '#A60000',
color: '#ffffff',
textTransform: 'capitalize',
[theme.breakpoints.down('sm')]: {
width: '100%'
},
'&:hover': {
backgroundColor: 'rgba(166, 0, 0, 0.8)'
}
},
textField: {
marginBottom: '16px'
},
submissions: {
width: '80px',
height: '50px'
}
}));
export default function VolunteerFormModal({ className }) {
const classes = useStyles();
const [open, setOpen] = useState(false);
const [formData, updateFormData] = useState({});
const [submitting, setSubmitting] = useState(0);
const { enqueueSnackbar } = useSnackbar();
const handleClickOpen = () => {
setOpen(true);
formData.countryCode = '+91';
formData.phone = '';
};
const handleClose = () => {
setOpen(false);
};
const handleChange = event => {
updateFormData({
...formData,
[event.target.name]: event.target.value
});
};
const handleSubmit = e => {
formData.phone = `${formData.countryCode}${formData.phone}`;
setSubmitting(1);
e.preventDefault();
axios({
method: 'post',
url: 'https://us-central1-codeforcauseorg.cloudfunctions.net/widgets', // TO CHANGE******************
data: formData
})
.then(response => {
setSubmitting(0);
handleClose();
enqueueSnackbar('Application Submitted Successfully');
})
.catch(error => {
enqueueSnackbar('Application Failed. Try again later');
});
};
return (
<div>
<Button
className={className}
size="large"
variant="outlined"
onClick={handleClickOpen}
>
Apply now
</Button>
<Dialog
fullWidth
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">
Apply to Volunteer with Codeforcause
</DialogTitle>
<DialogContent>
<DialogContentText>
<Typography>Please provide your details below.</Typography>
</DialogContentText>
<ValidatorForm onSubmit={handleSubmit}>
<TextValidator
required
key="name"
className={classes.textField}
label="Full Name"
variant="outlined"
value={formData.name}
fullWidth
name="name"
onChange={handleChange}
validators={['required']}
errorMessages={['This is a required field']}
/>
<TextValidator
required
key="email"
className={classes.textField}
label="Email"
variant="outlined"
value={formData.email}
fullWidth
name="email"
onChange={handleChange}
validators={['required', 'isEmail']}
errorMessages={[
'This is a required field',
'Please enter a valid email'
]}
/>
<TextValidator
key="contact"
className={classes.textField}
label="WhatsApp / Contact Number"
variant="outlined"
value={formData.phone}
fullWidth
name="phone"
onChange={handleChange}
validators={[
'matchRegexp:^[+]*[(]*[+]{0,1}[0-9]{1,3}[)]{0,1}[-s./0-9]*$'
]}
errorMessages={['Please enter a valid contact number']}
/>
<TextValidator
required
key="linkedIn"
className={classes.textField}
label="LinkedIn URL"
variant="outlined"
value={formData.linkedIn}
fullWidth
name="linkedIn"
onChange={handleChange}
validators={[
'required',
'matchRegexp:^(http(s)?://)?([w]+.)?linkedin.com/(pub|in|profile)'
]}
errorMessages={[
'This is a required field',
'Please enter a valid URL'
]}
/>
<TextValidator
required
key="interests"
className={classes.textField}
label="Interested Domains"
variant="outlined"
value={formData.interests}
fullWidth
name="interests"
onChange={handleChange}
validators={['required']}
errorMessages={['This is a required field']}
/>
<TextValidator
required
key="videoLink"
className={classes.textField}
label="Demo Video Link (3 - 10 min)"
variant="outlined"
value={formData.videoLink}
fullWidth
name="videoLink"
onChange={handleChange}
validators={['required']}
errorMessages={['This is a required field']}
/>
{submitting === 0 ? (
<Button type="submit" variant="contained" color="secondary">
Submit
</Button>
) : (
<div className={classes.submissions}>
<CircularProgress />
</div>
)}
<Button
variant="outlined"
onClick={handleClose}
color="secondary"
style={{
marginLeft: '16px'
}}
>
Cancel
</Button>
</ValidatorForm>
</DialogContent>
<DialogActions></DialogActions>
</Dialog>
</div>
);
}