Trigger data refetch on mount for events and themes pages

Added `useEffect` hooks to automatically refetch guests data in the Event Detail Page and themes data in the Event Themes Page upon component mount. This ensures the displayed data is always up-to-date when the user navigates to these pages.
This commit is contained in:
2025-03-19 09:02:57 +01:00
parent 31c6ae3f5c
commit 1f1192fb62
2 changed files with 11 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import Link from "next/link";
import { Loader2Icon, PaletteIcon } from "lucide-react"; import { Loader2Icon, PaletteIcon } from "lucide-react";
import { useEventThemes } from "@/context/event-theme-context"; import { useEventThemes } from "@/context/event-theme-context";
import { getServerFileUrl } from "@/lib/utils"; import { getServerFileUrl } from "@/lib/utils";
import { useEffect } from "react";
export default function EventThemesPage() { export default function EventThemesPage() {
// const { data: themes, isLoading } = useQuery({ // const { data: themes, isLoading } = useQuery({
@@ -24,8 +25,11 @@ export default function EventThemesPage() {
// queryFn: () => listEventThemes().then(res => res.data), // queryFn: () => listEventThemes().then(res => res.data),
// }); // });
const { themes, isLoadingThemes } = useEventThemes(); const { themes, refetchThemes, isLoadingThemes } = useEventThemes();
useEffect(() => {
refetchThemes();
}, []);
return ( return (
<div className="max-w-7xl mx-auto py-6 px-4"> <div className="max-w-7xl mx-auto py-6 px-4">
<div className="flex items-center justify-between mb-8"> <div className="flex items-center justify-between mb-8">

View File

@@ -27,11 +27,13 @@ import {
import { useEventThemes } from "@/context/event-theme-context"; import { useEventThemes } from "@/context/event-theme-context";
import { getServerFileUrl } from "@/lib/utils"; import { getServerFileUrl } from "@/lib/utils";
import GuestsList from "@/components/guests/guests-list"; import GuestsList from "@/components/guests/guests-list";
import { useGuests } from "@/context/guest-context";
export default function EventDetailPage() { export default function EventDetailPage() {
const { slug } = useParams<{ slug: string }>(); const { slug } = useParams<{ slug: string }>();
const { event, fetchEventBySlug, isLoadingEvent, eventError } = useEvents(); const { event, fetchEventBySlug, isLoadingEvent, eventError } = useEvents();
const { themes } = useEventThemes(); const { themes } = useEventThemes();
const { refetchGuests } = useGuests();
const currentTheme = const currentTheme =
event?.theme_id && themes event?.theme_id && themes
? themes.find((theme) => theme.id === event.theme_id) ? themes.find((theme) => theme.id === event.theme_id)
@@ -44,6 +46,10 @@ export default function EventDetailPage() {
fetchEventBySlug(slug); fetchEventBySlug(slug);
}, [slug, fetchEventBySlug]); }, [slug, fetchEventBySlug]);
useEffect(() => {
refetchGuests();
}, []);
if (isLoadingEvent) { if (isLoadingEvent) {
return ( return (
<div className="flex items-center justify-center min-h-[50vh]"> <div className="flex items-center justify-center min-h-[50vh]">