diff --git a/src/components/dashboard/EventsSection.astro b/src/components/dashboard/EventsSection.astro index a9a393a..5b4a94e 100644 --- a/src/components/dashboard/EventsSection.astro +++ b/src/components/dashboard/EventsSection.astro @@ -1,6 +1,4 @@ --- -import { Icon } from "@iconify/react"; -import JSZip from "jszip"; import FilePreview from "./universal/FilePreview"; import EventCheckIn from "./EventsSection/EventCheckIn"; import EventLoad from "./EventsSection/EventLoad"; diff --git a/src/components/dashboard/EventsSection/EventCheckIn.tsx b/src/components/dashboard/EventsSection/EventCheckIn.tsx index f2b48ab..bb9b2bd 100644 --- a/src/components/dashboard/EventsSection/EventCheckIn.tsx +++ b/src/components/dashboard/EventsSection/EventCheckIn.tsx @@ -4,26 +4,11 @@ import { Authentication } from "../../../scripts/pocketbase/Authentication"; import { Update } from "../../../scripts/pocketbase/Update"; import { SendLog } from "../../../scripts/pocketbase/SendLog"; import { Icon } from "@iconify/react"; +import type { Event, AttendeeEntry } from "../../../schemas/pocketbase"; - -interface Event { - id: string; - event_name: string; - event_code: string; - location: string; - points_to_reward: number; - attendees: AttendeeEntry[]; - start_date: string; - end_date: string; - has_food: boolean; - description: string; - files: string[]; -} - -interface AttendeeEntry { - user_id: string; - time_checked_in: string; - food: string; +// Extended Event interface with additional properties needed for this component +interface ExtendedEvent extends Event { + description?: string; // This component uses 'description' but schema has 'event_description' } // Toast management system @@ -109,7 +94,8 @@ const EventCheckIn = () => { const currentUser = auth.getCurrentUser(); if (!currentUser) { - throw new Error("You must be logged in to check in to events"); + createToast("You must be logged in to check in to events", "error"); + return; } // Find the event with the given code @@ -122,7 +108,8 @@ const EventCheckIn = () => { } // Check if user is already checked in - if (event.attendees.some((entry) => entry.user_id === currentUser.id)) { + const attendees = event.attendees || []; + if (attendees.some((entry) => entry.user_id === currentUser.id)) { throw new Error("You have already checked in to this event"); } @@ -157,6 +144,27 @@ const EventCheckIn = () => { throw new Error("You must be logged in to check in to events"); } + // Check if user is already checked in + const userId = auth.getUserId(); + + if (!userId) { + createToast("You must be logged in to check in to an event", "error"); + return; + } + + // Initialize attendees array if it doesn't exist + const attendees = event.attendees || []; + + // Check if user is already checked in + const isAlreadyCheckedIn = attendees.some( + (attendee) => attendee.user_id === userId + ); + + if (isAlreadyCheckedIn) { + createToast("You are already checked in to this event", "warning"); + return; + } + // Create attendee entry with check-in details const attendeeEntry: AttendeeEntry = { user_id: currentUser.id, diff --git a/src/components/dashboard/EventsSection/EventLoad.tsx b/src/components/dashboard/EventsSection/EventLoad.tsx index 263476d..5b009dc 100644 --- a/src/components/dashboard/EventsSection/EventLoad.tsx +++ b/src/components/dashboard/EventsSection/EventLoad.tsx @@ -2,30 +2,16 @@ import { useEffect, useState } from "react"; import { Icon } from "@iconify/react"; import { Get } from "../../../scripts/pocketbase/Get"; import { Authentication } from "../../../scripts/pocketbase/Authentication"; +import type { Event, AttendeeEntry } from "../../../schemas/pocketbase"; -interface Event { - id: string; - event_name: string; - event_code: string; - location: string; - points_to_reward: number; - attendees: AttendeeEntry[]; - start_date: string; - end_date: string; - has_food: boolean; - description: string; - files: string[]; -} - -interface AttendeeEntry { - user_id: string; - time_checked_in: string; - food: string; +// Extended Event interface with additional properties needed for this component +interface ExtendedEvent extends Event { + description?: string; // This component uses 'description' but schema has 'event_description' } declare global { interface Window { - openDetailsModal: (event: Event) => void; + openDetailsModal: (event: ExtendedEvent) => void; downloadAllFiles: () => Promise; currentEventId: string; [key: string]: any; @@ -118,13 +104,13 @@ const EventLoad = () => {
- {event.description || "No description available"} + {event.event_description || "No description available"}
{event.files && event.files.length > 0 && (