97
98 useEffect(() => {
99 fetch("/api/classes")
100 .then(res => res.json())
101 .then(data => {
102 console.log("Fetched classes:", data);
103 setClasses(data);
104 })
105 .catch(error => console.error("Error fetching classes:", error));
106 }, []);
107
132
133 useEffect(() => {
134 console.log("Fetching class details for ID:", id);
135 fetch(`/api/classes/${id}`)
136 .then(res => res.json())
137 .then(data => {
138 console.log("Fetched class details:", data);
139 setClassInfo(data);
140 })
141 .catch(error => console.error("Error fetching class details:", error));
142
143 if (email) {
144 console.log("Checking registration status for email:", email);
145 fetch(`/api/classes/${id}/registration?email=${email}`)
146 .then(res => res.json())
147 .then(data => {
148 console.log("Fetched registration status:", data);
149 setIsRegistered(data.registered);
150 })
151 .catch(error => console.error("Error fetching registration status:", error));
152 }
153 }, [id, email]);
156
157 const handleRegister = () => {
158 fetch(`/api/classes/${id}/register`, {
159 method: "POST",
160 headers: { "Content-Type": "application/json" },
174
175 const handleCancel = () => {
176 fetch(`/api/classes/${id}/cancel`, {
177 method: "POST",
178 headers: { "Content-Type": "application/json" },
193 const handleDelete = () => {
194 if (window.confirm("Are you sure you want to delete this class?")) {
195 fetch(`/api/classes/${id}`, { method: "DELETE" })
196 .then(() => navigate("/classes"))
197 .catch(error => console.error("Error deleting class:", error));
266 useEffect(() => {
267 if (id) {
268 fetch(`/api/classes/${id}`)
269 .then(res => res.json())
270 .then(data => {
275 });
276 })
277 .catch(error => console.error("Error fetching class data:", error));
278 }
279 }, [id]);
291 const url = id ? `/api/classes/${id}` : "/api/classes";
292
293 fetch(url, {
294 method,
295 headers: { "Content-Type": "application/json" },
415 const emailList = emails.split(/[\s,]+/).filter(email => email.trim() !== "");
416
417 fetch(`/api/classes/${id}/bulk-add`, {
418 method: "POST",
419 headers: { "Content-Type": "application/json" },
738
739 if (url.pathname.startsWith("/api")) {
740 return app.fetch(request);
741 }
742