From 9f0fcf58c4dff22c000c2572b2c6ad04e2c3fe48 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 1 Jun 2025 09:13:02 +0200 Subject: [PATCH] Display a toast indicating affinities have been reset --- app/[slug]/dashboard/guests/page.tsx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/[slug]/dashboard/guests/page.tsx b/app/[slug]/dashboard/guests/page.tsx index e76e172..d42b0ba 100644 --- a/app/[slug]/dashboard/guests/page.tsx +++ b/app/[slug]/dashboard/guests/page.tsx @@ -14,10 +14,13 @@ import GroupsTable from '@/app/ui/groups/table'; import SkeletonTable from '@/app/ui/guests/skeleton-row'; import GuestsTable from '@/app/ui/guests/table'; import { TabPanel, TabView } from 'primereact/tabview'; -import { Suspense, useState } from 'react'; +import { Toast } from 'primereact/toast'; +import { Suspense, useRef, useState } from 'react'; export default function Page() { + const toast = useRef(null); + function refreshGuests() { new AbstractApi().getAll(new GuestSerializer(), (objects: Guest[]) => { setGuests(objects); @@ -36,10 +39,28 @@ export default function Page() { fetch(`/api/${getSlug()}/groups/affinities/reset`, { method: 'POST', headers: { - 'Accept': 'application/json', - 'X-CSRF-TOKEN': getCsrfToken(), + 'Accept': 'application/json', + 'X-CSRF-TOKEN': getCsrfToken(), } }) + .then(response => { + if (response.ok) { + showAffinitiesResetSuccess(); + } else { + console.error('Failed to reset affinities'); + } + }) + .catch(error => { + console.error('Error resetting affinities:', error); + }); + } + + function showAffinitiesResetSuccess() { + toast.current?.show({ + severity: 'success', + summary: 'Affinities reset', + detail: 'All affinities have been reset to default values.' + }); } const [groupsLoaded, setGroupsLoaded] = useState(false); @@ -82,6 +103,7 @@ export default function Page() {
+