add toaster and fix count email reminder

This commit is contained in:
Max S 2024-09-13 12:19:18 +02:00
parent b6875ff609
commit d6456199cf
7 changed files with 32 additions and 18 deletions

View File

@ -8,6 +8,7 @@ export interface IGetFoldersParams {
select?: {}; select?: {};
where?: {}; where?: {};
include?: {}; include?: {};
orderBy?: {};
}; };
} }

View File

@ -1,5 +1,6 @@
import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents";
import Modal from "@Front/Components/DesignSystem/Modal"; import Modal from "@Front/Components/DesignSystem/Modal";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography";
import React, { useCallback } from "react"; import React, { useCallback } from "react";
@ -18,6 +19,7 @@ export default function DeleteAskedDocumentModal(props: IProps) {
Documents.getInstance() Documents.getInstance()
.delete(documentUid) .delete(documentUid)
.then(() => onDeleteSuccess(documentUid)) .then(() => onDeleteSuccess(documentUid))
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." }))
.then(onClose) .then(onClose)
.catch((error) => console.warn(error)), .catch((error) => console.warn(error)),
[documentUid, onClose, onDeleteSuccess], [documentUid, onClose, onDeleteSuccess],

View File

@ -1,5 +1,6 @@
import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary"; import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary";
import Modal from "@Front/Components/DesignSystem/Modal"; import Modal from "@Front/Components/DesignSystem/Modal";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography";
import React, { useCallback } from "react"; import React, { useCallback } from "react";
@ -18,6 +19,7 @@ export default function DeleteSentDocumentModal(props: IProps) {
DocumentsNotary.getInstance() DocumentsNotary.getInstance()
.delete(documentUid) .delete(documentUid)
.then(() => onDeleteSuccess(documentUid)) .then(() => onDeleteSuccess(documentUid))
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." }))
.then(onClose) .then(onClose)
.catch((error) => console.warn(error)), .catch((error) => console.warn(error)),
[documentUid, onClose, onDeleteSuccess], [documentUid, onClose, onDeleteSuccess],

View File

@ -8,6 +8,7 @@ import React, { useCallback, useMemo, useState } from "react";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers"; import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
type IProps = { type IProps = {
isOpen: boolean; isOpen: boolean;
@ -22,9 +23,11 @@ export default function ReminderModal(props: IProps) {
const [isAllSelected, setIsAllSelected] = useState(false); const [isAllSelected, setIsAllSelected] = useState(false);
const onRemind = useCallback(() => { const onRemind = useCallback(() => {
Customers.getInstance().sendReminder(customer.uid!, selectedOptions.map((option) => option.value) as string[]); Customers.getInstance()
onRemindSuccess(); .sendReminder(customer.uid!, selectedOptions.map((option) => option.value) as string[])
onClose?.(); .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]); }, [customer.uid, onClose, onRemindSuccess, selectedOptions]);
const documentsOptions: IOption[] = useMemo( const documentsOptions: IOption[] = useMemo(

View File

@ -9,7 +9,7 @@ import Customer from "le-coffre-resources/dist/Customer";
import { DocumentReminder } from "le-coffre-resources/dist/Notary"; import { DocumentReminder } from "le-coffre-resources/dist/Notary";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; 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 classes from "./classes.module.scss";
import ReminderModal from "./ReminderModal"; import ReminderModal from "./ReminderModal";
@ -26,22 +26,33 @@ export default function EmailReminder(props: IProps) {
const { isOpen, open, close } = useOpenable(); const { isOpen, open, close } = useOpenable();
const router = useRouter(); const router = useRouter();
let { folderUid } = router.query;
const fetchReminders = useCallback(async () => { const fetchReminders = useCallback(async () => {
if (!customer.uid || !folderUid) return;
DocumentReminders.getInstance() DocumentReminders.getInstance()
.get({ .get({
where: { document: { depositor: { uid: customer.uid } } }, where: { document: { depositor: { uid: customer.uid }, folder: { uid: folderUid } } },
include: { document: "true" }, include: { document: "true" },
orderBy: { reminder_date: "desc" }, orderBy: { reminder_date: "desc" },
}) })
.then((reminders) => setReminders(reminders)) .then((reminders) => setReminders(reminders))
.catch((e) => console.warn(e)); .catch((e) => console.warn(e));
}, [customer.uid]); }, [customer.uid, folderUid]);
useEffect(() => { useEffect(() => {
fetchReminders(); fetchReminders();
}, [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<number, number>);
return Object.keys(remindersGroupByDate ?? {}).length;
}, [reminders]);
return ( return (
<div className={classes["root"]}> <div className={classes["root"]}>
@ -68,21 +79,14 @@ export default function EmailReminder(props: IProps) {
<div className={classes["info"]}> <div className={classes["info"]}>
<Typography typo={ETypo.TEXT_XS_REGULAR} color={ETypoColor.TEXT_SECONDARY}> <Typography typo={ETypo.TEXT_XS_REGULAR} color={ETypoColor.TEXT_SECONDARY}>
Dernière relance:{" "} Dernière relance:{" "}
{reminders && reminders.length > 0 ? new Date(reminders[0]!.reminder_date!).toLocaleDateString() : "-"} {reminders && remindersLength > 0 ? new Date(reminders[0]!.reminder_date!).toLocaleDateString() : "-"}
</Typography> </Typography>
<Typography typo={ETypo.TEXT_XS_REGULAR} color={ETypoColor.TEXT_SECONDARY}> <Typography typo={ETypo.TEXT_XS_REGULAR} color={ETypoColor.TEXT_SECONDARY}>
Nombre de relance: {reminders && reminders.length > 0 ? reminders.length : "0"} Nombre de relance: {remindersLength}
</Typography> </Typography>
</div> </div>
</div> </div>
<ReminderModal <ReminderModal isOpen={isOpen} onRemindSuccess={fetchReminders} onClose={close} customer={customer} />
isOpen={isOpen}
onRemindSuccess={() => {
window.location.reload();
}}
onClose={close}
customer={customer}
/>
</div> </div>
); );
} }

View File

@ -16,6 +16,7 @@ import { useRouter } from "next/router";
import React, { useCallback, useEffect, useMemo, useState } from "react"; import React, { useCallback, useEffect, useMemo, useState } from "react";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
enum EClientSelection { enum EClientSelection {
ALL_CLIENTS = "all_clients", ALL_CLIENTS = "all_clients",
@ -68,7 +69,7 @@ export default function SendDocuments() {
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid as string), .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid as string),
); );
setIsSending(false); 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) { } catch (error) {
setIsSending(false); setIsSending(false);
console.error("Error while sending files: ", error); console.error("Error while sending files: ", error);

View File

@ -27,6 +27,7 @@ export default function Folder() {
.get({ .get({
q: { q: {
where: { status: EFolderStatus.LIVE }, where: { status: EFolderStatus.LIVE },
orderBy: { created_at: "desc" },
}, },
}) })
.then((folders) => { .then((folders) => {