Merge branch 'dev' into staging
This commit is contained in:
commit
69b0c3bf00
@ -1,6 +1,8 @@
|
||||
@import "@Themes/constants.scss";
|
||||
|
||||
.root {
|
||||
margin: 24px auto;
|
||||
width: 600px;
|
||||
.title {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
@ -1,118 +1,105 @@
|
||||
import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents";
|
||||
import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders";
|
||||
import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import Button, { EButtonSize, EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import CheckBox from "@Front/Components/DesignSystem/CheckBox";
|
||||
import Form from "@Front/Components/DesignSystem/Form";
|
||||
import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||
import BackArrow from "@Front/Components/Elements/BackArrow";
|
||||
import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
||||
import Module from "@Front/Config/Module";
|
||||
import { PlusIcon } from "@heroicons/react/24/outline";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { NextRouter, useRouter } from "next/router";
|
||||
import React from "react";
|
||||
|
||||
import BasePage from "../../Base";
|
||||
import { useRouter } from "next/router";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage";
|
||||
import classes from "./classes.module.scss";
|
||||
import ParameterDocuments from "./ParameterDocuments";
|
||||
import { IOptionOld } from "@Front/Components/DesignSystem/Form/SelectFieldOld";
|
||||
|
||||
import backgroundImage from "@Assets/images/background_refonte.svg";
|
||||
type IProps = {};
|
||||
type IPropsClass = IProps & {
|
||||
router: NextRouter;
|
||||
folderUid: string;
|
||||
customerUid: string;
|
||||
};
|
||||
type IState = {
|
||||
isCreateDocumentModalVisible: boolean;
|
||||
documentTypes: IOptionOld[];
|
||||
folder: OfficeFolder | null;
|
||||
};
|
||||
|
||||
class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
public constructor(props: IPropsClass) {
|
||||
super(props);
|
||||
export default function AskDocuments(props: IProps) {
|
||||
const router = useRouter();
|
||||
let { folderUid, customerUid } = router.query;
|
||||
folderUid = folderUid as string;
|
||||
customerUid = customerUid as string;
|
||||
const [isCreateDocumentModalVisible, setIsCreateDocumentModalVisible] = useState<boolean>(false);
|
||||
const [documentTypes, setDocumentTypes] = useState<IOptionOld[]>([]);
|
||||
const [folder, setFolder] = useState<OfficeFolder | null>(null);
|
||||
|
||||
this.state = {
|
||||
isCreateDocumentModalVisible: false,
|
||||
documentTypes: [],
|
||||
folder: null,
|
||||
};
|
||||
const closeModal = () => setIsCreateDocumentModalVisible(false);
|
||||
const openModal = () => setIsCreateDocumentModalVisible(true);
|
||||
|
||||
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||||
this.closeModal = this.closeModal.bind(this);
|
||||
this.openModal = this.openModal.bind(this);
|
||||
}
|
||||
const onFormSubmit = useCallback(
|
||||
async (
|
||||
e: React.FormEvent<HTMLFormElement> | null,
|
||||
values: {
|
||||
[key: string]: any;
|
||||
},
|
||||
) => {
|
||||
try {
|
||||
const documentAsked: [] = values["document_types"] as [];
|
||||
for (let i = 0; i < documentAsked.length; i++) {
|
||||
await Documents.getInstance().post({
|
||||
folder: {
|
||||
uid: folderUid,
|
||||
},
|
||||
depositor: {
|
||||
uid: customerUid,
|
||||
},
|
||||
document_type: {
|
||||
uid: documentAsked[i],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public override render(): JSX.Element {
|
||||
const backUrl = Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid);
|
||||
router.push(
|
||||
Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid),
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
[customerUid, folderUid, router],
|
||||
);
|
||||
|
||||
return (
|
||||
<DefaultNotaryDashboard title={"Demander des documents"}>
|
||||
<div className={classes["root"]}>
|
||||
<BackArrow url={backUrl} />
|
||||
<Typography typo={ETypo.DISPLAY_LARGE} color={ETypoColor.COLOR_GENERIC_BLACK} className={classes["title"]}>
|
||||
Demander des documents
|
||||
</Typography>
|
||||
<Form onSubmit={this.onFormSubmit}>
|
||||
<div className={classes["form-container"]}>
|
||||
<div className={classes["checkbox-container"]}>
|
||||
{this.state.documentTypes.map((documentType) => {
|
||||
if (documentType.description && documentType.description.length > 1) {
|
||||
return (
|
||||
<CheckBox
|
||||
name="document_types"
|
||||
toolTip={documentType.description}
|
||||
option={documentType}
|
||||
key={documentType.value as string}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return <CheckBox name="document_types" option={documentType} key={documentType.value as string} />;
|
||||
})}
|
||||
</div>
|
||||
<div className={classes["add-document-container"]}>
|
||||
<Button
|
||||
rightIcon={<PlusIcon style={{ transform: "rotate(180deg)", width: "22px", height: "22px" }} />}
|
||||
variant={EButtonVariant.PRIMARY}
|
||||
styletype={EButtonstyletype.TEXT}
|
||||
onClick={this.openModal}>
|
||||
Ajouter un document
|
||||
</Button>
|
||||
</div>
|
||||
<div className={classes["buttons-container"]}>
|
||||
<a href={backUrl}>
|
||||
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED} onClick={this.cancel}>
|
||||
Annuler
|
||||
</Button>
|
||||
</a>
|
||||
<Button type="submit">Valider</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
{this.state.folder && (
|
||||
<ParameterDocuments
|
||||
folder={this.state.folder}
|
||||
closeModal={this.closeModal}
|
||||
isCreateDocumentModalVisible={this.state.isCreateDocumentModalVisible}
|
||||
/>
|
||||
)}
|
||||
</DefaultNotaryDashboard>
|
||||
);
|
||||
}
|
||||
const getAvailableDocuments = useCallback(
|
||||
async (folder: OfficeFolder): Promise<IOptionOld[]> => {
|
||||
// Getting already asked documents UIDs in an array
|
||||
const userDocumentTypesUids = folder
|
||||
.documents!.filter((document) => document.depositor!.uid! === customerUid!)
|
||||
.map((document) => {
|
||||
return document.document_type!.uid!;
|
||||
});
|
||||
|
||||
public override async componentDidMount(): Promise<void> {
|
||||
this.loadData();
|
||||
}
|
||||
// If those UIDs are already asked, filter them to not show them in the list and only
|
||||
// show the documents that are not asked yet
|
||||
const documentTypes = folder.deed!.document_types!.filter((documentType) => {
|
||||
if (userDocumentTypesUids.includes(documentType!.uid!)) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
private cancel() {}
|
||||
// If there is none document type available, return an empty array
|
||||
if (!documentTypes) return [];
|
||||
|
||||
private async loadData() {
|
||||
// Else, return an array document types formatted as IOPtions
|
||||
const documentTypesOptions: IOptionOld[] = documentTypes.map((documentType) => {
|
||||
return {
|
||||
label: documentType!.name!,
|
||||
value: documentType!.uid!,
|
||||
description: documentType!.private_description!,
|
||||
};
|
||||
});
|
||||
|
||||
documentTypesOptions.sort((a, b) => (a.label > b.label ? 1 : -1));
|
||||
|
||||
return documentTypesOptions;
|
||||
},
|
||||
[customerUid],
|
||||
);
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
try {
|
||||
const folder = await Folders.getInstance().getByUid(this.props.folderUid, {
|
||||
const folder = await Folders.getInstance().getByUid(folderUid, {
|
||||
q: {
|
||||
deed: {
|
||||
include: {
|
||||
@ -129,97 +116,66 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
},
|
||||
});
|
||||
if (!folder) return;
|
||||
this.setState({
|
||||
folder,
|
||||
documentTypes: await this.getAvailableDocuments(folder),
|
||||
});
|
||||
setFolder(folder);
|
||||
setDocumentTypes(await getAvailableDocuments(folder));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}, [folderUid, getAvailableDocuments]);
|
||||
|
||||
private async getAvailableDocuments(folder: OfficeFolder): Promise<IOptionOld[]> {
|
||||
// Getting already asked documents UIDs in an array
|
||||
const userDocumentTypesUids = folder
|
||||
.documents!.filter((document) => document.depositor!.uid! === this.props.customerUid!)
|
||||
.map((document) => {
|
||||
return document.document_type!.uid!;
|
||||
});
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, [loadData]);
|
||||
|
||||
// If those UIDs are already asked, filter them to not show them in the list and only
|
||||
// show the documents that are not asked yet
|
||||
const documentTypes = folder.deed!.document_types!.filter((documentType) => {
|
||||
if (userDocumentTypesUids.includes(documentType!.uid!)) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
// If there is none document type available, return an empty array
|
||||
if (!documentTypes) return [];
|
||||
|
||||
// Else, return an array document types formatted as IOPtions
|
||||
const documentTypesOptions: IOptionOld[] = documentTypes.map((documentType) => {
|
||||
return {
|
||||
label: documentType!.name!,
|
||||
value: documentType!.uid!,
|
||||
description: documentType!.private_description!,
|
||||
};
|
||||
});
|
||||
|
||||
documentTypesOptions.sort((a, b) => (a.label > b.label ? 1 : -1));
|
||||
|
||||
return documentTypesOptions;
|
||||
}
|
||||
|
||||
private openModal() {
|
||||
this.setState({
|
||||
isCreateDocumentModalVisible: true,
|
||||
});
|
||||
}
|
||||
|
||||
private closeModal() {
|
||||
this.loadData();
|
||||
this.setState({
|
||||
isCreateDocumentModalVisible: false,
|
||||
});
|
||||
}
|
||||
|
||||
private async onFormSubmit(
|
||||
e: React.FormEvent<HTMLFormElement> | null,
|
||||
values: {
|
||||
[key: string]: any;
|
||||
},
|
||||
) {
|
||||
try {
|
||||
const documentAsked: [] = values["document_types"] as [];
|
||||
for (let i = 0; i < documentAsked.length; i++) {
|
||||
await Documents.getInstance().post({
|
||||
folder: {
|
||||
uid: this.props.folderUid,
|
||||
},
|
||||
depositor: {
|
||||
uid: this.props.customerUid,
|
||||
},
|
||||
document_type: {
|
||||
uid: documentAsked[i],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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} />;
|
||||
const backUrl = Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid);
|
||||
return (
|
||||
<DefaultDoubleSidePage title={"Demander des documents"} image={backgroundImage} showHeader>
|
||||
<div className={classes["root"]}>
|
||||
<BackArrow url={backUrl} />
|
||||
<Typography typo={ETypo.DISPLAY_LARGE} color={ETypoColor.COLOR_GENERIC_BLACK} className={classes["title"]}>
|
||||
Demander des documents
|
||||
</Typography>
|
||||
<Form onSubmit={onFormSubmit}>
|
||||
<div className={classes["form-container"]}>
|
||||
<div className={classes["checkbox-container"]}>
|
||||
{documentTypes.map((documentType) => {
|
||||
if (documentType.description && documentType.description.length > 1) {
|
||||
return (
|
||||
<CheckBox
|
||||
name="document_types"
|
||||
toolTip={documentType.description}
|
||||
option={documentType}
|
||||
key={documentType.value as string}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return <CheckBox name="document_types" option={documentType} key={documentType.value as string} />;
|
||||
})}
|
||||
</div>
|
||||
<div className={classes["add-document-container"]}>
|
||||
<Button
|
||||
rightIcon={<PlusIcon style={{ transform: "rotate(180deg)", width: "22px", height: "22px" }} />}
|
||||
variant={EButtonVariant.PRIMARY}
|
||||
styletype={EButtonstyletype.OUTLINED}
|
||||
size={EButtonSize.MD}
|
||||
onClick={openModal}>
|
||||
Ajouter un document
|
||||
</Button>
|
||||
</div>
|
||||
<div className={classes["buttons-container"]}>
|
||||
<a href={backUrl}>
|
||||
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}>
|
||||
Annuler
|
||||
</Button>
|
||||
</a>
|
||||
<Button type="submit">Valider</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
{folder && (
|
||||
<ParameterDocuments folder={folder} closeModal={closeModal} isCreateDocumentModalVisible={isCreateDocumentModalVisible} />
|
||||
)}
|
||||
</DefaultDoubleSidePage>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user