Ask documents working (#32)
This commit is contained in:
commit
b30ea3ea14
@ -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<DocumentType[]> {
|
||||||
|
const url = new URL(this.baseURl);
|
||||||
|
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||||
|
try {
|
||||||
|
return await this.getRequest<DocumentType[]>(url);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a Document
|
||||||
|
*/
|
||||||
|
public async post(body: any): Promise<DocumentType> {
|
||||||
|
const url = new URL(this.baseURl);
|
||||||
|
try {
|
||||||
|
return await this.postRequest<DocumentType>(url, body);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getByUid(uid: string, q?: any): Promise<DocumentType> {
|
||||||
|
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<DocumentType>(url);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async put(uid: string, body: IPutDocumentTypesParams): Promise<DocumentType> {
|
||||||
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||||
|
try {
|
||||||
|
return await this.putRequest<DocumentType>(url, body);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -53,7 +53,7 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
|||||||
const otherDocuments: Document[] | null = this.getValidatedAndPendindDocuments();
|
const otherDocuments: Document[] | null = this.getValidatedAndPendindDocuments();
|
||||||
const redirectPath = Module.getInstance()
|
const redirectPath = Module.getInstance()
|
||||||
.get()
|
.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 (
|
return (
|
||||||
<div className={classes["root"]} data-opened={this.props.isOpened.toString()}>
|
<div className={classes["root"]} data-opened={this.props.isOpened.toString()}>
|
||||||
<Confirm
|
<Confirm
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import "reflect-metadata";
|
||||||
|
|
||||||
import PlusIcon from "@Assets/Icons/plus.svg";
|
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 Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import CheckBox from "@Front/Components/DesignSystem/CheckBox";
|
import CheckBox from "@Front/Components/DesignSystem/CheckBox";
|
||||||
import Form from "@Front/Components/DesignSystem/Form";
|
import Form from "@Front/Components/DesignSystem/Form";
|
||||||
@ -8,40 +11,37 @@ import { IOption } from "@Front/Components/DesignSystem/Select";
|
|||||||
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||||
import BackArrow from "@Front/Components/Elements/BackArrow";
|
import BackArrow from "@Front/Components/Elements/BackArrow";
|
||||||
import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
||||||
|
import { NextRouter, useRouter } from "next/router";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import BasePage from "../../Base";
|
import BasePage from "../../Base";
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
|
import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes";
|
||||||
|
import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents";
|
||||||
|
import Module from "@Front/Config/Module";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
|
type IPropsClass = IProps & {
|
||||||
|
router: NextRouter;
|
||||||
|
folderUid: string;
|
||||||
|
customerUid: string;
|
||||||
|
};
|
||||||
type IState = {
|
type IState = {
|
||||||
isCreateDocumentModalVisible: boolean;
|
isCreateDocumentModalVisible: boolean;
|
||||||
documentName: string;
|
documentName: string;
|
||||||
visibleDescription: string;
|
visibleDescription: string;
|
||||||
|
documentTypes: IOption[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class AskDocuments extends BasePage<IProps, IState> {
|
class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||||
private documentsType: IOption[] = [
|
public constructor(props: IPropsClass) {
|
||||||
{ 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: IProps) {
|
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isCreateDocumentModalVisible: false,
|
isCreateDocumentModalVisible: false,
|
||||||
documentName: "",
|
documentName: "",
|
||||||
visibleDescription: "",
|
visibleDescription: "",
|
||||||
|
documentTypes: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onFormSubmit = this.onFormSubmit.bind(this);
|
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||||||
@ -65,8 +65,8 @@ export default class AskDocuments extends BasePage<IProps, IState> {
|
|||||||
<Form onSubmit={this.onFormSubmit}>
|
<Form onSubmit={this.onFormSubmit}>
|
||||||
<div className={classes["form-container"]}>
|
<div className={classes["form-container"]}>
|
||||||
<div className={classes["checkbox-container"]}>
|
<div className={classes["checkbox-container"]}>
|
||||||
{this.documentsType.map((documentType) => (
|
{this.state.documentTypes.map((documentType) => (
|
||||||
<CheckBox name="documents_type" toolTip="Checkbox with tooltip" option={documentType} key={documentType.value as string} />
|
<CheckBox name="document_types" toolTip="Checkbox with tooltip" option={documentType} key={documentType.value as string} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["add-document-container"]}>
|
<div className={classes["add-document-container"]}>
|
||||||
@ -117,6 +117,45 @@ export default class AskDocuments extends BasePage<IProps, IState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async componentDidMount(): Promise<void> {
|
||||||
|
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() {
|
private canAddDocument() {
|
||||||
if (this.state.documentName === "" || this.state.visibleDescription === "") {
|
if (this.state.documentName === "" || this.state.visibleDescription === "") {
|
||||||
return false;
|
return false;
|
||||||
@ -167,11 +206,39 @@ export default class AskDocuments extends BasePage<IProps, IState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private onFormSubmit(
|
private async onFormSubmit(
|
||||||
e: React.FormEvent<HTMLFormElement> | null,
|
e: React.FormEvent<HTMLFormElement> | null,
|
||||||
values: {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function AskDocuments(props: IProps){
|
||||||
|
const router = useRouter();
|
||||||
|
let { folderUid, customerUid } = router.query;
|
||||||
|
folderUid = folderUid as string;
|
||||||
|
customerUid = customerUid as string;
|
||||||
|
return <AskDocumentsClass folderUid={folderUid} customerUid={customerUid} router={router} />;
|
||||||
|
}
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
"AskDocument": {
|
"AskDocument": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/ask-documents",
|
"path": "/folders/[folderUid]/[customerUid]/ask-documents",
|
||||||
"labelKey": "ask_documents"
|
"labelKey": "ask_documents"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
"AskDocument": {
|
"AskDocument": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/ask-documents",
|
"path": "/folders/[folderUid]/[customerUid]/ask-documents",
|
||||||
"labelKey": "ask_documents"
|
"labelKey": "ask_documents"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
"AskDocument": {
|
"AskDocument": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/ask-documents",
|
"path": "/folders/[folderUid]/[customerUid]/ask-documents",
|
||||||
"labelKey": "ask_documents"
|
"labelKey": "ask_documents"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
"AskDocument": {
|
"AskDocument": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/ask-documents",
|
"path": "/folders/[folderUid]/[customerUid]/ask-documents",
|
||||||
"labelKey": "ask_documents"
|
"labelKey": "ask_documents"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user