Modify the behavior of the download invitations button to send them via email

This commit is contained in:
Manuel Bustillo 2025-07-08 19:25:49 +02:00
parent b4ec903ce0
commit 8f5c038f9c
2 changed files with 16 additions and 4 deletions

View File

@ -10,6 +10,8 @@ export interface Api<T extends Entity> {
create(serializable: Serializable<T>, object: T, callback: (object: T) => void): void;
update(serializable: Serializable<T>, object: T, callback: () => void): void;
destroy(serializable: Serializable<T>, object: T, callback: () => void): void;
post(serializable: Serializable<T>, path: string, callback: () => void): void;
}
export interface Serializable<T> {
@ -98,4 +100,14 @@ export class AbstractApi<T extends Entity> implements Api<T> {
}).then(callback)
.catch((error) => console.error(error));
}
post(serializable: Serializable<T>, 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));
}
}

View File

@ -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
</button>