Preprod (#199)
This commit is contained in:
commit
c679fe2d25
@ -8,16 +8,17 @@ import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Ty
|
|||||||
import BackArrow from "@Front/Components/Elements/BackArrow";
|
import BackArrow from "@Front/Components/Elements/BackArrow";
|
||||||
import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate";
|
import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate";
|
||||||
import Module from "@Front/Config/Module";
|
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 { ArrowDownTrayIcon, EyeIcon } from "@heroicons/react/24/outline";
|
||||||
import { saveAs } from "file-saver";
|
import { saveAs } from "file-saver";
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
import DocumentNotary from "le-coffre-resources/dist/Notary/DocumentNotary";
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
import Link from "next/link";
|
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[] = [
|
const header: readonly IHead[] = [
|
||||||
{
|
{
|
||||||
@ -38,14 +39,53 @@ export default function ReceivedDocuments() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
let { folderUid } = router.query;
|
let { folderUid } = router.query;
|
||||||
const [documentsNotary, setDocumentsNotary] = useState<DocumentNotary[]>([]);
|
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(() => {
|
useEffect(() => {
|
||||||
const customerUid = JwtService.getInstance().decodeCustomerJwt()?.customerId;
|
fetchFolderAndCustomer();
|
||||||
|
const customerUid = customer?.uid;
|
||||||
if (!folderUid || !customerUid) return;
|
if (!folderUid || !customerUid) return;
|
||||||
DocumentsNotary.getInstance()
|
DocumentsNotary.getInstance()
|
||||||
.get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } })
|
.get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } })
|
||||||
.then((documentsNotary) => setDocumentsNotary(documentsNotary));
|
.then((documentsNotary) => setDocumentsNotary(documentsNotary));
|
||||||
}, [folderUid]);
|
}, [folderUid, customer]);
|
||||||
|
|
||||||
const onDownload = useCallback((doc: DocumentNotary) => {
|
const onDownload = useCallback((doc: DocumentNotary) => {
|
||||||
const file = doc.files?.[0];
|
const file = doc.files?.[0];
|
||||||
|
@ -108,12 +108,12 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
}, [fetchDocuments, fetchFolderAndCustomer]);
|
}, [fetchDocuments, fetchFolderAndCustomer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const customerUid = JwtService.getInstance().decodeCustomerJwt()?.customerId;
|
const customerUid = customer?.uid;
|
||||||
if (!folderUid || !customerUid) return;
|
if (!folderUid || !customerUid) return;
|
||||||
DocumentsNotary.getInstance()
|
DocumentsNotary.getInstance()
|
||||||
.get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } })
|
.get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } })
|
||||||
.then((documentsNotary) => setDocumentsNotary(documentsNotary));
|
.then((documentsNotary) => setDocumentsNotary(documentsNotary));
|
||||||
}, [folderUid]);
|
}, [folderUid, customer?.uid]);
|
||||||
|
|
||||||
const documentsNotaryNotRead = useMemo(
|
const documentsNotaryNotRead = useMemo(
|
||||||
() => documentsNotary.filter((doc) => doc.document_status === EDocumentNotaryStatus.SENT),
|
() => documentsNotary.filter((doc) => doc.document_status === EDocumentNotaryStatus.SENT),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user