From bdd65be688acc170536024f79d2a838c943faa5b Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Thu, 4 May 2023 17:13:42 +0200 Subject: [PATCH 1/8] wip --- src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts | 2 +- .../Layouts/Folder/AddClientToFolder/index.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts index a181ca1d..ab46d76e 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts @@ -39,7 +39,7 @@ export type IPutFoldersParams = { archived_description?: OfficeFolder["archived_description"]; status?: OfficeFolder["status"]; office_folder_has_stakeholder?: OfficeFolder["office_folder_has_stakeholder"]; - OfficeFolderHasCustomer?: { customer: { uid: Customer["uid"] } }[]; + office_folder_has_customers?: { customer: { uid: Customer["uid"] } }[]; }; @Service() diff --git a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx index 3cce7e20..f3815db8 100644 --- a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx @@ -148,13 +148,16 @@ class AddClientToFolderClass extends BasePage { console.log("SELECTD >>>", this.props.selectedFolderUid); const newCustomerCreated: Customer = await Customers.getInstance().post(customer); + console.log("NEW CUSTOMER CREATED >>>", newCustomerCreated); if (newCustomerCreated) { - const query = { - OfficeFolderHasCustomer: [{ customer: { uid: newCustomerCreated.uid } }], + const body = { + office_folder_has_customers: [{ customer: { uid: newCustomerCreated.uid } }], }; - await Folders.getInstance().put(this.props.selectedFolderUid, query); + console.log("BODY >>>", body); + + await Folders.getInstance().put(this.props.selectedFolderUid, body); this.props.router.push(`/folders/${this.props.selectedFolderUid}`); } } From 03c79c197ec9c876090dbefbccf52c96fd126183 Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Fri, 5 May 2023 11:28:10 +0200 Subject: [PATCH 2/8] add customers, create customers to a folder --- .gitignore | 1 + package.json | 2 +- .../SuperAdmin/Customers/Customers.ts | 7 +- .../DesignSystem/MultiSelect/index.tsx | 19 ++- .../UserFolder/UserFolderHeader/index.tsx | 7 +- .../Folder/AddClientToFolder/index.tsx | 110 +++++++++++++----- .../Folder/FolderInformation/index.tsx | 43 ++++--- .../UpdateFolderCollaborators/index.tsx | 89 +++++++------- .../FolderInformation/index.tsx | 10 +- 9 files changed, 194 insertions(+), 94 deletions(-) diff --git a/.gitignore b/.gitignore index 1cc82db5..63a49dfe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /node_modules /.pnp .pnp.js +dist/ # testing /coverage diff --git a/package.json b/package.json index f7c9576f..cb79458c 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", + "dev": "tsc && next dev", "build": "next build", "start": "next start", "lint": "next lint", diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts index a52c30c2..ac7fa867 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts @@ -6,8 +6,8 @@ import { ECivility } from "le-coffre-resources/dist/Customer/Contact"; // TODO Type get query params -> Where + inclue + orderby export interface IGetCustomersparams { - where?:{}, - include?:{}, + where?: {}; + include?: {}; } // TODO Type getbyuid query params @@ -45,7 +45,8 @@ export default class Customers extends BaseSuperAdmin { public async get(q: IGetCustomersparams): Promise { const url = new URL(this.baseURl); - Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); try { return await this.getRequest(url); } catch (err) { diff --git a/src/front/Components/DesignSystem/MultiSelect/index.tsx b/src/front/Components/DesignSystem/MultiSelect/index.tsx index 5ddacf88..f59e0dd2 100644 --- a/src/front/Components/DesignSystem/MultiSelect/index.tsx +++ b/src/front/Components/DesignSystem/MultiSelect/index.tsx @@ -58,8 +58,8 @@ export default class MultiSelect extends React.Component { options={this.props.options} styles={styles} onChange={this.onChange} - value={this.props.value} - defaultValue={this.props.defaultValue} + value={this.props.defaultValue} + defaultValue={this.state.selectedOptions} closeMenuOnSelect={this.props.shouldCloseMenuOnSelect} isMulti isOptionDisabled={this.props.isOptionDisabled} @@ -88,6 +88,21 @@ export default class MultiSelect extends React.Component { } } + public override componentDidUpdate(prevProps: IProps): void { + if (this.props.defaultValue === prevProps.defaultValue) return; + if (this.props.defaultValue) { + // If default value contains multiple IOptions + if (Array.isArray(this.props.defaultValue)) { + this.setState({ selectedOptions: this.props.defaultValue }); + } + + // If default value is a single IOption + if ("label" in this.props.defaultValue) { + this.setState({ selectedOptions: [this.props.defaultValue] }); + } + } + } + private onFocus() { this.setState({ isFocused: true }); } diff --git a/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx b/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx index f32f3dc7..bdc82961 100644 --- a/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx @@ -44,8 +44,8 @@ export default class UserFolderHeader extends React.Component {
Numéro de téléphone - {this.formatPhoneNumber(this.props.customer.contact.phone_number ?? "") ?? - this.formatPhoneNumber(this.props.customer.contact.cell_phone_number)} + {this.formatPhoneNumber(this.props.customer.contact.cell_phone_number) ?? + this.formatPhoneNumber(this.props.customer.contact.phone_number?.toString() ?? "")}
@@ -82,6 +82,5 @@ export default class UserFolderHeader extends React.Component { return output.join(""); } - private onEditClick(): void { - } + private onEditClick(): void {} } diff --git a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx index 3fecf627..44f7e245 100644 --- a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx @@ -8,14 +8,13 @@ import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import { NextRouter, useRouter } from "next/router"; -import { ActionMeta, MultiValue } from "react-select"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; import Link from "next/link"; import Module from "@Front/Config/Module"; import { ECivility } from "le-coffre-resources/dist/Customer/Contact"; -import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; +import Folders, { IPutFoldersParams } from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import Customers from "@Front/Api/LeCoffreApi/SuperAdmin/Customers/Customers"; import { Customer } from "le-coffre-resources/dist/Notary"; @@ -24,7 +23,8 @@ type IState = { selectedFolder: IDashBoardFolder | null; isExistingClientSelected: boolean; isNewClientSelected: boolean; - hasNewClientSelected: boolean; + availableCustomers: Customer[] | null; + selectedCustomers: readonly IOption[]; }; type IPropsClass = IProps & { @@ -38,7 +38,8 @@ class AddClientToFolderClass extends BasePage { selectedFolder: null, isExistingClientSelected: true, isNewClientSelected: false, - hasNewClientSelected: false, + availableCustomers: [], + selectedCustomers: [], }; this.onSelectedFolder = this.onSelectedFolder.bind(this); this.onExistingClientSelected = this.onExistingClientSelected.bind(this); @@ -47,11 +48,8 @@ class AddClientToFolderClass extends BasePage { this.onFormSubmit = this.onFormSubmit.bind(this); } public override render(): JSX.Element { - const selectOptions = [ - { value: "adazzdsqaad", label: "john Doe" }, - { value: "rijgreipgje", label: "jane Doe" }, - { value: "gipjerpogkzfe", label: "Marcelino Doe" }, - ]; + const selectOptions: IOption[] = this.getSelectedOptions(); + const backwardPath = Module.getInstance() .get() .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid); @@ -82,14 +80,17 @@ class AddClientToFolderClass extends BasePage {
{this.state.isExistingClientSelected && (
- +
- +
)} @@ -114,12 +115,57 @@ class AddClientToFolderClass extends BasePage { ); } - private onMutiSelectChange(newValue: MultiValue, actionMeta: ActionMeta): void { - if (newValue.length <= 0) { - this.setState({ hasNewClientSelected: false }); + public override async componentDidMount() { + const query = {}; + const availableCustomers = await Customers.getInstance().get(query); + let preSelectedCustomers: IOption[] | undefined = await this.getFolderPreSelectedCustomers(this.props.selectedFolderUid); + const selectedCustomers = preSelectedCustomers ?? []; + this.setState({ availableCustomers, selectedCustomers }); + } + + private async getFolderPreSelectedCustomers(folderUid: string): Promise { + const query = { + q: { + office_folder_has_customers: { + include: { + customer: { + include: { + contact: true, + }, + }, + }, + }, + }, + }; + let preSelectedCustomers: IOption[] = []; + try { + const folder = await Folders.getInstance().getByUid(folderUid, query); + preSelectedCustomers = folder.office_folder_has_customers!.map((folderHasCustomer) => { + return { + label: folderHasCustomer.customer.contact?.first_name + " " + folderHasCustomer.customer.contact?.last_name, + value: folderHasCustomer.customer.uid, + }; + }); + } catch (error) { + this.props.router.push(Module.getInstance().get().modules.pages["404"].props.path); return; } - this.setState({ hasNewClientSelected: true }); + return preSelectedCustomers; + } + + private getSelectedOptions(): IOption[] { + let options = this.state.availableCustomers?.map((customer) => { + return { + label: customer.contact?.first_name + " " + customer.contact?.last_name, + value: customer.uid, + }; + }); + if (!options) options = []; + return options; + } + + private onMutiSelectChange(selectedCustomers: readonly IOption[]): void { + this.setState({ selectedCustomers }); } private onSelectedFolder(folder: IDashBoardFolder): void { @@ -140,20 +186,30 @@ class AddClientToFolderClass extends BasePage { [key: string]: any; }, ) { - values["civility"] = ECivility.MALE; - const customer = { - contact: values, - }; - const newCustomerCreated: Customer = await Customers.getInstance().post(customer); - console.log("NEW CUSTOMER CREATED >>>", newCustomerCreated); + values["civility"] = ECivility.MALE; // TODO: should maybe be deleted later or added to the form - if (newCustomerCreated) { + let customersToLink: IPutFoldersParams["office_folder_has_customers"] = []; + if (this.state.isNewClientSelected) { + const customer: Customer = await Customers.getInstance().post({ + customer: values, + }); + if (!customer.uid) return; + customersToLink = [{ customer: { uid: customer.uid } }]; + } + + if (this.state.isExistingClientSelected) { + customersToLink = this.state.selectedCustomers.map((customer) => { + return { + customer: { uid: customer.value }, + }; + }) as IPutFoldersParams["office_folder_has_customers"]; + } + + if (customersToLink) { const body = { - office_folder_has_customers: [{ customer: { uid: newCustomerCreated.uid } }], + office_folder_has_customers: customersToLink, }; - console.log("BODY >>>", body); - await Folders.getInstance().put(this.props.selectedFolderUid, body); this.props.router.push(`/folders/${this.props.selectedFolderUid}`); } diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index 961b537a..86d1e494 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -15,7 +15,7 @@ import BasePage from "../../Base"; import classes from "./classes.module.scss"; import ClientSection from "./ClientSection"; import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; -import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; +import Folders, { IPutFoldersParams } from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import { OfficeFolder } from "le-coffre-resources/dist/Customer"; import { ChangeEvent } from "react"; @@ -54,7 +54,11 @@ class FolderInformationClass extends BasePage { .get() .modules.pages.Folder.pages.EditCollaborators.props.path.replace("[folderUid]", this.props.selectedFolderUid); return ( - +
{this.state.selectedFolder ? (
@@ -74,7 +78,11 @@ class FolderInformationClass extends BasePage {
- +
{this.doesFolderHaveCustomer() && }
@@ -102,7 +110,12 @@ class FolderInformationClass extends BasePage {
Souhaitez-vous vraiment archiver le dossier ?
- + ) : ( @@ -125,9 +138,9 @@ class FolderInformationClass extends BasePage { }); } - private getCompletionNumber(){ + private getCompletionNumber() { const documents = this.state.selectedFolder?.documents; - if(!documents) return 0; + if (!documents) return 0; const totalDocuments = documents.length; const askedDocuments = documents.filter((document) => document.document_status === EDocumentStatus.ASKED).length; const depositedDocuments = totalDocuments - askedDocuments; @@ -152,15 +165,15 @@ class FolderInformationClass extends BasePage { this.setState({ isArchivedModalOpen: false }); } - private onArchivedDescriptionInputChange(e: ChangeEvent){ - this.setState({inputArchivedDescripton: e.target.value}) + private onArchivedDescriptionInputChange(e: ChangeEvent) { + this.setState({ inputArchivedDescripton: e.target.value }); } private async onArchivedModalAccepted() { if (!this.state.selectedFolder) return; const folder = this.state.selectedFolder; folder.archived_description = this.state.inputArchivedDescripton; - await Folders.getInstance().archive(this.state.selectedFolder.uid ?? "", folder); + await Folders.getInstance().archive(this.state.selectedFolder.uid ?? "", folder as IPutFoldersParams); this.closeArchivedModal(); this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path); } @@ -173,13 +186,13 @@ class FolderInformationClass extends BasePage { office_folder_has_customers: { include: { customer: { include: { contact: true } } } }, documents: { include: { - depositor:{ + depositor: { include: { - contact: true - } - } - } - } + contact: true, + }, + }, + }, + }, }, }; const folder = await Folders.getInstance().getByUid(this.props.selectedFolderUid, query); diff --git a/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx b/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx index 5397894d..d0d05218 100644 --- a/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx @@ -46,15 +46,15 @@ class UpdateFolderCollaboratorsClass extends BasePage { this.onFormSubmit = this.onFormSubmit.bind(this); this.onChangeSelectedCollaborators = this.onChangeSelectedCollaborators.bind(this); } - public override render(): JSX.Element { + public override render(): JSX.Element { const foldersInformationPath = Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path; const backwardPath = foldersInformationPath.replace("[folderUid]", this.props.selectedFolderUid); - const selectOptions : IOption[]= this.state.availableCollaborators.map((collaborator) => { + const selectOptions: IOption[] = this.state.availableCollaborators.map((collaborator) => { return { label: collaborator.contact?.first_name + " " + collaborator.contact?.last_name, value: collaborator.uid, - } - }) + }; + }); return (
@@ -75,7 +75,12 @@ class UpdateFolderCollaboratorsClass extends BasePage { {this.state.selectedOption === ERadioBoxValue.SELECTION && (
- +
)} @@ -91,11 +96,11 @@ class UpdateFolderCollaboratorsClass extends BasePage { ); } - public override async componentDidMount(){ + public override async componentDidMount() { await this.getFolderAvailableCollaborators(this.props.selectedFolderUid); } - private async getFolderAvailableCollaborators(folderUid: string){ + private async getFolderAvailableCollaborators(folderUid: string) { const query = { q: { office: true, @@ -104,44 +109,44 @@ class UpdateFolderCollaboratorsClass extends BasePage { user_stakeholder: { include: { contact: true, - } - } - } + }, + }, + }, }, }, - }; + }; let folder = null; try { - folder = await Folders.getInstance().getByUid(folderUid, query); - const preSelectedCollaborators : IOption[]= folder.office_folder_has_stakeholder!.map((collaborator) => { + folder = await Folders.getInstance().getByUid(folderUid, query); + const preSelectedCollaborators: IOption[] = folder.office_folder_has_stakeholder!.map((collaborator) => { return { label: collaborator.user_stakeholder.contact?.first_name + " " + collaborator.user_stakeholder.contact?.last_name, value: collaborator.user_stakeholder.uid, - } - }) - this.setState({selectedCollaborators: preSelectedCollaborators}) - } catch (error) { + }; + }); + this.setState({ selectedCollaborators: preSelectedCollaborators }); + } catch (error) { this.props.router.push(Module.getInstance().get().modules.pages["404"].props.path); return; } - + const userQuery: IGetUsersparams = { - where: { + where: { office_uid: folder.office?.uid, }, - include:{ + include: { contact: { - select:{ - first_name:true, - last_name:true, - } - } - } + select: { + first_name: true, + last_name: true, + }, + }, + }, }; - const availableCollaborators = await Users.getInstance().get(userQuery); - this.setState({availableCollaborators}); + const availableCollaborators = await Users.getInstance().get(userQuery); + this.setState({ availableCollaborators }); } private onSelectedOptionAllOffice(event: React.ChangeEvent) { @@ -168,18 +173,24 @@ class UpdateFolderCollaboratorsClass extends BasePage { private async onFormSubmit(e: React.FormEvent | null, values: { [key: string]: string }) { try { - let collaboratorsUid : OfficeFolderHasStakeholder[]; - if(this.state.selectedOption === ERadioBoxValue.SELECTION){ - collaboratorsUid = this.state.selectedCollaborators.map((collaborator) => ({user_stakeholder: {uid: collaborator.value}} as OfficeFolderHasStakeholder)); + let collaboratorsUid: OfficeFolderHasStakeholder[]; + if (this.state.selectedOption === ERadioBoxValue.SELECTION) { + collaboratorsUid = this.state.selectedCollaborators.map( + (collaborator) => ({ user_stakeholder: { uid: collaborator.value } } as OfficeFolderHasStakeholder), + ); + } else { + collaboratorsUid = this.state.availableCollaborators.map( + (collaborator) => ({ user_stakeholder: { uid: collaborator.uid } } as OfficeFolderHasStakeholder), + ); } - else{ - collaboratorsUid = this.state.availableCollaborators.map((collaborator) => ({user_stakeholder: {uid: collaborator.uid}} as OfficeFolderHasStakeholder)); - } - await Folders.getInstance().put(this.props.selectedFolderUid, {office_folder_has_stakeholder: collaboratorsUid}); - this.props.router.push(Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid)); - + await Folders.getInstance().put(this.props.selectedFolderUid, { office_folder_has_stakeholder: collaboratorsUid }); + this.props.router.push( + Module.getInstance() + .get() + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid), + ); } catch (error) { - console.error(error) + console.error(error); } } } @@ -188,5 +199,5 @@ export default function UpdateFolderCollaborators() { const router = useRouter(); let { folderUid } = router.query; folderUid = folderUid as string; - return ; + return ; } diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index 21399c54..840adf24 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -12,7 +12,7 @@ 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 Folders, { IPutFoldersParams } from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import Module from "@Front/Config/Module"; type IProps = {}; @@ -121,8 +121,12 @@ class FolderInformationClass extends BasePage { if (!this.state.selectedFolder) return; const folder = this.state.selectedFolder; folder.archived_description = null; - await Folders.getInstance().restore(this.state.selectedFolder.uid ?? "", folder); - this.props.router.push(Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid)); + await Folders.getInstance().restore(this.state.selectedFolder.uid ?? "", folder as IPutFoldersParams); + this.props.router.push( + Module.getInstance() + .get() + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid), + ); } private openArchivedModal(): void { From 528293430c10743c4e2693969c68d989fa7c6b45 Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Fri, 5 May 2023 11:44:03 +0200 Subject: [PATCH 3/8] next build --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb79458c..188cf199 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "tsc && next dev", + "dev": "next build && next dev", "build": "next build", "start": "next start", "lint": "next lint", From 84e049ce9d966c2f157f79ff3a2668f50974b13f Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 May 2023 14:34:32 +0200 Subject: [PATCH 4/8] :sparkles: Only one user folder opened working --- .../DesignSystem/UserFolder/index.tsx | 46 +++---------------- .../FolderInformation/ClientSection/index.tsx | 22 +++------ 2 files changed, 14 insertions(+), 54 deletions(-) diff --git a/src/front/Components/DesignSystem/UserFolder/index.tsx b/src/front/Components/DesignSystem/UserFolder/index.tsx index a7f00bd0..79343a4b 100644 --- a/src/front/Components/DesignSystem/UserFolder/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/index.tsx @@ -22,12 +22,10 @@ type IProps = { folder: IDashBoardFolder; isArchived?: boolean; isOpened: boolean; - onOpen: (id: string) => void; - onClose: () => void; + onChange: (id: string) => void; }; type IState = { isOpenDeletionModal: boolean; - willClose: boolean; }; export default class UserFolder extends React.Component { @@ -41,13 +39,10 @@ export default class UserFolder extends React.Component { super(props); this.state = { isOpenDeletionModal: false, - willClose: false, }; - this.toggleOpen = this.toggleOpen.bind(this); this.closeDeletionModal = this.closeDeletionModal.bind(this); this.openDeletionModal = this.openDeletionModal.bind(this); - this.openComponent = this.openComponent.bind(this); - this.closeComponent = this.closeComponent.bind(this); + this.changeUserFolder = this.changeUserFolder.bind(this); } public override render(): JSX.Element { const documentsAsked: Document[] | null = this.getDocumentsByStatus("ASKED"); @@ -67,7 +62,7 @@ export default class UserFolder extends React.Component { Êtes-vous vous de vouloir supprimer la demande de document ? -
+
{ src={ChevronIcon} alt="chevron open close" className={classNames(classes["chevron-icon"], this.props.isOpened && classes["open"])} - onClick={this.toggleOpen} + onClick={this.changeUserFolder} />
{this.props.isOpened && ( -
+
{ public override componentDidUpdate(prevProps: IProps): void { this.rootRefElement.current?.style.setProperty("--animation-delay", this.props.animationDelay!.toString().concat("ms")); - - if(prevProps.isOpened !== this.props.isOpened) { - if(this.props.isOpened) { - this.openComponent(); - }else{ - this.closeComponent(); - } - } } - private calculateDocumentsPercentageProgress(): number { if (!this.props.customer.documents) return 0; const totalDocuments: number = this.props.customer.documents.length; @@ -165,27 +151,9 @@ export default class UserFolder extends React.Component { // return this.props.customer.documents.filter((document) => !documentToExclude.includes(document)); // } - private toggleOpen(): void { - if (this.props.isOpened) { - this.closeComponent(); - } else { - this.openComponent(); - } - } - private openComponent(): void { - this.props.onOpen(this.props.folder.uid!); - } - - private closeComponent(): void { - if (this.state.willClose) return; - this.setState({ willClose: true }); - window.setTimeout(() => { - this.props.onClose(); - this.setState({ - willClose: false, - }); - }, this.props.animationDelay); + private changeUserFolder(){ + this.props.onChange(this.props.customer.uid!); } private openDeletionModal(uid?: string): void { diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx index 9a709763..cbe0d96d 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx @@ -23,8 +23,7 @@ export default class ClientSection extends React.Component { openedCustomer: "", }; - this.selectUserFolder = this.selectUserFolder.bind(this); - this.closeUserFolder = this.closeUserFolder.bind(this); + this.changeUserFolder = this.changeUserFolder.bind(this); } public override render(): JSX.Element { @@ -63,15 +62,13 @@ export default class ClientSection extends React.Component { private renderCustomerFolders() { const output = this.props.folder.office_folder_has_customers?.map((folderHasCustomer, index) => { if (!folderHasCustomer.customer) return null; - // TODO : Les documents ASKED fonctionne mais les autres documents ne doivcent etre seulement ceux qui correspondent au folder return ( ); }); @@ -79,15 +76,10 @@ export default class ClientSection extends React.Component { } - private closeUserFolder() { + private changeUserFolder(uid: string) { + console.log("changeUserFolder", uid) this.setState({ - openedCustomer: "", - }); - } - - private selectUserFolder(index: string) { - this.setState({ - openedCustomer: index, + openedCustomer: uid === this.state.openedCustomer ? "" : uid, }); } From 8e1e912502605cc8496e9343e7687b8d25416e47 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 May 2023 14:35:16 +0200 Subject: [PATCH 5/8] :bug: Forgot console.log --- .../Layouts/Folder/FolderInformation/ClientSection/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx index cbe0d96d..355f89ca 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx @@ -77,7 +77,6 @@ export default class ClientSection extends React.Component { private changeUserFolder(uid: string) { - console.log("changeUserFolder", uid) this.setState({ openedCustomer: uid === this.state.openedCustomer ? "" : uid, }); From f7dd2c244a7cdbcfe9d03ef9b436b0ee65fe425f Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 May 2023 14:45:45 +0200 Subject: [PATCH 6/8] :bug: Fixing build --- .../Components/Layouts/DesignSystem/index.tsx | 2 +- .../FolderInformation/ClientSection/index.tsx | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/front/Components/Layouts/DesignSystem/index.tsx b/src/front/Components/Layouts/DesignSystem/index.tsx index 9f643aa9..84d95c54 100644 --- a/src/front/Components/Layouts/DesignSystem/index.tsx +++ b/src/front/Components/Layouts/DesignSystem/index.tsx @@ -240,7 +240,7 @@ export default class DesignSystem extends BasePage { Notary Documents
- {return}} onOpen={() => {return}}/> + {return}}/>
diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx index 23250620..83f4950e 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx @@ -18,8 +18,7 @@ export default class ClientSection extends React.Component { openedCustomer: "", }; - this.selectUserFolder = this.selectUserFolder.bind(this); - this.closeUserFolder = this.closeUserFolder.bind(this); + this.changeUserFolder = this.changeUserFolder.bind(this); } public override render(): JSX.Element { @@ -50,23 +49,16 @@ export default class ClientSection extends React.Component { customer={folderHasCustomer.customer} key={this.props.folder.uid} isOpened={this.state.openedCustomer === this.props.folder.uid} - onOpen={this.selectUserFolder} - onClose={this.closeUserFolder} + onChange={this.changeUserFolder} /> ); }); return output ?? null; } - private closeUserFolder() { + private changeUserFolder(uid: string) { this.setState({ - openedCustomer: "", - }); - } - - private selectUserFolder(index: string) { - this.setState({ - openedCustomer: index, + openedCustomer: uid === this.state.openedCustomer ? "" : uid, }); } From b3a44dd97c6ff821aa18745abd7da5ec69d3087f Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Fri, 5 May 2023 15:00:33 +0200 Subject: [PATCH 7/8] hot fix --- .../Folder/AddClientToFolder/index.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx index 44f7e245..5daf7a2d 100644 --- a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx @@ -188,21 +188,18 @@ class AddClientToFolderClass extends BasePage { ) { values["civility"] = ECivility.MALE; // TODO: should maybe be deleted later or added to the form - let customersToLink: IPutFoldersParams["office_folder_has_customers"] = []; + let customersToLink: IPutFoldersParams["office_folder_has_customers"] = this.state.selectedCustomers.map((customer) => { + return { + customer: { uid: customer.value }, + }; + }) as IPutFoldersParams["office_folder_has_customers"]; + if (this.state.isNewClientSelected) { const customer: Customer = await Customers.getInstance().post({ - customer: values, + contact: values, }); if (!customer.uid) return; - customersToLink = [{ customer: { uid: customer.uid } }]; - } - - if (this.state.isExistingClientSelected) { - customersToLink = this.state.selectedCustomers.map((customer) => { - return { - customer: { uid: customer.value }, - }; - }) as IPutFoldersParams["office_folder_has_customers"]; + customersToLink?.push({ customer: { uid: customer.uid } }); } if (customersToLink) { From 860529a3612a92a5a3d79bfc5d05d0abb4967937 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 May 2023 17:21:47 +0200 Subject: [PATCH 8/8] :bug: Fix merge --- .../Components/Layouts/Folder/FolderInformation/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index f0cee6b3..cc299a01 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -1,7 +1,7 @@ import "reflect-metadata"; import ChevronIcon from "@Assets/Icons/chevron.svg"; -import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; +import Folders, { IPutFoldersParams } from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import FolderBoxInformation, { EFolderBoxInformationType } from "@Front/Components/DesignSystem/FolderBoxInformation"; import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField"; @@ -19,10 +19,6 @@ import { ChangeEvent } from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; import ClientSection from "./ClientSection"; -import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; -import Folders, { IPutFoldersParams } from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; -import { OfficeFolder } from "le-coffre-resources/dist/Customer"; -import { ChangeEvent } from "react"; type IProps = {};