diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts new file mode 100644 index 00000000..ad759e07 --- /dev/null +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts @@ -0,0 +1,81 @@ +import { Service } from "typedi"; +import Customer from "le-coffre-resources/dist/SuperAdmin"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetCustomersparams { + q?: {}; +} + +// TODO Type getbyuid query params + +export type IPutCustomersParams = { + uid?: Customer["uid"]; + contact?: Customer["contact"]; +}; + +@Service() +export default class Customers extends BaseSuperAdmin { + private static instance: Customers; + private readonly baseURl = this.namespaceUrl.concat("/customers"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all Customers + */ + 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))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getOne(uid: string): Promise { + const url = new URL(this.baseURl.concat("/").concat(uid)); + 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); + } + } + + public async put(uid: string, body: IPutCustomersParams): 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/DesignSystem/UserFolder/UserFolderHeader/index.tsx b/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx index 2f449829..da52f608 100644 --- a/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx @@ -1,6 +1,6 @@ import React from "react"; import classes from "./classes.module.scss"; -import { Contact } from "le-coffre-resources/dist/Notary"; +import { Customer } from "le-coffre-resources/dist/Notary"; import Typography, { ITypo } from "../../Typography"; import Image from "next/image"; import PenIcon from "@Assets/Icons/pen.svg"; @@ -10,14 +10,7 @@ import Module from "@Front/Config/Module"; import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; type IProps = { - contact: { - uid?: Contact["uid"]; - first_name: Contact["first_name"]; - last_name: Contact["last_name"]; - phone_number?: Contact["phone_number"]; - cell_phone_number: Contact["cell_phone_number"]; - email: Contact["email"]; - }; + customer: Customer; folder: IDashBoardFolder; isArchived?: boolean; }; @@ -31,31 +24,31 @@ export default class UserFolderHeader extends React.Component { const redirectPath = Module.getInstance() .get() .modules.pages.Folder.pages.EditClient.props.path.replace("[folderUid]", this.props.folder.uid ?? "") - .replace("[clientUid]", this.props.contact.uid ?? ""); + .replace("[customerUid]", this.props.customer.uid ?? ""); return (
Nom - {this.props.contact.last_name} + {this.props.customer.contact.last_name}
Prénom - {this.props.contact.first_name} + {this.props.customer.contact.first_name}
Numéro de téléphone - {this.formatPhoneNumber(this.props.contact.phone_number ?? "") ?? - this.formatPhoneNumber(this.props.contact.cell_phone_number)} + {this.formatPhoneNumber(this.props.customer.contact.phone_number ?? "") ?? + this.formatPhoneNumber(this.props.customer.contact.cell_phone_number)}
E-mail - {this.props.contact.email} + {this.props.customer.contact.email}
{!this.props.isArchived && ( @@ -71,7 +64,7 @@ export default class UserFolderHeader extends React.Component { } private hasPendingFiles(){ - const documents = this.props.folder.documents?.filter((document) => document.depositor.contact.uid === this.props.contact.uid) ?? []; + const documents = this.props.folder.documents?.filter((document) => document.depositor.contact.uid === this.props.customer.contact.uid) ?? []; const notAskedDocuments = documents.filter((document) => document.document_status === "PENDING") ?? []; return notAskedDocuments.length > 0; } diff --git a/src/front/Components/DesignSystem/UserFolder/index.tsx b/src/front/Components/DesignSystem/UserFolder/index.tsx index 0f9ea492..4e6e400a 100644 --- a/src/front/Components/DesignSystem/UserFolder/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/index.tsx @@ -67,7 +67,7 @@ export default class UserFolder extends React.Component {
diff --git a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx index 286d67df..eea7fa47 100644 --- a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx @@ -6,23 +6,23 @@ import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField" import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; -import { folders } from "@Front/Components/Layouts/DesignSystem/dummyData"; import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import { Contact } from "le-coffre-resources/dist/Customer"; import Link from "next/link"; import { NextRouter, useRouter } from "next/router"; import { ChangeEvent } from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; +import Customer from "le-coffre-resources/dist/Customer"; +import Customers from "@Front/Api/LeCoffreApi/SuperAdmin/Customers/Customers"; type IProps = {}; type IPropsClass = IProps & { selectedFolderUid: string; router: NextRouter; - client: Contact | null; + customerUid: string; }; type IState = { selectedFolder: IDashBoardFolder | null; @@ -34,6 +34,8 @@ type IState = { doesInputHaveValues: boolean; inputBirthdate: Date | null; inputAddress: string; + folder: IDashBoardFolder | null; + customer: Customer | null; }; class UpdateClientClass extends BasePage { constructor(props: IPropsClass) { @@ -48,6 +50,8 @@ class UpdateClientClass extends BasePage { doesInputHaveValues: false, inputBirthdate: null, inputAddress: "", + folder: null, + customer: null, }; this.onSelectedFolder = this.onSelectedFolder.bind(this); this.onChangeNameInput = this.onChangeNameInput.bind(this); @@ -75,15 +79,15 @@ class UpdateClientClass extends BasePage { Modifier les informations du client
- - - + + + { ); } + public override async componentDidMount() { + const customer = await Customers.getInstance().getOne(this.props.customerUid); + console.log(customer); + } + private leavePage() { this.props.router.push(this.backwardPath); } @@ -179,13 +188,8 @@ class UpdateClientClass extends BasePage { export default function UpdateClient(props: IProps) { const router = useRouter(); - let { folderUid, clientUid } = router.query; + let { folderUid, customerUid } = router.query; folderUid = folderUid as string; - - let client = null; - const folder = folders.find((folder) => folder.uid === folderUid) ?? null; - if (folder && folder.office_folder_has_customers) { - client = folder.office_folder_has_customers.find((client) => client.customer.contact.uid === clientUid) ?? null; - } - return ; + customerUid = customerUid as string; + return ; } diff --git a/src/front/Config/Module/development.json b/src/front/Config/Module/development.json index 1702ebb5..89ae00f9 100644 --- a/src/front/Config/Module/development.json +++ b/src/front/Config/Module/development.json @@ -76,7 +76,7 @@ "EditClient": { "enabled": true, "props": { - "path": "/folders/[folderUid]/edit/clients/[clientUid]", + "path": "/folders/[folderUid]/edit/clients/[customerUid]", "labelKey": "edit_informations" } }, diff --git a/src/front/Config/Module/preprod.json b/src/front/Config/Module/preprod.json index 1702ebb5..89ae00f9 100644 --- a/src/front/Config/Module/preprod.json +++ b/src/front/Config/Module/preprod.json @@ -76,7 +76,7 @@ "EditClient": { "enabled": true, "props": { - "path": "/folders/[folderUid]/edit/clients/[clientUid]", + "path": "/folders/[folderUid]/edit/clients/[customerUid]", "labelKey": "edit_informations" } }, diff --git a/src/front/Config/Module/production.json b/src/front/Config/Module/production.json index 1702ebb5..89ae00f9 100644 --- a/src/front/Config/Module/production.json +++ b/src/front/Config/Module/production.json @@ -76,7 +76,7 @@ "EditClient": { "enabled": true, "props": { - "path": "/folders/[folderUid]/edit/clients/[clientUid]", + "path": "/folders/[folderUid]/edit/clients/[customerUid]", "labelKey": "edit_informations" } }, diff --git a/src/front/Config/Module/staging.json b/src/front/Config/Module/staging.json index 1702ebb5..89ae00f9 100644 --- a/src/front/Config/Module/staging.json +++ b/src/front/Config/Module/staging.json @@ -76,7 +76,7 @@ "EditClient": { "enabled": true, "props": { - "path": "/folders/[folderUid]/edit/clients/[clientUid]", + "path": "/folders/[folderUid]/edit/clients/[customerUid]", "labelKey": "edit_informations" } }, diff --git a/src/pages/folders/[folderUid]/edit/clients/[clientUid].tsx b/src/pages/folders/[folderUid]/edit/clients/[customerUid].tsx similarity index 100% rename from src/pages/folders/[folderUid]/edit/clients/[clientUid].tsx rename to src/pages/folders/[folderUid]/edit/clients/[customerUid].tsx