From 68468f7793f805d635218d3357523ca166757075 Mon Sep 17 00:00:00 2001 From: Max S Date: Fri, 13 Sep 2024 13:26:15 +0200 Subject: [PATCH] :hammer: disabled email reminder button when validated documents --- .../EmailReminder/ReminderModal/index.tsx | 19 +++++++++++-------- .../ClientView/EmailReminder/index.tsx | 11 ++++++++--- .../FolderInformation/ClientView/index.tsx | 3 --- 3 files changed, 19 insertions(+), 14 deletions(-) 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 13629989..4da1f326 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 @@ -1,14 +1,15 @@ +import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import { IOption } from "@Front/Components/DesignSystem/Form/SelectFieldOld"; import Modal from "@Front/Components/DesignSystem/Modal"; import Separator, { ESeperatorColor } from "@Front/Components/DesignSystem/Separator"; +import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Customer from "le-coffre-resources/dist/Customer"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; 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; @@ -32,12 +33,14 @@ export default function ReminderModal(props: IProps) { const documentsOptions: IOption[] = useMemo( () => - customer.documents?.map((document) => { - return { - label: document.document_type?.name ?? "", - value: document.uid ?? "", - }; - }) ?? [], + customer.documents + ?.filter((document) => document.document_status !== EDocumentStatus.VALIDATED) + .map((document) => { + return { + label: document.document_type?.name ?? "", + value: document.uid ?? "", + }; + }) ?? [], [customer], ); 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 54a5069b..bedb14b4 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/EmailReminder/index.tsx @@ -13,15 +13,15 @@ import { useCallback, useEffect, useMemo, useState } from "react"; import classes from "./classes.module.scss"; import ReminderModal from "./ReminderModal"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; type IProps = { customer: Customer; - doesCustomerHaveDocument: boolean; isAnchored: boolean; }; export default function EmailReminder(props: IProps) { - const { customer, doesCustomerHaveDocument, isAnchored } = props; + const { customer, isAnchored } = props; const [reminders, setReminders] = useState(null); const { isOpen, open, close } = useOpenable(); const router = useRouter(); @@ -54,6 +54,11 @@ export default function EmailReminder(props: IProps) { return Object.keys(remindersGroupByDate ?? {}).length; }, [reminders]); + const doesCustomerHaveNotValidatedDocuments = useMemo( + () => customer.documents && customer.documents.some((document) => document.document_status !== EDocumentStatus.VALIDATED), + [customer.documents], + ); + return (
{!isAnchored && ( @@ -63,7 +68,7 @@ export default function EmailReminder(props: IProps) { variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED} fullwidth - disabled={doesCustomerHaveDocument}> + disabled={!doesCustomerHaveNotValidatedDocuments}> Relancer par mail )} diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx index 2608b960..22b7effa 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx @@ -56,8 +56,6 @@ export default function ClientView(props: IProps) { [customers], ); - const doesCustomerHaveDocument = useMemo(() => customer.documents && customer.documents.length > 0, [customer]); - const handleClientDelete = useCallback( (customerUid: string) => { if (!folder.uid) return; @@ -116,7 +114,6 @@ export default function ClientView(props: IProps) { )}