-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflight_booking.js
More file actions
61 lines (60 loc) · 1.83 KB
/
flight_booking.js
File metadata and controls
61 lines (60 loc) · 1.83 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
import { useState } from "react";
import "./styles.css";
export default function App() {
const [origin, setOrigin] = useState("");
const [destination, setDestination] = useState("");
const [date, setDate] = useState("");
const [bookingStatus, setBookingStatus] = useState(false);
const [bookingConfirmation, setBookingConfirmation] = useState(null);
const handleSubmit = (event) => {
event.preventDefault();
setBookingStatus(true);
setTimeout(() => {
setBookingConfirmation(
`Flight booked from ${origin} to ${destination} on ${date}`
);
setBookingStatus(false);
}, 1000); // Simulating network delay
};
return (
<div className="flight-booking">
<h2>Book Your Flight</h2>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label htmlFor="origin">Origin:</label>
<input
type="text"
id="origin"
value={origin}
onChange={(e) => setOrigin(e.target.value)}
required
/>
</div>
<div className="form-group">
<label htmlFor="destination">Destination:</label>
<input
type="text"
id="destination"
value={destination}
onChange={(e) => setDestination(e.target.value)}
required
/>
</div>
<div className="form-group">
<label htmlFor="date">Flight Date:</label>
<input
type="date"
id="date"
value={date}
onChange={(e) => setDate(e.target.value)}
required
/>
</div>
<button type="submit" disabled={bookingStatus}>
{bookingStatus ? "Booking..." : "Book Flight"}
</button>
</form>
{bookingConfirmation && <p>{bookingConfirmation}</p>}
</div>
);
}