diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts b/src/front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts new file mode 100644 index 00000000..a06b03e4 --- /dev/null +++ b/src/front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts @@ -0,0 +1,92 @@ +import { Service } from "typedi"; +import { Deed, DeedType } from "le-coffre-resources/dist/Notary"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDeedTypesParams { + q?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDeedTypesParams = { + uid?: DeedType["uid"]; + name?: DeedType["name"]; + description?: DeedType["description"]; + deed?: DeedType["deed"]; + office?: DeedType["office"]; + archived_at?: DeedType["archived_at"]; + deed_type_has_document_types?: DeedType["deed_type_has_document_types"]; +}; + +@Service() +export default class DeedTypes extends BaseSuperAdmin { + private static instance: DeedTypes; + private readonly baseURl = this.namespaceUrl.concat("/deed-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all DeedTypes + */ + public async get(q: IGetDeedTypesParams): 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 : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) 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 deed + */ + // public async post(body: IPostDeedTypesParams): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, body); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutDeedTypesParams): 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/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts new file mode 100644 index 00000000..948d021c --- /dev/null +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts @@ -0,0 +1,91 @@ +import { Service } from "typedi"; +import { Deed, OfficeFolder } from "le-coffre-resources/dist/Notary"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDeedsParams { + q?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDeedsParams = { + uid?: OfficeFolder["uid"]; + folder_number?: OfficeFolder["folder_number"]; + name?: OfficeFolder["name"]; + description?: OfficeFolder["description"]; + archived_description?: OfficeFolder["archived_description"]; + status?: OfficeFolder["status"]; +}; + +@Service() +export default class Deeds extends BaseSuperAdmin { + private static instance: Deeds; + private readonly baseURl = this.namespaceUrl.concat("/deeds"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all deeds + */ + public async get(q: IGetDeedsParams): 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 : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) 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 deed + */ + // public async post(body: IPostDeedsParams): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, body); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutDeedsParams): 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/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts index 334b5512..f0d59621 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts @@ -11,7 +11,19 @@ export interface IGetFoldersParams { }; } -// TODO Type getbyuid query params +// TODO Type getbyuid query searchParams +export type IPostFoldersParams = { + folder_number: OfficeFolder["folder_number"]; + name: OfficeFolder["name"]; + description: OfficeFolder["description"]; + archived_description: OfficeFolder["archived_description"]; + status: OfficeFolder["status"]; + deed: OfficeFolder["deed"]; + office: OfficeFolder["office"]; + office_folder_has_customers?: OfficeFolder["office_folder_has_customers"]; + office_folder_has_stakeholder?: OfficeFolder["office_folder_has_stakeholder"]; + documents?: OfficeFolder["documents"]; +}; export type IPutFoldersParams = { uid?: OfficeFolder["uid"]; @@ -70,15 +82,15 @@ export default class Folders extends BaseSuperAdmin { /** * @description : Create a folder */ - // public async post(body: IPostFoldersParams): 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 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); + } + } /** * @description : Update the folder description diff --git a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx index 65386b9d..d57ee893 100644 --- a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx +++ b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx @@ -85,6 +85,7 @@ export default function FolderBoxInformation(props: IProps) { function formatDate(date: Date | null): string { if (!date) return "..."; + if (!(date instanceof Date)) date = new Date(date); return date.toLocaleDateString("fr-FR", { year: "numeric", month: "long", diff --git a/src/front/Components/DesignSystem/FolderList/index.tsx b/src/front/Components/DesignSystem/FolderList/index.tsx index cbb20bec..07bf0672 100644 --- a/src/front/Components/DesignSystem/FolderList/index.tsx +++ b/src/front/Components/DesignSystem/FolderList/index.tsx @@ -28,7 +28,7 @@ class FolderListClass extends React.Component { return (
{this.props.folders.sort((folder) => { - const pendingDocuments = folder.documents!.filter((document) => document.document_status === "PENDING"); + const pendingDocuments = (folder.documents ?? []).filter((document) => document.document_status === "PENDING"); return pendingDocuments.length >= 1 ? -1 : 1; }).map((folder) => { return ( diff --git a/src/front/Components/DesignSystem/Form/index.tsx b/src/front/Components/DesignSystem/Form/index.tsx index e66cd454..39a0bfd2 100644 --- a/src/front/Components/DesignSystem/Form/index.tsx +++ b/src/front/Components/DesignSystem/Form/index.tsx @@ -1,5 +1,6 @@ import React, { ReactNode } from "react"; -import BaseField, { IError, IProps as IBaseFieldProps } from "./Elements/BaseField"; + +import BaseField, { IProps as IBaseFieldProps, IError } from "./Elements/BaseField"; export type IBaseField = BaseField; @@ -90,13 +91,41 @@ export default class Form extends React.Component { if (this.props.onValidated) this.props.onValidated(); - const elementsValues = this.getAllChildrenFields(e).reduce( + const allChildren = this.getAllChildrenFields(e); + const elementsValues = allChildren + .filter((e) => { + return e.getAttribute("type") !== "radio" && e.getAttribute("type") !== "checkbox"; + }) + .reduce((obj, element) => ({ ...obj, [element.getAttribute("name") ?? ""]: (element as any).value }), {}); + + const radioInputs = allChildren.filter((e) => e.getAttribute("type") === "radio").filter((e) => (e as any).checked); + const radioInputsValues = radioInputs.reduce( (obj, element) => ({ ...obj, [element.getAttribute("name") ?? ""]: (element as any).value }), {}, ); + const checkBoxesInput = allChildren.filter((e) => e.getAttribute("type") === "checkbox").filter((e) => (e as any).checked); + const checkBoxesValues = checkBoxesInput.reduce((obj, element) => { + const inputName = element.getAttribute("name") ?? ""; + const inputValue = (element as any).value as string; + const newValue = (obj as any)[inputName] as string[] ?? []; + newValue.push(inputValue); + return { + ...obj, + [inputName]: newValue, + }; + }, {}); + + const allInputs = { + ...elementsValues, + ...radioInputsValues, + ...checkBoxesValues, + }; + + // Deleting empty input + delete (allInputs as any)[""]; if (this.props.onSubmit) { - this.props.onSubmit(e, elementsValues, this.onSubmitErrorApi); + this.props.onSubmit(e, allInputs, this.onSubmitErrorApi); } return { values: elementsValues }; diff --git a/src/front/Components/DesignSystem/Header/Notifications/NotificationModal/index.tsx b/src/front/Components/DesignSystem/Header/Notifications/NotificationModal/index.tsx index 623bcdcf..183731ed 100644 --- a/src/front/Components/DesignSystem/Header/Notifications/NotificationModal/index.tsx +++ b/src/front/Components/DesignSystem/Header/Notifications/NotificationModal/index.tsx @@ -43,7 +43,7 @@ export default class NotificationModal extends React.Component { {Toasts.getInstance().toasts.length === 0 ? (
- Vous n’avez pas de notifications. + Vous n'avez pas de notifications.
) : ( diff --git a/src/front/Components/DesignSystem/Select/index.tsx b/src/front/Components/DesignSystem/Select/index.tsx index 9a389c2d..72425ece 100644 --- a/src/front/Components/DesignSystem/Select/index.tsx +++ b/src/front/Components/DesignSystem/Select/index.tsx @@ -14,6 +14,7 @@ type IProps = { hasBorderRightCollapsed?: boolean; placeholder?: string; className?: string; + name?: string; }; export type IOption = { @@ -50,6 +51,7 @@ export default class Select extends React.Component { const selectedOption = this.state.selectedOption ?? this.props.selectedOption; return (
+ {selectedOption && }
@@ -79,13 +87,27 @@ class UpdateFolderMetadataClass extends BasePage { ); } - public override componentDidMount(): void { + public override async componentDidMount() { + const folder = await this.getFolder(); this.setState({ + selectedFolder: folder, selectedOption: { - label: this.props.folder?.deed.deed_type?.name ?? "", - value: this.props.folder?.deed.deed_type?.uid ?? "", + label: folder?.deed.deed_type?.name ?? "", + value: folder?.deed.deed_type?.uid ?? "", }, - }); + }) + } + + private async getFolder(): Promise { + const query = { + q: { + deed: { include: { deed_type: true } }, + office: true, + office_folder_has_customers: { include: { customer: { include: { contact: true } } } }, + }, + }; + const folder = await Folders.getInstance().getByUid(this.props.folderUid, query); + return folder; } private onSelectedOption(option: IOption) { @@ -99,19 +121,9 @@ class UpdateFolderMetadataClass extends BasePage { } } -export default function UpdateFolderMetadata() { +export default function UpdateFolderMetadata(props: IProps) { const router = useRouter(); let { folderUid } = router.query; folderUid = folderUid as string; - const folder = folders.find((folder) => folder.uid === folderUid) ?? null; - return ; -} - -function formatDate(date: Date | null): string { - if (!date) return "..."; - return date.toLocaleDateString("fr-FR", { - year: "numeric", - month: "long", - day: "numeric", - }); + return ; } diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index 1e249bfb..db23e6e6 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -5,17 +5,20 @@ import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import FolderBoxInformation, { EFolderBoxInformationType } from "@Front/Components/DesignSystem/FolderBoxInformation"; import QuantityProgressBar from "@Front/Components/DesignSystem/QuantityProgressBar"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; -import { folders } from "@Front/Components/Layouts/DesignSystem/dummyData"; import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; -import { useRouter } from "next/router"; +import { NextRouter, useRouter } from "next/router"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; import ClientSection from "./ClientSection"; +import { OfficeFolder } from "le-coffre-resources/dist/Customer"; +import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; +import Module from "@Front/Config/Module"; type IProps = {}; type IPropsClass = IProps & { + router: NextRouter; selectedFolderUid: string; }; @@ -33,6 +36,7 @@ class FolderInformationClass extends BasePage { this.onSelectedFolder = this.onSelectedFolder.bind(this); this.openArchivedModal = this.openArchivedModal.bind(this); this.closeArchivedModal = this.closeArchivedModal.bind(this); + this.restoreFolder = this.restoreFolder.bind(this); } // TODO: Message if the user has not created any folder yet @@ -101,13 +105,8 @@ class FolderInformationClass extends BasePage { ); } public override async componentDidMount() { - // TODO : GET Current folder from the api - for (const folder of folders) { - if (folder.uid === this.props.selectedFolderUid) { - this.setState({ selectedFolder: folder }); - break; - } - } + const folder = await this.getFolder(); + this.setState({ selectedFolder: folder }); } private doesFolderHaveCustomer(): boolean { @@ -118,8 +117,12 @@ class FolderInformationClass extends BasePage { this.setState({ selectedFolder: folder }); } - private restoreFolder() {} - // should call the api to restore the folder + private async restoreFolder() { + if (!this.state.selectedFolder) return; + await Folders.getInstance().restore(this.state.selectedFolder.uid, this.state.selectedFolder); + this.props.router.push(Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.props.path); + } + private openArchivedModal(): void { this.setState({ isArchivedModalOpen: true }); } @@ -127,11 +130,23 @@ class FolderInformationClass extends BasePage { private closeArchivedModal(): void { this.setState({ isArchivedModalOpen: false }); } + + private async getFolder(): Promise { + const query = { + q: { + deed: { include: { deed_type: "true" } }, + office: "true", + office_folder_has_customers: { include: { customer: { include: { contact: true } } } }, + }, + }; + const folder = await Folders.getInstance().getByUid(this.props.selectedFolderUid, query); + return folder; + } } export default function FolderInformation(props: IProps) { const router = useRouter(); let { folderUid } = router.query; folderUid = folderUid as string; - return ; + return ; } diff --git a/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx b/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx index 21f3aa7f..710abc8b 100644 --- a/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx @@ -52,7 +52,7 @@ class UpdateFolderMetadataClass extends BasePage {