diff --git a/app/api/abstract-api.tsx b/app/api/abstract-api.tsx index a6751d2..e0b3f8b 100644 --- a/app/api/abstract-api.tsx +++ b/app/api/abstract-api.tsx @@ -10,6 +10,8 @@ export interface Api { create(serializable: Serializable, object: T, callback: (object: T) => void): void; update(serializable: Serializable, object: T, callback: () => void): void; destroy(serializable: Serializable, object: T, callback: () => void): void; + + post(serializable: Serializable, path: string, callback: () => void): void; } export interface Serializable { @@ -98,4 +100,14 @@ export class AbstractApi implements Api { }).then(callback) .catch((error) => console.error(error)); } + + post(serializable: Serializable, path: string, callback: () => void): void { + fetch(`/api/${getSlug()}/${serializable.apiPath()}/${path}`, { + method: 'POST', + headers: { + 'X-CSRF-TOKEN': getCsrfToken(), + } + }).then(callback) + .catch((error) => console.error(error)); + } } diff --git a/app/ui/invitations/board.tsx b/app/ui/invitations/board.tsx index dbe6c1c..4cc7cc4 100644 --- a/app/ui/invitations/board.tsx +++ b/app/ui/invitations/board.tsx @@ -11,6 +11,7 @@ import { LinkIcon, TrashIcon } from "@heroicons/react/24/outline"; import { useEffect, useRef } from "react"; import { useState } from "react"; import { classNames } from "../components/button"; +import { Toast } from "primereact/toast"; function InvitationCard({ invitation, allGuests, onGuestAdded, onDestroy }: { invitation: Invitation, @@ -117,6 +118,7 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati guests: Array, invitations: Array }) { + const toast = useRef(null); const api = new AbstractApi(); const serializer = new InvitationSerializer(); @@ -146,14 +148,19 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati } function handleDownloadQrCodes() { - api.getAllPdf(serializer, () => { - console.log("QR codes downloaded"); + api.post(serializer, 'email', () => { + toast.current?.show({ + severity: 'success', + summary: 'Email scheduled', + detail: 'A document with the QR codes will be sent to the organizer\'s email.' }); + }) } return (
{/* Left Column: Guests */} +

{unassignedGuests.length} guests without invitation

@@ -180,7 +187,7 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati onClick={handleDownloadQrCodes} className={classNames('primary')} > - Download QR codes + Send QR codes via email