✨ Update users working
This commit is contained in:
parent
00a7529c72
commit
25202a2542
@ -1,5 +1,6 @@
|
|||||||
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import Customer from "le-coffre-resources/dist/SuperAdmin";
|
|
||||||
import BaseSuperAdmin from "../BaseSuperAdmin";
|
import BaseSuperAdmin from "../BaseSuperAdmin";
|
||||||
|
|
||||||
// TODO Type get query params -> Where + inclue + orderby
|
// 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<Customer[]> {
|
public async get(q: IGetCustomersparams): Promise<Customer[]> {
|
||||||
const url = new URL(this.baseURl);
|
const url = new URL(this.baseURl);
|
||||||
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
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<Customer> {
|
|
||||||
const url = new URL(this.baseURl.concat("/").concat(uid));
|
|
||||||
try {
|
|
||||||
return await this.getRequest<Customer>(url);
|
|
||||||
} catch (err) {
|
|
||||||
this.onError(err);
|
|
||||||
return Promise.reject(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Get a folder by uid
|
|
||||||
*/
|
|
||||||
public async getByUid(uid: string, q?: any): Promise<Customer> {
|
public async getByUid(uid: string, q?: any): Promise<Customer> {
|
||||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
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 {
|
try {
|
||||||
return await this.getRequest<Customer>(url);
|
return await this.getRequest<Customer>(url);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -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 Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import Form from "@Front/Components/DesignSystem/Form";
|
import Form from "@Front/Components/DesignSystem/Form";
|
||||||
import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField";
|
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 BackArrow from "@Front/Components/Elements/BackArrow";
|
||||||
import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
||||||
import Module from "@Front/Config/Module";
|
import Module from "@Front/Config/Module";
|
||||||
|
import Customer, { Contact } from "le-coffre-resources/dist/Customer";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { NextRouter, useRouter } from "next/router";
|
import { NextRouter, useRouter } from "next/router";
|
||||||
import { ChangeEvent } from "react";
|
import { ChangeEvent } from "react";
|
||||||
|
|
||||||
import BasePage from "../../Base";
|
import BasePage from "../../Base";
|
||||||
import classes from "./classes.module.scss";
|
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 IProps = {};
|
||||||
|
|
||||||
@ -63,6 +61,7 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
this.leavePage = this.leavePage.bind(this);
|
this.leavePage = this.leavePage.bind(this);
|
||||||
this.onChangeBirthDateInput = this.onChangeBirthDateInput.bind(this);
|
this.onChangeBirthDateInput = this.onChangeBirthDateInput.bind(this);
|
||||||
this.onChangeAddressInput = this.onChangeAddressInput.bind(this);
|
this.onChangeAddressInput = this.onChangeAddressInput.bind(this);
|
||||||
|
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private backwardPath = Module.getInstance()
|
private backwardPath = Module.getInstance()
|
||||||
@ -77,13 +76,29 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
<BackArrow url={this.backwardPath} />
|
<BackArrow url={this.backwardPath} />
|
||||||
</div>
|
</div>
|
||||||
<Typography typo={ITypo.H1Bis}>Modifier les informations du client</Typography>
|
<Typography typo={ITypo.H1Bis}>Modifier les informations du client</Typography>
|
||||||
<Form className={classes["form"]}>
|
<Form className={classes["form"]} onSubmit={this.onFormSubmit}>
|
||||||
<div className={classes["content"]}>
|
<div className={classes["content"]}>
|
||||||
<InputField name="input field" fakeplaceholder="Nom" onChange={this.onChangeNameInput} defaultValue={this.state.customer?.contact.first_name}/>
|
|
||||||
<InputField name="input field" fakeplaceholder="Prénom" onChange={this.onChangeFirstNameInput} defaultValue={this.state.customer?.contact.last_name}/>
|
|
||||||
<InputField name="input field" fakeplaceholder="E-mail" isEmail onChange={this.onChangeEmailInput} defaultValue={this.state.customer?.contact.email}/>
|
|
||||||
<InputField
|
<InputField
|
||||||
name="input field"
|
name="first_name"
|
||||||
|
fakeplaceholder="Nom"
|
||||||
|
onChange={this.onChangeNameInput}
|
||||||
|
defaultValue={this.state.customer?.contact.first_name}
|
||||||
|
/>
|
||||||
|
<InputField
|
||||||
|
name="last_name"
|
||||||
|
fakeplaceholder="Prénom"
|
||||||
|
onChange={this.onChangeFirstNameInput}
|
||||||
|
defaultValue={this.state.customer?.contact.last_name}
|
||||||
|
/>
|
||||||
|
<InputField
|
||||||
|
name="email"
|
||||||
|
fakeplaceholder="E-mail"
|
||||||
|
isEmail
|
||||||
|
onChange={this.onChangeEmailInput}
|
||||||
|
defaultValue={this.state.customer?.contact.email}
|
||||||
|
/>
|
||||||
|
<InputField
|
||||||
|
name="phone_number"
|
||||||
fakeplaceholder="Numéro de téléphone"
|
fakeplaceholder="Numéro de téléphone"
|
||||||
isPositiveNumber
|
isPositiveNumber
|
||||||
onChange={this.onChangePhoneNumberInput}
|
onChange={this.onChangePhoneNumberInput}
|
||||||
@ -91,10 +106,11 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
/>
|
/>
|
||||||
<InputField
|
<InputField
|
||||||
name="birthdate"
|
name="birthdate"
|
||||||
type="date"
|
type="text"
|
||||||
fakeplaceholder="Date de naissance"
|
fakeplaceholder="Date de naissance"
|
||||||
required={false}
|
required={false}
|
||||||
onChange={this.onChangeBirthDateInput}
|
onChange={this.onChangeBirthDateInput}
|
||||||
|
defaultValue={this.state.customer?.contact.birthdate?.toString() ?? ""}
|
||||||
/>
|
/>
|
||||||
<InputField
|
<InputField
|
||||||
name="address"
|
name="address"
|
||||||
@ -102,6 +118,7 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
fakeplaceholder="Adresse"
|
fakeplaceholder="Adresse"
|
||||||
required={false}
|
required={false}
|
||||||
onChange={this.onChangeAddressInput}
|
onChange={this.onChangeAddressInput}
|
||||||
|
defaultValue={this.state.customer?.contact.address?.address ?? ""}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -134,8 +151,46 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async componentDidMount() {
|
public override async componentDidMount() {
|
||||||
const customer = await Customers.getInstance().getOne(this.props.customerUid);
|
const customer = await Customers.getInstance().getByUid(this.props.customerUid, {
|
||||||
console.log(customer);
|
contact: {
|
||||||
|
include: {
|
||||||
|
address: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (customer) {
|
||||||
|
this.setState({
|
||||||
|
customer,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async onFormSubmit(
|
||||||
|
e: React.FormEvent<HTMLFormElement> | 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() {
|
private leavePage() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user