diff --git a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx index c6398dfa..fe6b1c22 100644 --- a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx @@ -16,9 +16,10 @@ import Button, { EButtonstyletype, EButtonVariant } from "../Button"; import Confirm from "../OldModal/Confirm"; import Alert from "../OldModal/Alert"; -import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; +import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; type IProps = { onChange?: (files: File[]) => void; @@ -238,14 +239,28 @@ export default class DepositOtherDocument extends React.Component((resolve: (customer: any) => void) => { + CustomerService.getCustomerByUid(this.props.customer_uid).then((process: any) => { + if (process) { + const customer: any = process.processData; + resolve(customer); + } + }); + }); + for (let i = 0; i < filesArray.length; i++) { const file = filesArray[i]!.file; await new Promise((resolve: () => void) => { const reader = new FileReader(); reader.onload = (event) => { if (event.target?.result) { - const arrayBuffer = event.target.result as ArrayBuffer; - const uint8Array = new Uint8Array(arrayBuffer); + const date: Date = new Date(); + const strDate: string = `${date.getDate().toString().padStart(2, '0')}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getFullYear()}`; + + const fileName: string = `${customer.contact.last_name}-${strDate}-APCL.${file.name.split('.').pop()}`.toUpperCase(); + + const arrayBuffer: ArrayBuffer = event.target.result as ArrayBuffer; + const uint8Array: Uint8Array = new Uint8Array(arrayBuffer); const fileBlob: any = { type: file.type, @@ -254,7 +269,7 @@ export default class DepositOtherDocument extends React.Component void; + isCustomer?: boolean; }; type IState = {}; @@ -19,29 +20,31 @@ export default class ProfileModal extends React.Component { <>
- + />} - + />} - - + />} + +
); diff --git a/src/front/Components/DesignSystem/Header/Profile/index.tsx b/src/front/Components/DesignSystem/Header/Profile/index.tsx index e2d66719..4298665f 100644 --- a/src/front/Components/DesignSystem/Header/Profile/index.tsx +++ b/src/front/Components/DesignSystem/Header/Profile/index.tsx @@ -9,7 +9,7 @@ import ProfileModal from "./ProfileModal"; const headerBreakpoint = 1023; -export default function Profile() { +export default function Profile(props: { isCustomer?: boolean }) { const { isOpen, toggle, close } = useOpenable(); useEffect(() => { @@ -27,7 +27,7 @@ export default function Profile() { return (
} onClick={toggle} /> - +
); } diff --git a/src/front/Components/DesignSystem/Header/index.tsx b/src/front/Components/DesignSystem/Header/index.tsx index e42fd796..aea3aa66 100644 --- a/src/front/Components/DesignSystem/Header/index.tsx +++ b/src/front/Components/DesignSystem/Header/index.tsx @@ -20,12 +20,13 @@ import Profile from "./Profile"; type IProps = { isUserConnected: boolean; + isCustomer?: boolean; }; const headerHeight = 75; export default function Header(props: IProps) { - const { isUserConnected } = props; + const { isUserConnected, isCustomer } = props; const router = useRouter(); const { pathname } = router; @@ -62,7 +63,7 @@ export default function Header(props: IProps) { logo
- {isUserConnected && ( + {isUserConnected && !isCustomer && ( <>
@@ -83,6 +84,11 @@ export default function Header(props: IProps) {
)} + {isCustomer && ( +
+ +
+ )} {isOnCustomerLoginPage && ciel-nature} {/* {cancelAt && ( diff --git a/src/front/Components/DesignSystem/LogOutButton/index.tsx b/src/front/Components/DesignSystem/LogOutButton/index.tsx index 6e1b1e13..24f6a88a 100644 --- a/src/front/Components/DesignSystem/LogOutButton/index.tsx +++ b/src/front/Components/DesignSystem/LogOutButton/index.tsx @@ -6,14 +6,19 @@ import React, { useCallback } from "react"; import MenuItem from "../Menu/MenuItem"; -export default function LogOut() { +export default function LogOut(props: { isCustomer?: boolean }) { const router = useRouter(); const variables = FrontendVariables.getInstance(); const disconnect = useCallback(() => { - UserStore.instance - .disconnect() - .then(() => router.push(`https://qual-connexion.idnot.fr/user/auth/logout?sourceURL=${variables.FRONT_APP_HOST}`)); + if (!props.isCustomer) { + UserStore.instance + .disconnect() + .then(() => router.push(`https://qual-connexion.idnot.fr/user/auth/logout?sourceURL=${variables.FRONT_APP_HOST}`)); + } else { + sessionStorage.setItem("customerIsConnected", "false"); + router.push("/"); + } }, [router, variables.FRONT_APP_HOST]); return , onClick: disconnect }} />; diff --git a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx index d539fb3b..b56f9238 100644 --- a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx @@ -9,7 +9,9 @@ import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDas import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; -type IProps = IPropsDashboardWithList & {}; +type IProps = IPropsDashboardWithList & { + isReady: boolean; +}; export default function DefaultCustomerDashboard(props: IProps) { const router = useRouter(); @@ -46,13 +48,15 @@ export default function DefaultCustomerDashboard(props: IProps) { .then((folders) => setFolders(folders)); */ - FolderService.getFolders().then((processes: any[]) => { - if (processes.length > 0) { - const folders: any[] = processes.map((process: any) => process.processData); - setFolders(folders); - } - }); - }, []); + if (props.isReady) { + FolderService.getFolders().then((processes: any[]) => { + if (processes.length > 0) { + const folders: any[] = processes.map((process: any) => process.processData); + setFolders(folders); + } + }); + } + }, [props.isReady]); const onSelectedBlock = (block: IBlock) => { const folder = folders.find((folder) => folder.uid === block.id); @@ -65,7 +69,7 @@ export default function DefaultCustomerDashboard(props: IProps) { .replace("[profileUid]", profileUid as string ?? ""), ); }; - return ; + return ; function getBlocks(folders: OfficeFolder[]): IBlock[] { return folders.map((folder) => { diff --git a/src/front/Components/LayoutTemplates/DefaultDashboardWithList/index.tsx b/src/front/Components/LayoutTemplates/DefaultDashboardWithList/index.tsx index 5261e700..5fc1d600 100644 --- a/src/front/Components/LayoutTemplates/DefaultDashboardWithList/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultDashboardWithList/index.tsx @@ -15,6 +15,7 @@ export type IPropsDashboardWithList = { mobileBackText?: string; headerConnected?: boolean; noPadding?: boolean; + isCustomer?: boolean; }; type IProps = IPropsDashboardWithList & ISearchBlockListProps; @@ -29,11 +30,12 @@ export default function DefaultDashboardWithList(props: IProps) { headerConnected = true, bottomButton, noPadding = false, + isCustomer = false, } = props; return (
-
+
diff --git a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx index 041af337..d472709f 100644 --- a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx @@ -14,11 +14,12 @@ import WatermarkService from "@Front/Services/WatermarkService"; type IProps = { document: any; + customer: any; onChange: () => void; }; export default function DepositDocumentComponent(props: IProps) { - const { document, onChange } = props; + const { document, customer,onChange } = props; const [isModalOpen, setIsModalOpen] = useState(false); const [refused_reason, setRefusedReason] = useState(null); @@ -42,8 +43,13 @@ export default function DepositDocumentComponent(props: IProps) { const reader = new FileReader(); reader.onload = (event) => { if (event.target?.result) { - const arrayBuffer = event.target.result as ArrayBuffer; - const uint8Array = new Uint8Array(arrayBuffer); + const date: Date = new Date(); + const strDate: string = `${date.getDate().toString().padStart(2, '0')}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getFullYear()}`; + + const fileName: string = `aplc-${document.document_type.name}-${customer.contact.last_name}-${strDate}.${file.name.split('.').pop()}`; + + const arrayBuffer: ArrayBuffer = event.target.result as ArrayBuffer; + const uint8Array: Uint8Array = new Uint8Array(arrayBuffer); const fileBlob: FileBlob = { type: watermarkedFile.type, @@ -52,7 +58,7 @@ export default function DepositDocumentComponent(props: IProps) { const fileData: FileData = { file_blob: fileBlob, - file_name: watermarkedFile.name + file_name: fileName }; const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index c02202dd..5c94d6f8 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -46,14 +46,16 @@ export default function ClientDashboard(props: IProps) { const [documentsNotary, setDocumentsNotary] = useState([]); const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState(false); + const [isReady, setIsReady] = useState(false); const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); - const [isSmsModalOpen, setIsSmsModalOpen] = useState(false); + const [isSmsModalOpen, setIsSmsModalOpen] = useState(true); const [smsCode, setSmsCode] = useState(""); const [smsError, setSmsError] = useState(""); const verifySmsCode = useCallback(() => { if (smsCode === "1234") { setIsSmsModalOpen(false); + setIsAuthModalOpen(true); } else { setSmsError("Code incorrect. Le code valide est 1234."); } @@ -97,7 +99,6 @@ export default function ClientDashboard(props: IProps) { setCustomer(customer); setFolder(folder); - setIsAuthModalOpen(true); LoaderService.getInstance().hide(); return { folder, customer }; @@ -171,9 +172,11 @@ export default function ClientDashboard(props: IProps) { [folderUid], ); + /* useEffect(() => { fetchFolderAndCustomer().then(({ customer }) => fetchDocuments(customer.uid)); }, [fetchDocuments, fetchFolderAndCustomer]); + */ useEffect(() => { const customerUid = customer?.uid; @@ -235,8 +238,8 @@ export default function ClientDashboard(props: IProps) { }, [customer, folderUid, isAddDocumentModalVisible, onCloseModalAddDocument, folder]); return ( - -
+ + {isReady && (
@@ -315,6 +318,7 @@ export default function ClientDashboard(props: IProps) { fetchDocuments(customer?.uid)} /> ))} @@ -332,58 +336,61 @@ export default function ClientDashboard(props: IProps) { Ajouter d'autres documents {isAddDocumentModalVisible && renderBox()} +
)} - {isAuthModalOpen && { - setIsAuthModalOpen(false); - setIsSmsModalOpen(true); - }} - />} + {isAuthModalOpen && { + setIsReady(true); + setIsAuthModalOpen(false); + fetchFolderAndCustomer().then(({ customer }) => fetchDocuments(customer.uid)); - {isSmsModalOpen && ( - setIsSmsModalOpen(false)} - title="Vérification SMS" - > -
- - Veuillez saisir le code à 4 chiffres que vous avez reçu par SMS + sessionStorage.setItem("customerIsConnected", "true"); + }} + />} + + {isSmsModalOpen && ( + setIsSmsModalOpen(false)} + title="Vérification SMS" + > +
+ + Veuillez saisir le code à 4 chiffres que vous avez reçu par SMS + + + { + const value = e.target.value; + // Only allow digits + if (value === "" || /^\d+$/.test(value)) { + setSmsCode(value); + setSmsError(""); + } + }} + /> + + {smsError && ( + + {smsError} + )} - { - const value = e.target.value; - // Only allow digits - if (value === "" || /^\d+$/.test(value)) { - setSmsCode(value); - setSmsError(""); - } - }} - /> - - {smsError && ( - - {smsError} - - )} - -
- -
+
+
- - )} -
+
+
+ )} ); } diff --git a/src/front/Components/Layouts/Folder/SendDocuments/index.tsx b/src/front/Components/Layouts/Folder/SendDocuments/index.tsx index 81f50e1c..dcc56311 100644 --- a/src/front/Components/Layouts/Folder/SendDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/SendDocuments/index.tsx @@ -22,6 +22,7 @@ import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; +import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; enum EClientSelection { ALL_CLIENTS = "all_clients", @@ -65,13 +66,27 @@ export default function SendDocuments() { LoaderService.getInstance().show(); for (const selectedClient of selectedClients) { + const customer: any = await new Promise((resolve: (customer: any) => void) => { + CustomerService.getCustomerByUid(selectedClient as string).then((process: any) => { + if (process) { + const customer: any = process.processData; + resolve(customer); + } + }); + }); + for (const file of files) { await new Promise((resolve: () => void) => { const reader = new FileReader(); reader.onload = (event) => { if (event.target?.result) { - const arrayBuffer = event.target.result as ArrayBuffer; - const uint8Array = new Uint8Array(arrayBuffer); + const date: Date = new Date(); + const strDate: string = `${date.getDate().toString().padStart(2, '0')}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getFullYear()}`; + + const fileName: string = `${customer.contact.last_name}-${strDate}-APCL.${file.name.split('.').pop()}`.toUpperCase(); + + const arrayBuffer: ArrayBuffer = event.target.result as ArrayBuffer; + const uint8Array: Uint8Array = new Uint8Array(arrayBuffer); const fileBlob: any = { type: file.type, @@ -80,7 +95,7 @@ export default function SendDocuments() { const fileData: any = { file_blob: fileBlob, - file_name: file.name + file_name: fileName }; const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';