From 8007b05805d5947ef008a79885ba0b890f67c25d Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Fri, 2 Aug 2024 12:46:01 -0700 Subject: Use snackbar to display RSVP status --- client/src/components/Home.tsx | 2 +- client/src/components/RsvpForm.tsx | 44 ++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 10 deletions(-) (limited to 'client') diff --git a/client/src/components/Home.tsx b/client/src/components/Home.tsx index bfa3fa8..b6ecc47 100644 --- a/client/src/components/Home.tsx +++ b/client/src/components/Home.tsx @@ -9,7 +9,7 @@ import p4 from '/EngagmentSession_06.23.2024-267.jpg'; import p5 from '/EngagmentSession_06.23.2024-284.jpg'; function Home() { - const [currentIndex, setIndex] = useState(0); + const [currentIndex, setIndex] = useState(0); const photos = [p0, p1, p2, p3, p4, p5]; useEffect(() => { diff --git a/client/src/components/RsvpForm.tsx b/client/src/components/RsvpForm.tsx index 63981f8..708a1fb 100644 --- a/client/src/components/RsvpForm.tsx +++ b/client/src/components/RsvpForm.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { useRef } from 'react'; import { useOutletContext } from 'react-router-dom'; import { @@ -10,17 +10,42 @@ import { Grid, Radio, RadioGroup, + Snackbar, TextField, } from '@mui/material'; import { useForm, Controller, useFieldArray } from 'react-hook-form'; import { useUpdateGuestMutation } from '../slices/apiSlice'; import type { Guest } from '../slices/apiSlice'; +interface StatusProps { + error: boolean; + setOpen: (open: boolean) => void; +} + +const Status = ({ error, setOpen }: StatusProps) => { + return error ? ( + setOpen(false)}> + RSVP failed + + ) : ( + setOpen(false)}> + RSVP updated + + ); +}; + function RsvpForm() { - const [updateGuest, { isSuccess: success, isError: error }] = - useUpdateGuestMutation(); + const [ + updateGuest, + { isLoading: loading, isSuccess: success, isError: error }, + ] = useUpdateGuestMutation(); const guest: Guest = useOutletContext(); const previousPartySize = useRef(guest?.partySize - 1); + const [open, setOpen] = useState(false); + + useEffect(() => { + setOpen(success || error); + }, [success, error]); const { register, @@ -229,14 +254,15 @@ function RsvpForm() { RSVP -
setOpen(false)} + autoHideDuration={5000} > -
- {success && RSVP updated} - {error && RSVP failed} +
+
-
+ -- cgit v1.2.3