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 5e0e41c9..749f3ca5 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts @@ -5,10 +5,25 @@ import { EFolderStatus } from "le-coffre-resources/dist/Customer/OfficeFolder"; // TODO Type get query params -> Where + inclue + orderby export interface IGetFoldersParams { - q?: {}; + q?: { + where?: {}; + include?: {}; + }; } -// 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"]; @@ -67,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: IPostFoldersParams): 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/Api/LeCoffreApi/SuperAdmin/Users/Users.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Users/Users.ts index 052a7367..94db6c0b 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Users/Users.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Users/Users.ts @@ -1,11 +1,27 @@ import { Service } from "typedi"; -import User from "le-coffre-resources/dist/Notary"; +import User from "le-coffre-resources/dist/SuperAdmin"; import BaseSuperAdmin from "../BaseSuperAdmin"; +// TODO Type get query params -> Where + inclue + orderby +export interface IGetUsersparams { + q?: {}; +} + +// TODO Type getbyuid query params + +export type IPutUsersParams = { + uid?: User["uid"]; + idNot?: User["idNot"]; + contact?: User["contact"]; + office_membership?: User["office_membership"]; + office_folder_has_stakeholders?: User["office_folder_has_stakeholders"]; + documents?: User["documents"]; +}; + @Service() export default class Users extends BaseSuperAdmin { private static instance: Users; - private readonly baseURl = this.namespaceUrl.concat("/Users"); + private readonly baseURl = this.namespaceUrl.concat("/users"); private constructor() { super(); @@ -19,8 +35,12 @@ export default class Users extends BaseSuperAdmin { } } - public async get(): Promise { + /** + * @description : Get all Users + */ + public async get(q: IGetUsersparams): 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) { @@ -29,8 +49,12 @@ export default class Users extends BaseSuperAdmin { } } - public async getByUid(uid: string): Promise { - const url = new URL(this.baseURl.concat("/").concat(uid)); + /** + * @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) { @@ -38,4 +62,30 @@ export default class Users extends BaseSuperAdmin { return Promise.reject(err); } } + + /** + * @description : Create a User + */ + // 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: IPutUsersParams): 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/LayoutTemplates/DefaultDoubleSidePage/index.tsx b/src/front/Components/LayoutTemplates/DefaultDoubleSidePage/index.tsx index e76a0821..ce0192fb 100644 --- a/src/front/Components/LayoutTemplates/DefaultDoubleSidePage/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultDoubleSidePage/index.tsx @@ -1,3 +1,4 @@ +import "reflect-metadata"; import Header from "@Front/Components/DesignSystem/Header"; import Version from "@Front/Components/DesignSystem/Version"; import classNames from "classnames"; diff --git a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx index cef389b3..f07f9332 100644 --- a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx @@ -1,6 +1,6 @@ import RightImage from "@Front/Assets/images/create-folder/right-image.png"; import Button from "@Front/Components/DesignSystem/Button"; -import Form, { IApiFormErrors } from "@Front/Components/DesignSystem/Form"; +import Form from "@Front/Components/DesignSystem/Form"; import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField"; import MultiSelect from "@Front/Components/DesignSystem/MultiSelect"; import RadioBox from "@Front/Components/DesignSystem/RadioBox"; @@ -13,11 +13,17 @@ import { ActionMeta, MultiValue } from "react-select"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; +import { Deed, DeedType, OfficeFolder, OfficeFolderHasStakeholder } from "le-coffre-resources/dist/Notary"; +import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes"; +import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; +import User from "le-coffre-resources/dist/Notary"; +import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; +import { EFolderStatus } from "le-coffre-resources/dist/Customer/OfficeFolder"; type IFormValues = { folder_number: number; entitled: string; - act_type: IOption | null; + act_typ: IOption | null; personal_note: string; collaborators: MultiValue; }; @@ -26,23 +32,12 @@ type IProps = {}; type IState = { folder_access: string; formValues: IFormValues; + deedTypes: DeedType[]; + deedTypesOptions: IOption[]; + collaborators: User[]; + collaboratorsOptions: IOption[]; }; export default class CreateFolder extends BasePage { - private collaboratorsOptions: IOption[] = [ - { label: "John Doe", value: "john_doe" }, - { label: "Éric Dupont", value: "eric_dupont" }, - { label: "Julien Doe", value: "julien_doe" }, - { label: "Nathalie Costa", value: "nathalie_costa" }, - { label: "Max Durant", value: "max_durant" }, - { label: "Jane Doe", value: "jane_doe" }, - ]; - - private actsOptions: IOption[] = [ - { label: "Divorce", value: "divorce" }, - { label: "Succession", value: "succession" }, - { label: "Vente immobilière", value: "vente_immobiliere" }, - ]; - public constructor(props: IProps) { super(props); @@ -51,10 +46,14 @@ export default class CreateFolder extends BasePage { formValues: { folder_number: NaN, entitled: "", - act_type: null, + act_typ: null, personal_note: "", collaborators: [], }, + deedTypes: [], + deedTypesOptions: [], + collaborators: [], + collaboratorsOptions: [], }; this.radioOnChange = this.radioOnChange.bind(this); @@ -64,6 +63,7 @@ export default class CreateFolder extends BasePage { this.onPersonalNoteChange = this.onPersonalNoteChange.bind(this); this.onCollaboratorsChange = this.onCollaboratorsChange.bind(this); this.isFormSubmittable = this.isFormSubmittable.bind(this); + this.onFormSubmit = this.onFormSubmit.bind(this); } public override render(): JSX.Element { @@ -85,10 +85,10 @@ export default class CreateFolder extends BasePage { type="number" onChange={this.onFolderNumberChange} /> - - { {this.state.folder_access === "select_collaborators" && (
{ ); } + public override async componentDidMount() { + const deedTypes = await DeedTypes.getInstance().get({ q: {} }); + // TODO SETUP userStore and get the user's office membership -> Replace IwJ70M471c by the user's office membership uid + const usersMock = await Users.getInstance().get({ q: { include: { office_membership: true } } }); + const userMock = usersMock[0]; + const collaborators = await Users.getInstance().get({ + q: { where: { office_membership: { uid: userMock?.office_membership.uid } }, include: { contact: true } }, + }); + this.setState({ + deedTypes, + deedTypesOptions: this.mapDeedOptions(deedTypes), + collaborators, + collaboratorsOptions: this.mapUsersOptions(collaborators), + }); + } + + private mapDeedOptions(deedTypes: DeedType[]) { + return deedTypes.map((deedType) => ({ + label: deedType.name, + value: deedType.uid, + })) as IOption[]; + } + + private mapUsersOptions(collaborators: User[]) { + return collaborators.map((collaborator) => ({ + label: collaborator.contact.last_name.concat(" ", collaborator.contact.first_name), + value: collaborator.uid, + })) as IOption[]; + } + private onFolderNumberChange(e: React.ChangeEvent) { this.setState({ formValues: { @@ -150,7 +180,7 @@ export default class CreateFolder extends BasePage { this.setState({ formValues: { ...this.state.formValues, - act_type: selectedOption, + act_typ: selectedOption, }, }); } @@ -173,20 +203,58 @@ export default class CreateFolder extends BasePage { }); } - private onFormSubmit( + private async onFormSubmit( e: React.FormEvent | null, values: { - [key: string]: string; + [key: string]: any; }, - onApiErrors: (apiFormErrors: IApiFormErrors | null) => void, - ) {} + ) { + const selectedDeedType: DeedType | undefined = this.state.deedTypes.find( + (deedType) => deedType.uid === this.state.formValues.act_typ?.value, + ); + + // const selectedCollaborator: User | undefined = this.state.collaborators?.find( + // (deedType) => deedType.uid === this.state.formValues.act_typ?.value, + // ); + + let collaborators: User[] = this.state.collaborators; + + if (!selectedDeedType) return; + const deed = Deed.hydrate({ + deed_type: selectedDeedType, + }); + let office_folder_has_stakeholders = collaborators.map((collaborator) => { + return OfficeFolderHasStakeholder.hydrate({ + office_folder: new OfficeFolder(), + user_stakeholder: collaborator, + }); + }); + + if (this.state.folder_access === "select_collaborators") { + office_folder_has_stakeholders = office_folder_has_stakeholders.filter((collaborator) => { + return this.state.formValues.collaborators?.some((selectedCollaborator) => { + return selectedCollaborator.value === collaborator.user_stakeholder.uid; + }); + }); + } + + const usersMock = await Users.getInstance().get({ q: { include: { office_membership: true } } }); + const userMock = usersMock[0]; + + values["deed"] = deed; + values["archived_description"] = ""; + values["status"] = EFolderStatus.LIVE; + values["office"] = values["office_folder_has_stakeholders"] = office_folder_has_stakeholders; + console.log(values); + // Folders.getInstance().post(values); + } private isFormSubmittable(): boolean { if ( this.state.formValues.entitled === "" || this.state.formValues.personal_note === "" || Number.isNaN(this.state.formValues.folder_number) || - this.state.formValues.act_type === null + this.state.formValues.act_typ === null ) { return false; }