✨ 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 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<Customer[]> {
|
||||
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<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> {
|
||||
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<Customer>(url);
|
||||
} 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 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<IPropsClass, IState> {
|
||||
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<IPropsClass, IState> {
|
||||
<BackArrow url={this.backwardPath} />
|
||||
</div>
|
||||
<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"]}>
|
||||
<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
|
||||
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"
|
||||
isPositiveNumber
|
||||
onChange={this.onChangePhoneNumberInput}
|
||||
@ -91,10 +106,11 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
||||
/>
|
||||
<InputField
|
||||
name="birthdate"
|
||||
type="date"
|
||||
type="text"
|
||||
fakeplaceholder="Date de naissance"
|
||||
required={false}
|
||||
onChange={this.onChangeBirthDateInput}
|
||||
defaultValue={this.state.customer?.contact.birthdate?.toString() ?? ""}
|
||||
/>
|
||||
<InputField
|
||||
name="address"
|
||||
@ -102,6 +118,7 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
||||
fakeplaceholder="Adresse"
|
||||
required={false}
|
||||
onChange={this.onChangeAddressInput}
|
||||
defaultValue={this.state.customer?.contact.address?.address ?? ""}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -134,8 +151,46 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
||||
}
|
||||
|
||||
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<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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user