Newer
Older
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
import { useState } from 'react';
import { useForm } from 'react-hook-form';
interface IFlightCreationForm {
origin: string;
destination: string;
departure: string;
arrival: string;
economyCapacity: number;
businessCapacity: number;
economyPrice: number;
businessPrice: number;
}
function FlightCreationForm() {
const [error, setError] = useState('');
const { register, handleSubmit } = useForm<IFlightCreationForm>({mode: 'onChange'});
const onSubmit = (formValue : IFlightCreationForm) => {
if (!Number.isInteger(formValue.businessCapacity) || !Number.isInteger(formValue.economyCapacity)) {
setError('Please enter an integer for the capacity.')
return;
}
}
return (
<>
<div className='flightCreationForm'>
<form onSubmit={handleSubmit(onSubmit)}>
<div className='card register-card'>
<div className='form-group'>
<label>Origin</label>
<input type='text' placeholder='Enter origin' {...register('origin', { required: true })} />
</div>
<div className='form-group'>
<label>Destination</label>
<input type='text' placeholder='Enter destination' {...register('destination', { required: true })} />
</div>
<div className='form-group'>
<label>Departure Time</label>
<input type='datetime-local' placeholder='Enter departure time' {...register('departure', { required: true })} />
</div>
<div className='form-group'>
<label>Arrival Time</label>
<input type='datetime-local' placeholder='Enter arrival time' {...register('arrival', { required: true })} />
</div>
<div className='form-group'>
<label>Economy Class Capacity</label>
<input type='number' placeholder='Enter capacity' {...register('economyCapacity', { required: true })} />
</div>
<div className='form-group'>
<label>Business Class Capacity</label>
<input type='number' placeholder='Enter capacity' {...register('businessCapacity', { required: true })} />
</div>
<div className='form-group'>
<label>Economy Class Price</label>
<input type='number' placeholder='Enter price' {...register('economyPrice', { required: true })} />
</div>
<div className='form-group'>
<label>Business Class Price</label>
<input type='number' placeholder='Enter price' {...register('businessPrice', { required: true })} />
</div>
<div className='form-group'>
<button type='submit'>Submit</button>
</div>
<div className='form-group'>
{error && <span>{error}</span>}
</div>
</div>
</form>
</div>
</>
)
}
export default FlightCreationForm;