From da7152b6b373ba55aaab980a024d9882c4c5c6b2 Mon Sep 17 00:00:00 2001 From: Harini312821 Date: Thu, 1 Aug 2024 13:56:44 +0800 Subject: [PATCH] updated create events and event details --- client/src/pages/CreateEventsPage.tsx | 40 +++++++++++++++---- client/src/pages/EventDetailsPage.tsx | 56 +++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/client/src/pages/CreateEventsPage.tsx b/client/src/pages/CreateEventsPage.tsx index c85acc8..522262d 100644 --- a/client/src/pages/CreateEventsPage.tsx +++ b/client/src/pages/CreateEventsPage.tsx @@ -1,3 +1,4 @@ +import React, { useState, useEffect } from "react"; import { Button } from "@nextui-org/react"; import { Formik, Form } from "formik"; import * as Yup from "yup"; @@ -8,6 +9,7 @@ import NextUIFormikTextarea from "../components/NextUIFormikTextarea"; import config from "../config"; import { ArrowUTurnLeftIcon } from "../icons"; +// Validation schema const validationSchema = Yup.object({ title: Yup.string() .trim() @@ -40,8 +42,22 @@ const validationSchema = Yup.object({ }); const CreateEventsPage = () => { + const [townCouncils, setTownCouncils] = useState([]); const navigate = useNavigate(); + useEffect(() => { + const fetchTownCouncils = async () => { + try { + const res = await axios.get(`${config.serverAddress}/users/town-councils-metadata`); + setTownCouncils(JSON.parse(res.data).townCouncils); + } catch (error) { + console.error("Failed to fetch town councils:", error); + } + }; + + fetchTownCouncils(); + }, []); + const initialValues = { title: "", description: "", @@ -100,7 +116,7 @@ const CreateEventsPage = () => { validationSchema={validationSchema} onSubmit={handleSubmit} > - {({ isValid, dirty, isSubmitting }) => ( + {({ isValid, dirty, isSubmitting, setFieldValue }) => (
{ placeholder="Enter event time" labelPlacement="inside" /> - +
+ + +
{ const { id } = useParams<{ id: string }>(); // Get the event ID from the URL const [event, setEvent] = useState(null); // State to store event details + const [similarEvents, setSimilarEvents] = useState([]); // State to store similar events const navigate = useNavigate(); useEffect(() => { @@ -17,6 +18,18 @@ const EventDetailsPage = () => { const res = await instance.get(`${config.serverAddress}/events/${id}`); console.log("Fetched event details:", res.data); // Log the fetched data setEvent(res.data); + + // Fetch all events to find similar ones + const allEventsRes = await instance.get(`${config.serverAddress}/events`); + const allEvents = allEventsRes.data; + + // Find similar events based on location and category, excluding the current event + const similar = allEvents.filter((e: any) => + e.id !== Number(id) && // Make sure to exclude the current event + (e.location === res.data.location || e.category === res.data.category) + ); + + setSimilarEvents(similar); } catch (error) { console.error("Failed to fetch event details:", error); } @@ -31,7 +44,7 @@ const EventDetailsPage = () => {
+ + {/* Similar Events Section */} +
+

Similar Events You Might Be Interested In

+
+ {similarEvents.length === 0 ? ( +

No similar events available.

+ ) : ( + similarEvents.map((similarEvent: any) => ( + + +

{similarEvent.title}

+
+ + {similarEvent.title} + + + + +
+ )) + )} +
+
); };