From dfba3474d55e8a6cb8004753f3f72cde244fc944 Mon Sep 17 00:00:00 2001 From: Max S Date: Mon, 9 Sep 2024 16:45:02 +0200 Subject: [PATCH] :sparkles: filtrer par customer dans l'historique des relances --- .../DesignSystem/Dropdown/index.tsx | 5 +- .../classes.module.scss | 4 ++ .../Folder/DocumentsReminderHistory/index.tsx | 63 +++++++++++++++++-- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/front/Components/DesignSystem/Dropdown/index.tsx b/src/front/Components/DesignSystem/Dropdown/index.tsx index b88dae07..b45d2070 100644 --- a/src/front/Components/DesignSystem/Dropdown/index.tsx +++ b/src/front/Components/DesignSystem/Dropdown/index.tsx @@ -15,10 +15,11 @@ type IProps = { disabled?: boolean; onSelectionChange?: (option: IOption) => void; selectedOption?: IOption | null; + className?: string; }; export default function Dropdown(props: IProps) { - const { options, placeholder, disabled, onSelectionChange, selectedOption: selectedOptionProps, label } = props; + const { options, placeholder, disabled, onSelectionChange, selectedOption: selectedOptionProps, label, className } = props; const [selectedOption, setSelectedOption] = useState(selectedOptionProps ?? null); const openable = useOpenable({ defaultOpen: false }); @@ -40,7 +41,7 @@ export default function Dropdown(props: IProps) { openable={openable} onSelect={handleOnSelect} selectedOptions={selectedOption ? [selectedOption] : []}> -
+
{label && ( {label} diff --git a/src/front/Components/Layouts/Folder/DocumentsReminderHistory/classes.module.scss b/src/front/Components/Layouts/Folder/DocumentsReminderHistory/classes.module.scss index 62f8849f..9b949a1f 100644 --- a/src/front/Components/Layouts/Folder/DocumentsReminderHistory/classes.module.scss +++ b/src/front/Components/Layouts/Folder/DocumentsReminderHistory/classes.module.scss @@ -13,6 +13,10 @@ width: 100%; } + .customer-filter{ + width: 472px; + } + @media screen and (max-width: $screen-m) { padding: var(--spacing-3); } diff --git a/src/front/Components/Layouts/Folder/DocumentsReminderHistory/index.tsx b/src/front/Components/Layouts/Folder/DocumentsReminderHistory/index.tsx index f9a4130f..cc642b1d 100644 --- a/src/front/Components/Layouts/Folder/DocumentsReminderHistory/index.tsx +++ b/src/front/Components/Layouts/Folder/DocumentsReminderHistory/index.tsx @@ -1,17 +1,21 @@ +import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers"; import DocumentReminders from "@Front/Api/LeCoffreApi/Notary/DocumentReminders/DocumentReminders"; +import Dropdown from "@Front/Components/DesignSystem/Dropdown"; +import { IOption } from "@Front/Components/DesignSystem/Dropdown/DropdownMenu/DropdownOption"; import Table from "@Front/Components/DesignSystem/Table"; import { IHead, IRowProps } from "@Front/Components/DesignSystem/Table/MuiTable"; +import Tag, { ETagColor } from "@Front/Components/DesignSystem/Tag"; import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate"; import Module from "@Front/Config/Module"; +import Customer from "le-coffre-resources/dist/Customer"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import { DocumentReminder } from "le-coffre-resources/dist/Notary"; import { useRouter } from "next/router"; -import React, { useCallback, useEffect, useState } from "react"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; import classes from "./classes.module.scss"; -import Tag, { ETagColor } from "@Front/Components/DesignSystem/Tag"; -import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; type IProps = {}; @@ -36,12 +40,15 @@ const header: readonly IHead[] = [ export default function DocumentsReminderHistory(props: IProps) { const [reminders, setReminders] = useState(null); + const [customers, setCustomers] = useState(null); + const [customerOption, setCustomerOption] = useState(null); const router = useRouter(); let { folderUid } = router.query; - const fetchReminders = useCallback(async () => { + const fetchReminders = useCallback(() => { DocumentReminders.getInstance() .get({ + ...(customerOption && customerOption.id !== "tous" && { where: { document: { depositor: { uid: customerOption.id } } } }), include: { document: { include: { @@ -58,11 +65,49 @@ export default function DocumentsReminderHistory(props: IProps) { }) .then((reminders) => setReminders(reminders)) .catch((e) => console.warn(e)); - }, []); + }, [customerOption]); + + const fetchCustomers = useCallback(async () => { + if (!folderUid) return; + Customers.getInstance() + .get({ + where: { + office_folders: { + some: { + uid: folderUid as string, + }, + }, + }, + }) + .then(setCustomers) + .catch(console.warn); + }, [folderUid]); + + const customersOptions: IOption[] = useMemo(() => { + let options = [ + { + id: "tous", + label: "Tous", + }, + ]; + + customers?.forEach((customer) => { + options.push({ + id: customer.uid ?? "", + label: `${customer.contact?.first_name} ${customer.contact?.last_name}`, + }); + }); + return options; + }, [customers]); useEffect(() => { fetchReminders(); - }, [fetchReminders]); + fetchCustomers(); + }, [customerOption, customersOptions, fetchCustomers, fetchReminders]); + + const onSelectionChange = useCallback((option: IOption | null) => { + setCustomerOption(option ?? null); + }, []); return ( @@ -76,6 +121,12 @@ export default function DocumentsReminderHistory(props: IProps) { Historique des relances de documents +