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