From 8f5c038f9cc495cb3506193055df4eff0cfa84b4 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Tue, 8 Jul 2025 19:25:49 +0200 Subject: [PATCH] Modify the behavior of the download invitations button to send them via email --- app/api/abstract-api.tsx | 12 ++++++++++++ app/ui/invitations/board.tsx | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) 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..1206ff1 100644 --- a/app/ui/invitations/board.tsx +++ b/app/ui/invitations/board.tsx @@ -146,9 +146,9 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati } function handleDownloadQrCodes() { - api.getAllPdf(serializer, () => { - console.log("QR codes downloaded"); - }); + api.post(serializer, 'email', () => { + console.log("Email scheduled to be sent with QR codes."); + }) } return ( @@ -180,7 +180,7 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati onClick={handleDownloadQrCodes} className={classNames('primary')} > - Download QR codes + Send QR codes via email