From 14a47bc4749f8e97be9dd8e447a47ca8fdbe5426 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 9 May 2023 13:22:07 +0200 Subject: [PATCH 1/3] :sparkles: Getting documents available --- .../SuperAdmin/DocumentTypes/DocumentTypes.ts | 81 +++++++++++++++++++ .../Layouts/Folder/AskDocuments/index.tsx | 64 ++++++++++++++- 2 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 src/front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts b/src/front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts new file mode 100644 index 00000000..0cb86bd3 --- /dev/null +++ b/src/front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts @@ -0,0 +1,81 @@ +import { DocumentType } from "le-coffre-resources/dist/SuperAdmin"; +import { Service } from "typedi"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentTypesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentTypesParams = { +}; + +export interface IPostDocumentTypesParams {} + +@Service() +export default class DocumentTypes extends BaseSuperAdmin { + private static instance: DocumentTypes; + private readonly baseURl = this.namespaceUrl.concat("/document-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentTypesparams): Promise { + const url = new URL(this.baseURl); + Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentTypesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx index 2f95d95e..8316e98a 100644 --- a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx @@ -1,4 +1,7 @@ +import "reflect-metadata"; + import PlusIcon from "@Assets/Icons/plus.svg"; +import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import Form from "@Front/Components/DesignSystem/Form"; @@ -8,19 +11,27 @@ import { IOption } from "@Front/Components/DesignSystem/Select"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { NextRouter, useRouter } from "next/router"; import React from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; +import DocumentTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes"; +import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes"; type IProps = {}; +type IPropsClass = IProps & { + router: NextRouter; + folderUid: string; +}; type IState = { isCreateDocumentModalVisible: boolean; documentName: string; visibleDescription: string; + documentTypes: IOption[]; }; -export default class AskDocuments extends BasePage { +class AskDocumentsClass extends BasePage { private documentsType: IOption[] = [ { label: "Carte d'identité", value: "carte_identite" }, { label: "Diagnostic État Risques et Pollution", value: "diagnostic_erep" }, @@ -35,13 +46,14 @@ export default class AskDocuments extends BasePage { { label: "Diagnostic État des nuisances sonores aériennes", value: "diagnostic_ednsa" }, ]; - public constructor(props: IProps) { + public constructor(props: IPropsClass) { super(props); this.state = { isCreateDocumentModalVisible: false, documentName: "", visibleDescription: "", + documentTypes: [], }; this.onFormSubmit = this.onFormSubmit.bind(this); @@ -65,7 +77,7 @@ export default class AskDocuments extends BasePage {
- {this.documentsType.map((documentType) => ( + {this.state.documentTypes.map((documentType) => ( ))}
@@ -117,6 +129,45 @@ export default class AskDocuments extends BasePage { ); } + public override async componentDidMount(): Promise { + try{ + const folder = await Folders.getInstance().getByUid(this.props.folderUid, { + q:{ + deed: { + include: { + deed_type: true + } + } + } + }); + if(!folder) return; + + const documentTypes = await DeedTypes.getInstance().getByUid(folder.deed!.deed_type!.uid!, { + q: { + deed_type_has_document_types: { + include: { + document_type: true + } + } + } + }) + + if(!documentTypes) return; + + const documentTypesOptions: IOption[] = documentTypes.deed_type_has_document_types!.map((documentType) => { + return { + label: documentType.document_type!.name!, + value: documentType.document_type!.uid!, + }; + }); + + this.setState({ + documentTypes: documentTypesOptions, + }); + }catch(e){ + console.error(e); + } + } private canAddDocument() { if (this.state.documentName === "" || this.state.visibleDescription === "") { return false; @@ -175,3 +226,10 @@ export default class AskDocuments extends BasePage { ) { } } + +export default function AskDocuments(props: IProps){ + const router = useRouter(); + let { folderUid } = router.query; + folderUid = folderUid as string; + return ; +} From 22442234e2e832496d9d14c9ea353a6cf64776e0 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 9 May 2023 13:32:57 +0200 Subject: [PATCH 2/3] :sparkles: Ask documents working --- .../DesignSystem/UserFolder/index.tsx | 2 +- .../Layouts/Folder/AskDocuments/index.tsx | 50 +++++++++++-------- src/front/Config/Module/development.json | 2 +- src/front/Config/Module/preprod.json | 2 +- src/front/Config/Module/production.json | 2 +- src/front/Config/Module/staging.json | 2 +- .../ask-documents/index.tsx | 0 7 files changed, 35 insertions(+), 25 deletions(-) rename src/pages/folders/[folderUid]/{ => [customerUid]}/ask-documents/index.tsx (100%) diff --git a/src/front/Components/DesignSystem/UserFolder/index.tsx b/src/front/Components/DesignSystem/UserFolder/index.tsx index 8e0b391b..d0c528de 100644 --- a/src/front/Components/DesignSystem/UserFolder/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/index.tsx @@ -49,7 +49,7 @@ export default class UserFolder extends React.Component { const otherDocuments: Document[] | null = this.getValidatedAndPendindDocuments(); const redirectPath = Module.getInstance() .get() - .modules.pages.Folder.pages.AskDocument.props.path.replace("[folderUid]", this.props.folder.uid ?? ""); + .modules.pages.Folder.pages.AskDocument.props.path.replace("[folderUid]", this.props.folder.uid ?? "").replace("[customerUid]", this.props.customer.uid ?? ""); return (
{ - private documentsType: IOption[] = [ - { label: "Carte d'identité", value: "carte_identite" }, - { label: "Diagnostic État Risques et Pollution", value: "diagnostic_erep" }, - { label: "Justificatif de domicile", value: "justificatif_domicile" }, - { label: "Diagnostic gaz", value: "diagnostic_gaz" }, - { label: "Compromis de vente", value: "compromis_de_vente" }, - { label: "Diagnostic DPE", value: "diagnostic_dpe" }, - { label: "Diagnostic électrique", value: "diagnostic_electrique" }, - { label: "Diagnostic plombs", value: "diagnostic_plombs" }, - { label: "Diagnostic amiante", value: "diagnostic_amiante" }, - { label: "Diagnostic termites", value: "diagnostic_termites" }, - { label: "Diagnostic État des nuisances sonores aériennes", value: "diagnostic_ednsa" }, - ]; - public constructor(props: IPropsClass) { super(props); @@ -78,7 +66,7 @@ class AskDocumentsClass extends BasePage {
{this.state.documentTypes.map((documentType) => ( - + ))}
@@ -218,18 +206,40 @@ class AskDocumentsClass extends BasePage { }); } - private onFormSubmit( + private async onFormSubmit( e: React.FormEvent | null, values: { - [key: string]: string; + [key: string]: any; } ) { + try{ + const documentAsked: [] = values["document_types"] as []; + await documentAsked.forEach(async (document) => { + await Documents.getInstance().post({ + folder: { + uid: this.props.folderUid + }, + depositor: { + uid: this.props.customerUid + }, + document_type: { + uid: document + } + }); + }); + + this.props.router.push(Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid)); + }catch(e){ + console.error(e); + } + console.log(values["document_types"]); } } export default function AskDocuments(props: IProps){ const router = useRouter(); - let { folderUid } = router.query; + let { folderUid, customerUid } = router.query; folderUid = folderUid as string; - return ; + customerUid = customerUid as string; + return ; } diff --git a/src/front/Config/Module/development.json b/src/front/Config/Module/development.json index ed5d3660..882bd5dd 100644 --- a/src/front/Config/Module/development.json +++ b/src/front/Config/Module/development.json @@ -55,7 +55,7 @@ "AskDocument": { "enabled": true, "props": { - "path": "/folders/[folderUid]/ask-documents", + "path": "/folders/[folderUid]/[customerUid]/ask-documents", "labelKey": "ask_documents" } }, diff --git a/src/front/Config/Module/preprod.json b/src/front/Config/Module/preprod.json index ed5d3660..882bd5dd 100644 --- a/src/front/Config/Module/preprod.json +++ b/src/front/Config/Module/preprod.json @@ -55,7 +55,7 @@ "AskDocument": { "enabled": true, "props": { - "path": "/folders/[folderUid]/ask-documents", + "path": "/folders/[folderUid]/[customerUid]/ask-documents", "labelKey": "ask_documents" } }, diff --git a/src/front/Config/Module/production.json b/src/front/Config/Module/production.json index ed5d3660..882bd5dd 100644 --- a/src/front/Config/Module/production.json +++ b/src/front/Config/Module/production.json @@ -55,7 +55,7 @@ "AskDocument": { "enabled": true, "props": { - "path": "/folders/[folderUid]/ask-documents", + "path": "/folders/[folderUid]/[customerUid]/ask-documents", "labelKey": "ask_documents" } }, diff --git a/src/front/Config/Module/staging.json b/src/front/Config/Module/staging.json index ed5d3660..882bd5dd 100644 --- a/src/front/Config/Module/staging.json +++ b/src/front/Config/Module/staging.json @@ -55,7 +55,7 @@ "AskDocument": { "enabled": true, "props": { - "path": "/folders/[folderUid]/ask-documents", + "path": "/folders/[folderUid]/[customerUid]/ask-documents", "labelKey": "ask_documents" } }, diff --git a/src/pages/folders/[folderUid]/ask-documents/index.tsx b/src/pages/folders/[folderUid]/[customerUid]/ask-documents/index.tsx similarity index 100% rename from src/pages/folders/[folderUid]/ask-documents/index.tsx rename to src/pages/folders/[folderUid]/[customerUid]/ask-documents/index.tsx From 824390d9f4e244022ff4aa89773b13f566c6947d Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 9 May 2023 16:24:51 +0200 Subject: [PATCH 3/3] :bug: Forgot console log --- src/front/Components/Layouts/Folder/AskDocuments/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx index fac5849e..44aced87 100644 --- a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx @@ -232,7 +232,6 @@ class AskDocumentsClass extends BasePage { }catch(e){ console.error(e); } - console.log(values["document_types"]); } }