diff --git a/src/app/harbor/tavern/tavern.tsx b/src/app/harbor/tavern/tavern.tsx index ee4ce997..badedffa 100644 --- a/src/app/harbor/tavern/tavern.tsx +++ b/src/app/harbor/tavern/tavern.tsx @@ -58,6 +58,7 @@ const RsvpStatusSwitcher = ({ const [editedFlag, setEditedFlag] = useState(false) const [attendeeNoOrganizerModal, setAttendeeNoOrganizerModal] = useState(false) + const [submitting, setSubmitting] = useState(false) const { toast } = useToast() @@ -128,21 +129,40 @@ const RsvpStatusSwitcher = ({
{ - const rsvpResponse = JSON.parse(await rspvForTavern(formData)) - - if (rsvpResponse.success) { - toast({ - title: 'Saved', - description: - editMessages[Math.floor(Math.random() * editMessages.length)], + onSubmit={(e) => { + e.preventDefault() // Prevent default form submission + setSubmitting(true) + + rspvForTavern(new FormData(e.currentTarget)) + .then((res) => { + const rsvpResponse = JSON.parse(res) + + if (rsvpResponse.success) { + toast({ + title: 'Saved', + description: + editMessages[ + Math.floor(Math.random() * editMessages.length) + ], + }) + } else { + toast({ + title: 'Error', + description: `Failed to save your changes:\n${rsvpResponse.error}`, + }) + } + setSubmitting(false) + setEditedFlag(false) }) - } else { - toast({ - title: 'Error', - description: `Failed to save your changes:\n${rsvpResponse.error}`, + .catch((error) => { + console.error('Submission error:', error) + toast({ + title: 'Error', + description: 'An unexpected error occurred', + }) + setSubmitting(false) + setEditedFlag(false) }) - } }} className="flex flex-col justify-items-stretch gap-2" > @@ -263,8 +283,10 @@ const RsvpStatusSwitcher = ({

You have unsaved changes!

) : null} -