-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddAvailabilityPage.js
More file actions
117 lines (101 loc) · 3.42 KB
/
AddAvailabilityPage.js
File metadata and controls
117 lines (101 loc) · 3.42 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
function AddAvailabilityPage() {
const [date, setDate] = React.useState("");
const [startTime, setStartTime] = React.useState("");
const [endTime, setEndTime] = React.useState("");
const [diningType, setDiningType] = React.useState("");
const [location, setLocation] = React.useState("");
const [title, setTitle] = React.useState("");
const userId = localStorage.getItem("user_id");
function handleSubmit() {
if (!date || !startTime || !endTime || !diningType) {
alert("Please fill out date, time, and dining type.");
return;
}
if (startTime >= endTime) {
alert("End time must be after start time.");
return;
}
const payload = {
host_id: parseInt(userId),
date,
time_range: `${startTime} - ${endTime}`,
dining_type: diningType,
location,
title,
is_availability: true,
is_public: true
};
fetch("http://localhost:3001/api/events", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
})
.then(res => res.json())
.then(data => {
if (data.id) {
window.location.hash = "#calendar";
} else {
alert("Failed to create availability.");
}
});
}
return (
<div className="flex flex-col min-h-screen pb-16 bg-[#F1FAEE] p-4">
<h1 className="text-2xl font-bold mb-4">Add Availability</h1>
<label className="font-semibold">Date:</label>
<input
type="date"
value={date}
onChange={(e) => setDate(e.target.value)}
className="w-full mb-5 px-4 py-2 rounded border"
/>
<label className="font-semibold">Start Time:</label>
<input
type="time"
value={startTime}
onChange={(e) => setStartTime(e.target.value)}
className="w-full mb-5 px-4 py-2 rounded border"
/>
<label className="font-semibold">End Time:</label>
<input
type="time"
value={endTime}
onChange={(e) => setEndTime(e.target.value)}
className="w-full mb-5 px-4 py-2 rounded border"
/>
<label className="font-semibold">Meal Type:</label>
<select
value={diningType}
onChange={(e) => setDiningType(e.target.value)}
className="w-full mb-5 px-4 py-2 rounded border"
>
<option value="">Select Meal</option>
<option value="Breakfast">Breakfast</option>
<option value="Lunch">Lunch</option>
<option value="Dinner">Dinner</option>
</select>
<label className="font-semibold">Optional Location:</label>
<input
type="text"
value={location}
onChange={(e) => setLocation(e.target.value)}
className="w-full mb-5 px-4 py-2 rounded border"
/>
<label className="font-semibold">Optional Title:</label>
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
className="w-full mb-5 px-4 py-2 rounded border"
/>
<button
onClick={handleSubmit}
className="button-primary mt-4"
>
Add Availability
</button>
<Navigation />
</div>
);
}
window.AddAvailabilityPage = AddAvailabilityPage;