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
|
import React, { useState } from 'react';
import { Grid, TextField, Button } from '@material-ui/core';
import { post } from '../../requests';
import { Event } from '../../types';
interface PropTypes {
mutate: () => void;
}
const EventForm: React.FC<PropTypes> = ({ mutate }) => {
const [name, setName] = useState<string>('');
const [schedule, setSchedule] = useState<string>('* * * * * *');
const [attendanceId, setAttendanceId] = useState<string>('');
const [conferenceId, setConferenceId] = useState<string>('');
const createHandler = (setter: any) => (event: React.ChangeEvent<HTMLInputElement>) => {
setter(event.target.value);
};
const handleSubmit = () => {
if (schedule && conferenceId) {
const event: Partial<Event> = {
name,
schedule,
context: {
attendanceId,
conferenceId,
participants: []
}
};
setName('');
setAttendanceId('');
setConferenceId('');
setSchedule('');
return post('/events', event).then(() => mutate());
}
}
return (
<Grid container spacing={2}>
<Grid item sm={6} xs={12}>
<TextField
value={name}
onChange={createHandler(setName)}
variant="outlined"
label="Name"
fullWidth
required
/>
</Grid>
<Grid item sm={6} xs={12}>
<TextField
value={schedule}
onChange={createHandler(setSchedule)}
variant="outlined"
label="Date"
fullWidth
required
/>
</Grid>
<Grid item sm={6} xs={12}>
<TextField
value={conferenceId}
onChange={createHandler(setConferenceId)}
variant="outlined"
label="Conference ID"
fullWidth
required
/>
</Grid>
<Grid item sm={6} xs={12}>
<TextField
value={attendanceId}
onChange={createHandler(setAttendanceId)}
variant="outlined"
label="Attendance ID"
fullWidth
/>
</Grid>
<Grid item sm={2} xs={12}>
<Button
onClick={handleSubmit}
variant="contained"
size="large"
color="primary"
fullWidth
>
Create event
</Button>
</Grid>
</Grid>
);
};
export default EventForm;
|