Merge branch 'dev' into staging
This commit is contained in:
commit
0e706d4371
@ -8,16 +8,17 @@ import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Ty
|
||||
import BackArrow from "@Front/Components/Elements/BackArrow";
|
||||
import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate";
|
||||
import Module from "@Front/Config/Module";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
import JwtService, { ICustomerJwtPayload } from "@Front/Services/JwtService/JwtService";
|
||||
import { ArrowDownTrayIcon, EyeIcon } from "@heroicons/react/24/outline";
|
||||
import { saveAs } from "file-saver";
|
||||
import JSZip from "jszip";
|
||||
import DocumentNotary from "le-coffre-resources/dist/Notary/DocumentNotary";
|
||||
import { useRouter } from "next/router";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import classes from "./classes.module.scss";
|
||||
import Link from "next/link";
|
||||
import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders";
|
||||
import Customer from "le-coffre-resources/dist/Customer";
|
||||
import { DocumentNotary } from "le-coffre-resources/dist/Notary";
|
||||
|
||||
const header: readonly IHead[] = [
|
||||
{
|
||||
@ -38,14 +39,53 @@ export default function ReceivedDocuments() {
|
||||
const router = useRouter();
|
||||
let { folderUid } = router.query;
|
||||
const [documentsNotary, setDocumentsNotary] = useState<DocumentNotary[]>([]);
|
||||
const [customer, setCustomer] = useState<Customer | null>(null);
|
||||
|
||||
const fetchFolderAndCustomer = useCallback(async () => {
|
||||
let jwt: ICustomerJwtPayload | undefined;
|
||||
if (typeof document !== "undefined") {
|
||||
jwt = JwtService.getInstance().decodeCustomerJwt();
|
||||
}
|
||||
|
||||
const folder = await Folders.getInstance().getByUid(folderUid as string, {
|
||||
q: {
|
||||
office: true,
|
||||
customers: true,
|
||||
notes: {
|
||||
include: {
|
||||
customer: true,
|
||||
},
|
||||
},
|
||||
stakeholders: {
|
||||
include: {
|
||||
contact: true,
|
||||
office_role: true,
|
||||
},
|
||||
},
|
||||
deed: {
|
||||
include: {
|
||||
deed_type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const customer = folder?.customers?.find((customer) => customer.contact?.email === jwt?.email);
|
||||
if (!customer) throw new Error("Customer not found");
|
||||
|
||||
setCustomer(customer);
|
||||
|
||||
return { folder, customer };
|
||||
}, [folderUid]);
|
||||
|
||||
useEffect(() => {
|
||||
const customerUid = JwtService.getInstance().decodeCustomerJwt()?.customerId;
|
||||
fetchFolderAndCustomer();
|
||||
const customerUid = customer?.uid;
|
||||
if (!folderUid || !customerUid) return;
|
||||
DocumentsNotary.getInstance()
|
||||
.get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } })
|
||||
.then((documentsNotary) => setDocumentsNotary(documentsNotary));
|
||||
}, [folderUid]);
|
||||
}, [folderUid, customer]);
|
||||
|
||||
const onDownload = useCallback((doc: DocumentNotary) => {
|
||||
const file = doc.files?.[0];
|
||||
|
@ -108,12 +108,12 @@ export default function ClientDashboard(props: IProps) {
|
||||
}, [fetchDocuments, fetchFolderAndCustomer]);
|
||||
|
||||
useEffect(() => {
|
||||
const customerUid = JwtService.getInstance().decodeCustomerJwt()?.customerId;
|
||||
const customerUid = customer?.uid;
|
||||
if (!folderUid || !customerUid) return;
|
||||
DocumentsNotary.getInstance()
|
||||
.get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } })
|
||||
.then((documentsNotary) => setDocumentsNotary(documentsNotary));
|
||||
}, [folderUid]);
|
||||
}, [folderUid, customer?.uid]);
|
||||
|
||||
const documentsNotaryNotRead = useMemo(
|
||||
() => documentsNotary.filter((doc) => doc.document_status === EDocumentNotaryStatus.SENT),
|
||||
|
Loading…
x
Reference in New Issue
Block a user