Update guest-context.tsx with new guest rsvp hybrid endpoint
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"use client";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useRSVPs } from "@/context/rsvp-context";
|
||||
import { useGuests } from "@/context/guest-context";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -23,8 +22,12 @@ interface RSVPProps {
|
||||
}
|
||||
|
||||
export const RSVP: React.FC<RSVPProps> = ({ eventId, onRSVPSuccess }) => {
|
||||
const { createRsvp } = useRSVPs();
|
||||
const { guests, isLoadingGuests } = useGuests();
|
||||
const {
|
||||
guests,
|
||||
isLoadingGuests,
|
||||
findGuestByInvitationCode,
|
||||
submitGuestRsvp,
|
||||
} = useGuests();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const [status, setStatus] = useState<RsvpStatus>(RsvpStatus.ATTENDING);
|
||||
@@ -46,19 +49,18 @@ export const RSVP: React.FC<RSVPProps> = ({ eventId, onRSVPSuccess }) => {
|
||||
}
|
||||
|
||||
// Find the guest with matching invitation code
|
||||
if (guests && guests.length > 0) {
|
||||
const matchingGuest = guests.find(
|
||||
(guest) => guest.invitation_code === invitationCode,
|
||||
);
|
||||
console.debug("matchingGuest", matchingGuest);
|
||||
if (guests) {
|
||||
const matchingGuest = findGuestByInvitationCode(invitationCode);
|
||||
|
||||
if (matchingGuest) {
|
||||
console.log("matchingGuest ", matchingGuest);
|
||||
setGuestId(matchingGuest.id);
|
||||
setError(null);
|
||||
} else {
|
||||
setError("Invalid invitation code. Please check your invitation link.");
|
||||
}
|
||||
}
|
||||
}, [searchParams, guests]);
|
||||
}, [searchParams, guests, findGuestByInvitationCode]);
|
||||
|
||||
const submitRsvp = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -74,7 +76,8 @@ export const RSVP: React.FC<RSVPProps> = ({ eventId, onRSVPSuccess }) => {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await createRsvp({
|
||||
// Use the combined endpoint to update both RSVP and Guest status
|
||||
await submitGuestRsvp(guestId, {
|
||||
event_id: eventId,
|
||||
guest_id: guestId,
|
||||
status,
|
||||
|
||||
Reference in New Issue
Block a user