diff --git a/app/api/abstract-api.tsx b/app/api/abstract-api.tsx index b49e763..a6751d2 100644 --- a/app/api/abstract-api.tsx +++ b/app/api/abstract-api.tsx @@ -3,6 +3,7 @@ import { Entity } from '@/app/lib/definitions'; import { getCsrfToken, getSlug } from '@/app/lib/utils'; + export interface Api { getAll(serializable: Serializable, callback: (objets: T[]) => void): void; get(serializable: Serializable, id: string, callback: (object: T) => void): void; @@ -30,6 +31,18 @@ export class AbstractApi implements Api { }); } + getAllPdf(serializable: Serializable, callback: () => void): void { + fetch(`/api/${getSlug()}/${serializable.apiPath()}`, { + headers: { + 'Accept': 'application/pdf', + } + }).then(res => res.blob()) + .then(blob => { + var file = window.URL.createObjectURL(blob); + window.location.assign(file); + }); + } + get(serializable: Serializable, id: (string | undefined), callback: (object: T) => void): void { const endpoint = id ? `/api/${getSlug()}/${serializable.apiPath()}/${id}` : `/api/${getSlug()}/${serializable.apiPath()}`; fetch(endpoint) diff --git a/app/ui/components/button.tsx b/app/ui/components/button.tsx index 2ecfabb..4d92bd1 100644 --- a/app/ui/components/button.tsx +++ b/app/ui/components/button.tsx @@ -5,7 +5,7 @@ import clsx from "clsx"; type ButtonColor = 'primary' | 'blue' | 'green' | 'red' | 'yellow' | 'gray'; export function classNames(type: ButtonColor) { - return (clsx("text-white py-1 px-2 mx-1 rounded disabled:opacity-50 disabled:cursor-not-allowed", { + return (clsx("text-white py-1 px-2 m-2 rounded disabled:opacity-50 disabled:cursor-not-allowed", { 'bg-blue-400 hover:bg-blue-600': type === 'primary' || type === 'blue', 'bg-green-500 hover:bg-green-600': type === 'green', 'bg-red-500 hover:bg-red-600': type === 'red', diff --git a/app/ui/invitations/board.tsx b/app/ui/invitations/board.tsx index 7969cff..dbe6c1c 100644 --- a/app/ui/invitations/board.tsx +++ b/app/ui/invitations/board.tsx @@ -10,6 +10,7 @@ import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-d import { LinkIcon, TrashIcon } from "@heroicons/react/24/outline"; import { useEffect, useRef } from "react"; import { useState } from "react"; +import { classNames } from "../components/button"; function InvitationCard({ invitation, allGuests, onGuestAdded, onDestroy }: { invitation: Invitation, @@ -144,6 +145,12 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati }); } + function handleDownloadQrCodes() { + api.getAllPdf(serializer, () => { + console.log("QR codes downloaded"); + }); + } + return (
{/* Left Column: Guests */} @@ -164,11 +171,18 @@ export default function InvitationsBoard({ guests, invitations: originalInvitati + +