From e78096c9562d74f8da59cdf4b5a0b76033073102 Mon Sep 17 00:00:00 2001 From: Maxime Roucher Date: Wed, 5 Jun 2024 17:15:53 +0200 Subject: [PATCH] feat: adding fully registered dialog --- src/app/page.tsx | 8 ++ src/components/custom/ParticipantField.tsx | 1 + src/components/custom/StatusDialog.tsx | 2 +- .../home/RegisteringCompleteDialog.tsx | 81 +++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/components/home/RegisteringCompleteDialog.tsx diff --git a/src/app/page.tsx b/src/app/page.tsx index 9c1d215b..f3c39263 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -18,6 +18,8 @@ import { getDaysLeft } from "../utils/dateFormat"; import { WarningDialog } from "../components/custom/WarningDialog"; import { toast } from "../components/ui/use-toast"; import { StatusDialog } from "../components/custom/StatusDialog"; +import { Button } from "../components/ui/button"; +import { RegisteringCompleteDialog } from "../components/home/RegisteringCompleteDialog"; const Home = () => { const { isTokenQueried, token } = useAuth(); @@ -99,6 +101,12 @@ const Home = () => { }} /> )} + {team?.validation_progress === 100 && ( + + )} {isFetched && me === undefined && isOpened && user && ( <> ({ toast({ title: "Erreur", description: "Impossible de télécharger le fichier", + variant: "destructive", }); setIsFileLoading(false); return; diff --git a/src/components/custom/StatusDialog.tsx b/src/components/custom/StatusDialog.tsx index 596bbb88..e60e3f94 100644 --- a/src/components/custom/StatusDialog.tsx +++ b/src/components/custom/StatusDialog.tsx @@ -12,7 +12,7 @@ interface StatusDialogProps { isOpened: boolean; setIsOpened: (value: boolean) => void; title: string; - description: string; + description: string | JSX.Element; width?: string; callback: () => void; status?: keyof typeof DialogStatus; diff --git a/src/components/home/RegisteringCompleteDialog.tsx b/src/components/home/RegisteringCompleteDialog.tsx new file mode 100644 index 00000000..ed98d050 --- /dev/null +++ b/src/components/home/RegisteringCompleteDialog.tsx @@ -0,0 +1,81 @@ +import { useDocument } from "@/src/hooks/useDocument"; +import { useInformation } from "@/src/hooks/useInformation"; +import { useState } from "react"; +import { StatusDialog } from "../custom/StatusDialog"; +import { toast } from "../ui/use-toast"; +import { useRouter } from "next/navigation"; +import { LoadingButton } from "../custom/LoadingButton"; + +interface RegisteringCompleteDialogProps { + isOpened: boolean; + setIsOpened: (value: boolean) => void; +} + +export const RegisteringCompleteDialog = ({ + isOpened, + setIsOpened, +}: RegisteringCompleteDialogProps) => { + const [isFileLoading, setIsFileLoading] = useState(false); + const { information } = useInformation(); + const { refetch, setDocumentId } = useDocument(); + const router = useRouter(); + + function downloadRaidInformation(documentId: string) { + setIsFileLoading(true); + setDocumentId(documentId); + refetch().then((response) => { + const data = response.data; + if (!data) { + toast({ + title: "Erreur", + description: "Impossible de télécharger le fichier", + variant: "destructive" + }); + setIsFileLoading(false); + return; + } + const extension = data.type.split("/")[1]; + const name = `Réglement_du_raid.${extension}`; + const url = window.URL.createObjectURL(new Blob([data])); + const link = document.createElement("a"); + link.href = url; + link.setAttribute("download", name); + document.body.appendChild(link); + setIsFileLoading(false); + link.click(); + }); + } + return ( + information && ( + +
Votre inscription est complète.
+
+ Vous trouverez toutes les informations nécessaires dans le + document à télécharger ci-dessous. +
+
Bonne préparation et à très bientôt !
+ + downloadRaidInformation(information.raid_information_id!) + } + isLoading={isFileLoading} + label="Télécharger le document" + /> + + } + status="SUCCESS" + callback={() => { + setIsOpened(false); + router.replace("/"); + }} + /> + ) + ); +};