-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRegistration.jsx
More file actions
661 lines (635 loc) · 17.3 KB
/
Registration.jsx
File metadata and controls
661 lines (635 loc) · 17.3 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
"use client";
import {
Autocomplete,
Box,
Button,
Checkbox,
Container,
FormControl,
FormControlLabel,
FormHelperText,
FormLabel,
Grid,
Link,
MenuItem,
Radio,
RadioGroup,
Select,
Stack,
Step,
StepContent,
StepLabel,
Stepper,
TextField,
Typography,
} from "@mui/material";
import * as React from "react";
import { useMemo, useState } from "react";
import HackHPIWrapper from "../Theme/HackHPIWrapper.jsx";
import { LoadingButton } from "@mui/lab";
import { RegistrationRest } from "../../rest/RegistrationRest.js";
import { Mail, Send } from "@mui/icons-material";
import universities from "./universitiesDE.json";
import { GroupManager } from "./GroupManager/GroupManager";
import { INPUT_TYPES } from "./InputTypes.js";
const registrationClosed = false;
const personalData = [
{
formLabel: "First name",
type: INPUT_TYPES.TEXT_FIELD,
input: ["First Name"],
name: "forename",
max: 50,
min: 2,
required: true,
},
{
formLabel: "Last name",
type: INPUT_TYPES.TEXT_FIELD,
input: ["Last Name"],
name: "surname",
max: 50,
min: 2,
required: true,
},
{
formLabel: "Date of birth",
type: INPUT_TYPES.DATE,
name: "age",
required: true,
},
{
formLabel: "Gender",
type: INPUT_TYPES.SELECT,
input: ["male", "female", "diverse"],
name: "gender",
required: true,
},
{
formLabel: "E-mail",
type: INPUT_TYPES.TEXT_FIELD,
input: ["example@example.com"],
name: "email",
regex:
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
required: true,
},
{
formLabel: "T-shirt size",
type: INPUT_TYPES.SELECT,
input: ["XS", "S", "M", "L", "XL", "XXL"],
name: "shirtSize",
required: true,
},
{
formLabel: "Diet preferences",
type: INPUT_TYPES.SELECT,
input: ["omnivore", "vegetarian", "vegan"],
name: "dietPreference",
required: true,
},
{
formLabel: "Allergies",
type: INPUT_TYPES.TEXT_FIELD,
input: ["e. g. gluten, ..."],
helperText:
"Please let us know if you have severe allergies that we must know about.",
name: "allergies",
max: 150,
required: false,
},
{
formLabel: "University/School/Institute",
type: INPUT_TYPES.AUTOCOMPLETE,
input: universities,
name: "university",
max: 150,
min: 2,
required: true,
},
{
formLabel: "Course of study",
type: INPUT_TYPES.TEXT_FIELD,
input: ["e. g. Computer Science"],
name: "fieldOfStudy",
max: 150,
min: 2,
required: true,
},
{
formLabel: "Intended degree",
type: INPUT_TYPES.SELECT,
input: ["High School Diploma", "Bachelor", "Master", "PhD"],
name: "intendedDegree",
required: true,
},
];
const motivation = [
{
formLabel: "How did you hear from us?",
type: INPUT_TYPES.RADIO,
input: [
"university/school/institute",
"friends/other students",
"LinkedIn",
"Instagram",
],
name: "howDidYouHear",
required: false,
},
{
formLabel: "",
type: INPUT_TYPES.EMPTY,
},
{
formLabel: "Your motivation",
type: INPUT_TYPES.TEXT_FIELD,
input: ["My motivation is ..."],
helperText:
"Please write a short text (max. 1200 characters) or 3 key phrases describing your motivation to be part of HackHPI. If you can't think of anything, take the following questions as guidance: Can you share a project, creation, or task that holds a special place as one of your favorites? What motivated you to undertake it, and what aspects make you proud of the outcome?",
rows: 5,
name: "motivation",
max: 1200,
min: 10,
required: true,
fullWidth: true,
},
];
// TODO: maximal capacity for motivation text: 150 words
const skills = [
{
formLabel: "Tech stack",
type: INPUT_TYPES.TEXT_FIELD,
input: ["e. g. Python, ..."],
helperText:
"Please note programming languages, frameworks, etc. you have already worked with.",
rows: 3,
name: "techStack",
max: 300,
required: false,
},
{
formLabel: "Previous experiences / studies / projects...",
type: INPUT_TYPES.TEXT_FIELD,
input: ["e. g. working student at HPI, ..."],
helperText:
"Outline the most important steps of your CV like work experiences, studies and projects.",
rows: 3,
name: "basicOutline",
max: 500,
required: false,
},
{
formLabel: "GitHub account",
type: INPUT_TYPES.TEXT_FIELD,
input: ["e. g. maxm90"],
name: "github",
max: 50,
required: false,
},
{
formLabel: "LinkedIn account",
type: INPUT_TYPES.TEXT_FIELD,
input: ["e. g. /in/max-mustermann"],
name: "linkedin",
max: 50,
required: false,
},
];
const travelSponsorship = [
{
fullWidth: true,
input:
"Our partner, Quantco, provides travel scholarships for participants from around the globe. Applying is easy — just submit your CV and select the checkbox below.",
type: INPUT_TYPES.TYPOGRAPHY,
},
{
fullWidth: true,
input:
"Please email your CV in PDF format to travel-scholarship@hackhpi.org.",
type: INPUT_TYPES.TYPOGRAPHY,
},
{
formLabel: "",
input: [
"I consent to sharing my contact information and CV with our partner, Quantco, and authorize them to contact me.",
],
name: "travelStipend",
type: INPUT_TYPES.CHECKBOX,
required: false,
fullWidth: true,
},
];
const legal = [
{
formLabel: "Privacy Policy",
input: ["I have read and accept the Privacy Policy."],
name: "privacyPolicy",
type: INPUT_TYPES.CHECKBOX,
required: true,
fullWidth: true,
},
{
formLabel: "Recruiting",
input: [
"I agree that my contact and job-related data may be passed on to participating recruiters (sponsors)",
],
name: "recruiters",
type: INPUT_TYPES.CHECKBOX,
required: false,
fullWidth: true,
},
{
input: [
"Film and sound recordings as well as photos will be made at the event, and you agree to their subsequent use by attending the event.",
],
type: INPUT_TYPES.TYPOGRAPHY,
name: "photos",
required: false,
fullWidth: true,
},
];
function Registration() {
const [activeStep, setActiveStep] = React.useState(0);
const [values, setValues] = useState({});
const [isSending, setIsSending] = useState(false);
const registrationRest = useMemo(() => new RegistrationRest(), []);
const steps = [
{
label: "Personal data",
content: personalData,
},
{
label: "Motivation",
content: motivation,
},
{
label: "Skills",
content: skills,
},
{
label: "Team members",
children: (
<GroupManager
eventId={"c11a427e-f679-49b6-8574-b0d3211ad123"}
onGroupChange={(change) => handleChange("group", change)}
/>
),
},
{
label: "Travel Scholarship",
content: travelSponsorship,
},
{
label: "Confirmation",
content: legal,
},
{
label: "E-Mail Verification",
children: (
<Box
sx={{
width: "100%",
height: "20vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
paddingTop: "3rem",
}}
>
<Stack spacing={3} justifyContent={"center"}>
<Mail color={"inherit"} sx={{ fontSize: "2rem" }} />
<Typography>
To complete the registration, please click on the link in the
email we sent you!
</Typography>
</Stack>
</Box>
),
},
];
function handleChange(name, inputValue) {
const newValue = { ...values };
newValue[name] = inputValue;
setValues(newValue);
}
function enableNext(inputList, name) {
if (!inputList) {
console.log("No input list");
return;
}
if (inputList.children) {
return true;
}
const result = inputList.content.reduce((previous, current) => {
if (
!current.required &&
(values[current.name] === undefined || values[current.name] === "")
) {
return previous && true;
}
if (
current.required &&
((!values[current.name] && values[current.name] !== 0) ||
values[current.name] === "")
) {
return previous && false;
}
if (current.regex && !values[current.name].match(current.regex)){
return previous && false;
}
const meetsMax = current.max
? values[current.name]?.length <= current.max
: true;
const meetsMin = current.min
? values[current.name]?.length >= current.min
: true;
const meetsAll = meetsMax && meetsMin;
return previous && meetsAll;
}, true);
return result;
}
function contentForm(props) {
const type = props.type;
const input = props.input;
const name = props.name;
const rows = props.rows;
switch (type) {
case INPUT_TYPES.TEXT_FIELD:
return (
<TextField
type="text"
placeholder={input[0]}
multiline
minRows={rows}
name={name}
value={values[name] ?? ""}
onChange={(event) =>
handleChange(event.target.name, event.target.value)
}
/>
);
case INPUT_TYPES.DATE:
return (
<TextField
type="date"
name={name}
value={values[name] ?? ""}
style={{ color: "inherit" }}
onChange={(event) =>
handleChange(event.target.name, event.target.value)
}
/>
);
case INPUT_TYPES.SELECT:
return (
<Select
value={values[name] ?? ""}
displayEmpty
name={name}
onChange={(event) =>
handleChange(event.target.name, event.target.value)
}
>
<MenuItem value="">
<em>Please select...</em>
</MenuItem>
{input.map((item, i) => (
<MenuItem value={item} key={i}>
{item}
</MenuItem>
))}
</Select>
);
case INPUT_TYPES.RADIO:
return (
<RadioGroup
value={values[name] ?? ""}
name={name}
onChange={(event, value) => handleChange(event.target.name, value)}
errorCheck
>
{input.map((item, i) => (
<FormControlLabel
value={item}
control={<Radio />}
key={i}
label={item}
/>
))}
</RadioGroup>
);
case INPUT_TYPES.CHECKBOX:
return (
<FormControlLabel
control={
<Checkbox
name={name}
checked={values[name] ?? false}
onChange={(event, value) => handleChange(name, value)}
/>
}
label={input.join("")}
/>
);
case INPUT_TYPES.AUTOCOMPLETE:
return (
<Autocomplete
freeSolo
value={values[name] ?? ""}
options={input}
autoSelect
onChange={(event, value) => handleChange(name, value)}
renderInput={(params) => (
<TextField
{...params}
name={name}
onChange={(event) => handleChange(name, event.target.value)}
/>
)}
/>
);
case INPUT_TYPES.TYPOGRAPHY:
return <Typography fullWidth>{input}</Typography>;
default:
return null;
}
}
function gridItemSize(props) {
if (props.name === "motivation" || props.fullWidth) {
return 12;
} else {
return 6;
}
}
const handleNext = () => {
setActiveStep((prevActiveStep) => prevActiveStep + 1);
};
const handleBack = () => {
setActiveStep((prevActiveStep) => prevActiveStep - 1);
};
const submitForm = () => {
setIsSending(true);
registrationRest
.addRegistration({
firstName: values.forename,
lastName: values.surname,
email: values.email,
fieldData: JSON.stringify(values),
signUpForm: {
id: "e73735ad-c930-44ee-8631-6c5bc3aed029",
//id: "2f1c60f2-f30b-4432-8129-9131c6e398dd",
},
group: values.group ? values.group : undefined,
})
.then(() => {
setIsSending(false);
handleNext();
})
.catch((error) => {
alert(
"Could not save Registration. Please try again. If problem persists, please contact team@hackhpi.org. Error: " +
JSON.stringify(error.data),
);
setIsSending(false);
});
};
function renderNextButton(index, step) {
if (index === steps.length - 1) {
return;
}
if (index === steps.length - 2) {
return (
<LoadingButton
variant={"contained"}
startIcon={<Send />}
loading={isSending}
onClick={submitForm}
disabled={!enableNext(steps[index], step.label)}
>
Send
</LoadingButton>
);
}
return (
<Button
variant="contained"
onClick={handleNext}
disabled={!enableNext(steps[index], step.label)}
>
Next
</Button>
);
}
function renderRegistration() {
if (registrationClosed) {
return (
<Box sx={{ paddingTop: 10 }}>
<Typography variant={"h5"} fontWeight={"bold"} gutterBottom>
Registration is closed!
</Typography>
<Typography
variant={"h5"}
fontWeight={"bold"}
color={"text.disabled"}
>
We are currently reviewing all applications and will reach out to
you soon.
</Typography>
</Box>
);
}
return (
<>
<Stepper activeStep={activeStep} orientation="vertical" sx={{ mt: 5 }}>
{steps.map((step, index) => (
<Step key={index}>
<StepLabel
optional={
index === 3 ? (
<Typography variant="caption">optional</Typography>
) : null
}
>
<Box direction="row" spacing={1}>
<Typography>{step.label}</Typography>
</Box>
</StepLabel>
<StepContent>
<Grid container>
<Grid item md={8} xs={12}>
<Grid container spacing={3}>
{step.children
? step.children
: step.content.map((item, i) => (
<Grid item md={gridItemSize(item)} xs={12} key={i}>
<FormControl fullWidth>
<FormLabel focused={false}>
{item.formLabel}
{item.required ? "*" : ""}
</FormLabel>
{contentForm({
type: item.type,
input: item.input,
rows: item.rows,
name: item.name,
})}
<FormHelperText>
{item.helperText}
</FormHelperText>
</FormControl>
</Grid>
))}
<Grid item xs={12}>
<Stack direction={"row"} spacing={2}>
{renderNextButton(index, step)}
{index === steps.length - 1 ? undefined : (
<Grid item xs={2}>
<Button
disabled={index === 0}
onClick={handleBack}
color={"inherit"}
>
Back
</Button>
</Grid>
)}
</Stack>
</Grid>
</Grid>
</Grid>
</Grid>
</StepContent>
</Step>
))}
</Stepper>
<Typography color={"text.disabled"} sx={{ marginTop: 3 }}>
Read our{" "}
<Link href={"/privacy"} color={"inherit"}>
privacy policy
</Link>{" "}
for information on how we handle your data and what your rights are.
</Typography>
</>
);
}
return (
<HackHPIWrapper>
<Container sx={{ paddingTop: 10, paddingBottom: 10 }} id={"signupForm"}>
<Typography variant={"h2"} component={"h1"}>
Registration
</Typography>
{!registrationClosed ? (
<Typography variant={"subtitle1"} gutterBottom>
Apply now before February 28th!
</Typography>
) : undefined}
{renderRegistration()}
</Container>
</HackHPIWrapper>
);
}
export default Registration;
//TODO:
// Ja zur Datenschutzerklärung
// Please check your mailbox to confirm your registration