Add a feature to handle invitations #261
@ -17,7 +17,7 @@ export class InvitationSerializer {
|
||||
}
|
||||
|
||||
toJson(invitation: Invitation): string {
|
||||
return JSON.stringify({ invitation: { guests: invitation.guests.map(guest => ({ id: guest.id })) } });
|
||||
return JSON.stringify({ invitation: { guest_ids: invitation.guests.map(guest => guest.id) } });
|
||||
}
|
||||
|
||||
apiPath(): string {
|
||||
|
@ -13,18 +13,24 @@ function InvitationCard({ invitation, allGuests, onGuestAdded }: { invitation: I
|
||||
|
||||
const ref = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const api = new AbstractApi<Invitation>();
|
||||
const serializer = new InvitationSerializer();
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
return dropTargetForElements({
|
||||
element: ref.current,
|
||||
onDrop: (data) => {
|
||||
console.log('Dropped guest ID:', data.source.element.dataset.guestId);
|
||||
const guestId = data.source.element.dataset.guestId;
|
||||
if (guestId) {
|
||||
const guestToAdd = allGuests.find((guest) => guest.id === guestId);
|
||||
if (guestToAdd) {
|
||||
setGuests((prevGuests) => [...prevGuests, guestToAdd]);
|
||||
invitation.guests.push(guestToAdd);
|
||||
|
||||
api.update(serializer, invitation, () => {
|
||||
onGuestAdded(guestToAdd);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -61,7 +67,6 @@ function GuestCard(guest: Guest) {
|
||||
if (ref.current) {
|
||||
return draggable({
|
||||
element: ref.current,
|
||||
onDragStart: () => console.log('Something started dragging in me!')
|
||||
});
|
||||
}
|
||||
}, [guest.id]);
|
||||
@ -104,7 +109,6 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati
|
||||
|
||||
function handleCreateInvitation() {
|
||||
api.create(serializer, new Invitation(), (createdInvitation) => {
|
||||
console.log(`Invitation created successfully with ID: ${createdInvitation.id}`);
|
||||
setInvitations((prevInvitations) => [createdInvitation, ...prevInvitations]);
|
||||
});
|
||||
}
|
||||
@ -143,7 +147,6 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati
|
||||
invitation={invitation}
|
||||
allGuests={guests}
|
||||
onGuestAdded={(guestAdded: Guest) => {
|
||||
console.log(`Guest added: ${guestAdded.name}`);
|
||||
setUnassignedGuests((prevUnassignedGuests) => prevUnassignedGuests.filter(g => g.id !== guestAdded.id));
|
||||
}}
|
||||
/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user