-
Notifications
You must be signed in to change notification settings - Fork 2
/
InsertJob.tsx
84 lines (80 loc) · 2.11 KB
/
InsertJob.tsx
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
import {
Box,
Button,
Center,
FormControl,
FormLabel,
Input,
Select,
} from '@chakra-ui/react';
import { useState } from 'react';
import GenericService from '../service/GenericService';
import { useNavigate } from 'react-router-dom';
import Job from '../dto/Job';
export default function InserJob() {
const [form, setForm] = useState({ title: '', description: '', type: 0 });
const updateFormData = (evt: any) => {
const name = evt.target.name;
const value =
evt.target.type === 'checkbox' ? evt.target.checked : evt.target.value;
setForm({
...form,
[name]: value,
});
};
const navigate = useNavigate();
const onSubmit = () => {
const data: Job = {
title: form.title,
description: form.description,
type: form.type,
};
GenericService.create<Job>('api/v1/job', data).then((data) => {
console.log(data);
if (form.type == 0) {
navigate('/offers');
} else if (form.type == 1) {
navigate('/requests');
}
});
};
return (
<Center>
<Box width={'3xl'}>
<FormControl isRequired>
<FormLabel>Title</FormLabel>
<Input
placeholder="Title"
value={form.title}
name="title"
onChange={(e) => updateFormData(e)}
/>
</FormControl>
<FormControl isRequired>
<FormLabel>Description</FormLabel>
<Input
name="description"
value={form.description}
placeholder="Description"
onChange={(e) => updateFormData(e)}
/>
</FormControl>
<FormControl isRequired>
<FormLabel>Type</FormLabel>
<Select
placeholder="Select type"
name="type"
value={form.type}
onChange={(e) => updateFormData(e)}
>
<option value="0">Offer</option>
<option value="1">Request</option>
</Select>
</FormControl>
<Button mt={4} colorScheme="teal" type="submit" onClick={onSubmit}>
Submit
</Button>
</Box>
</Center>
);
}