From d6456199cf7b96add3a025d540959cfab335d0f2 Mon Sep 17 00:00:00 2001 From: Max S Date: Fri, 13 Sep 2024 12:19:18 +0200 Subject: [PATCH] :sparkles: add toaster and fix count email reminder --- .../Api/LeCoffreApi/Notary/Folders/Folders.ts | 1 + .../DeleteAskedDocumentModal/index.tsx | 2 ++ .../DeleteSentDocumentModal/index.tsx | 2 ++ .../EmailReminder/ReminderModal/index.tsx | 9 ++++-- .../ClientView/EmailReminder/index.tsx | 32 +++++++++++-------- .../Layouts/Folder/SendDocuments/index.tsx | 3 +- src/front/Components/Layouts/Folder/index.tsx | 1 + 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts b/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts index b7aa1342..ef7ad713 100644 --- a/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts @@ -8,6 +8,7 @@ export interface IGetFoldersParams { select?: {}; where?: {}; include?: {}; + orderBy?: {}; }; } diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx index 87d2586a..e43a3e1d 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx @@ -1,5 +1,6 @@ import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; import Modal from "@Front/Components/DesignSystem/Modal"; +import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import React, { useCallback } from "react"; @@ -18,6 +19,7 @@ export default function DeleteAskedDocumentModal(props: IProps) { Documents.getInstance() .delete(documentUid) .then(() => onDeleteSuccess(documentUid)) + .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." })) .then(onClose) .catch((error) => console.warn(error)), [documentUid, onClose, onDeleteSuccess], diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx index 72fed16e..e3d6296e 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx @@ -1,5 +1,6 @@ import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary"; import Modal from "@Front/Components/DesignSystem/Modal"; +import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import React, { useCallback } from "react"; @@ -18,6 +19,7 @@ export default function DeleteSentDocumentModal(props: IProps) { DocumentsNotary.getInstance() .delete(documentUid) .then(() => onDeleteSuccess(documentUid)) + .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." })) .then(onClose) .catch((error) => console.warn(error)), [documentUid, onClose, onDeleteSuccess], diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/ReminderModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/ReminderModal/index.tsx index 5c540d68..13629989 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/ReminderModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/ReminderModal/index.tsx @@ -8,6 +8,7 @@ import React, { useCallback, useMemo, useState } from "react"; import classes from "./classes.module.scss"; import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers"; +import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; type IProps = { isOpen: boolean; @@ -22,9 +23,11 @@ export default function ReminderModal(props: IProps) { const [isAllSelected, setIsAllSelected] = useState(false); const onRemind = useCallback(() => { - Customers.getInstance().sendReminder(customer.uid!, selectedOptions.map((option) => option.value) as string[]); - onRemindSuccess(); - onClose?.(); + Customers.getInstance() + .sendReminder(customer.uid!, selectedOptions.map((option) => option.value) as string[]) + .then(onRemindSuccess) + .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "La relance a été envoyée avec succès." })) + .then(onClose); }, [customer.uid, onClose, onRemindSuccess, selectedOptions]); const documentsOptions: IOption[] = useMemo( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/index.tsx index ca9155d2..54a5069b 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/index.tsx @@ -9,7 +9,7 @@ import Customer from "le-coffre-resources/dist/Customer"; import { DocumentReminder } from "le-coffre-resources/dist/Notary"; import Link from "next/link"; import { useRouter } from "next/router"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import classes from "./classes.module.scss"; import ReminderModal from "./ReminderModal"; @@ -26,22 +26,33 @@ export default function EmailReminder(props: IProps) { const { isOpen, open, close } = useOpenable(); const router = useRouter(); + let { folderUid } = router.query; + const fetchReminders = useCallback(async () => { + if (!customer.uid || !folderUid) return; DocumentReminders.getInstance() .get({ - where: { document: { depositor: { uid: customer.uid } } }, + where: { document: { depositor: { uid: customer.uid }, folder: { uid: folderUid } } }, include: { document: "true" }, orderBy: { reminder_date: "desc" }, }) .then((reminders) => setReminders(reminders)) .catch((e) => console.warn(e)); - }, [customer.uid]); + }, [customer.uid, folderUid]); useEffect(() => { fetchReminders(); }, [fetchReminders]); - let { folderUid } = router.query; + // count the number of reminders group by reminder_date rounded at seconde + const remindersLength = useMemo(() => { + const remindersGroupByDate = reminders?.reduce((acc, reminder) => { + const reminderDate = new Date(reminder.reminder_date!).setSeconds(0, 0); + acc[reminderDate] = acc[reminderDate] ? acc[reminderDate] + 1 : 1; + return acc; + }, {} as Record); + return Object.keys(remindersGroupByDate ?? {}).length; + }, [reminders]); return (
@@ -68,21 +79,14 @@ export default function EmailReminder(props: IProps) {
Dernière relance:{" "} - {reminders && reminders.length > 0 ? new Date(reminders[0]!.reminder_date!).toLocaleDateString() : "-"} + {reminders && remindersLength > 0 ? new Date(reminders[0]!.reminder_date!).toLocaleDateString() : "-"} - Nombre de relance: {reminders && reminders.length > 0 ? reminders.length : "0"} + Nombre de relance: {remindersLength}
- { - window.location.reload(); - }} - onClose={close} - customer={customer} - /> + ); } diff --git a/src/front/Components/Layouts/Folder/SendDocuments/index.tsx b/src/front/Components/Layouts/Folder/SendDocuments/index.tsx index 0449d17e..d9691b84 100644 --- a/src/front/Components/Layouts/Folder/SendDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/SendDocuments/index.tsx @@ -16,6 +16,7 @@ import { useRouter } from "next/router"; import React, { useCallback, useEffect, useMemo, useState } from "react"; import classes from "./classes.module.scss"; +import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; enum EClientSelection { ALL_CLIENTS = "all_clients", @@ -68,7 +69,7 @@ export default function SendDocuments() { .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid as string), ); setIsSending(false); - console.log("All files have been successfully sent."); + ToasterService.getInstance().success({ title: "Succès !", description: "Votre document a été envoyée avec succès." }); } catch (error) { setIsSending(false); console.error("Error while sending files: ", error); diff --git a/src/front/Components/Layouts/Folder/index.tsx b/src/front/Components/Layouts/Folder/index.tsx index c7e2dd5e..a3f4ca4b 100644 --- a/src/front/Components/Layouts/Folder/index.tsx +++ b/src/front/Components/Layouts/Folder/index.tsx @@ -27,6 +27,7 @@ export default function Folder() { .get({ q: { where: { status: EFolderStatus.LIVE }, + orderBy: { created_at: "desc" }, }, }) .then((folders) => {