diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts index ad759e07..065b0a47 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts @@ -1,5 +1,6 @@ +import { Customer } from "le-coffre-resources/dist/SuperAdmin"; import { Service } from "typedi"; -import Customer from "le-coffre-resources/dist/SuperAdmin"; + import BaseSuperAdmin from "../BaseSuperAdmin"; // TODO Type get query params -> Where + inclue + orderby @@ -31,9 +32,6 @@ export default class Customers extends BaseSuperAdmin { } } - /** - * @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))); @@ -45,22 +43,10 @@ export default class Customers extends BaseSuperAdmin { } } - 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))); + const query = { q }; + if (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/Layouts/Folder/UpdateClient/index.tsx b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx index eea7fa47..779fa406 100644 --- a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx @@ -1,5 +1,4 @@ -import "reflect-metadata"; - +import Customers from "@Front/Api/LeCoffreApi/SuperAdmin/Customers/Customers"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField"; @@ -8,14 +7,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 Module from "@Front/Config/Module"; +import Customer, { 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 = {}; @@ -63,6 +61,7 @@ class UpdateClientClass extends BasePage { this.leavePage = this.leavePage.bind(this); this.onChangeBirthDateInput = this.onChangeBirthDateInput.bind(this); this.onChangeAddressInput = this.onChangeAddressInput.bind(this); + this.onFormSubmit = this.onFormSubmit.bind(this); } private backwardPath = Module.getInstance() @@ -77,13 +76,29 @@ class UpdateClientClass extends BasePage { Modifier les informations du client -
+
- - - + + + { /> { fakeplaceholder="Adresse" required={false} onChange={this.onChangeAddressInput} + defaultValue={this.state.customer?.contact.address?.address ?? ""} />
@@ -134,8 +151,46 @@ class UpdateClientClass extends BasePage { } public override async componentDidMount() { - const customer = await Customers.getInstance().getOne(this.props.customerUid); - console.log(customer); + const customer = await Customers.getInstance().getByUid(this.props.customerUid, { + contact: { + include: { + address: true, + }, + }, + }); + if (customer) { + this.setState({ + customer, + }); + } + } + + private async onFormSubmit( + e: React.FormEvent | null, + values: { + [key: string]: string; + }, + ) { + const contact = { + first_name: values["first_name"], + last_name: values["last_name"], + email: values["email"], + phone_number: values["phone_number"], + birthdate: values["birthdate"] === "" ? null : values["birthdate"], + address: + values["address"] === "" + ? null + : { + address: values["address"], + }, + } as Contact; + + try{ + await Customers.getInstance().put(this.props.customerUid, { contact }) + this.props.router.push(this.backwardPath); + } catch (e) { + console.error(e) + } } private leavePage() {