WIP Put in customer

This commit is contained in:
Maxime Lalo 2023-05-03 15:54:27 +02:00
parent 86702bac30
commit a58a08a603
9 changed files with 114 additions and 36 deletions

View File

@ -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<Customer[]> {
const url = new URL(this.baseURl);
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
try {
return await this.getRequest<Customer[]>(url);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
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)));
try {
return await this.getRequest<Customer>(url);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
public async put(uid: string, body: IPutCustomersParams): Promise<Customer> {
const url = new URL(this.baseURl.concat(`/${uid}`));
try {
return await this.putRequest<Customer>(url, body);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
}

View File

@ -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<IProps, IState> {
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 (
<div className={classes["root"]}>
<div className={classes["content"]}>
<div className={classes["container"]}>
<Typography typo={ITypo.NAV_INPUT_16}>Nom</Typography>
<Typography typo={ITypo.P_18}>{this.props.contact.last_name}</Typography>
<Typography typo={ITypo.P_18}>{this.props.customer.contact.last_name}</Typography>
</div>
<div className={classes["container"]}>
<Typography typo={ITypo.NAV_INPUT_16}>Prénom</Typography>
<Typography typo={ITypo.P_18}>{this.props.contact.first_name}</Typography>
<Typography typo={ITypo.P_18}>{this.props.customer.contact.first_name}</Typography>
</div>
<div className={classes["container"]}>
<Typography typo={ITypo.NAV_INPUT_16}>Numéro de téléphone</Typography>
<Typography typo={ITypo.P_18}>
{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)}
</Typography>
</div>
<div className={classes["container"]}>
<Typography typo={ITypo.NAV_INPUT_16}>E-mail</Typography>
<Typography typo={ITypo.P_18}>{this.props.contact.email}</Typography>
<Typography typo={ITypo.P_18}>{this.props.customer.contact.email}</Typography>
</div>
</div>
{!this.props.isArchived && (
@ -71,7 +64,7 @@ export default class UserFolderHeader extends React.Component<IProps, IState> {
}
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;
}

View File

@ -67,7 +67,7 @@ export default class UserFolder extends React.Component<IProps, IState> {
<div className={classes["header"]} onClick={this.toggleOpen}>
<UserFolderHeader
contact={this.props.customer.contact}
customer={this.props.customer}
folder={this.props.folder}
isArchived={this.props.isArchived}
/>

View File

@ -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<IPropsClass, IState> {
constructor(props: IPropsClass) {
@ -48,6 +50,8 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
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<IPropsClass, IState> {
<Typography typo={ITypo.H1Bis}>Modifier les informations du client</Typography>
<Form className={classes["form"]}>
<div className={classes["content"]}>
<InputField name="input field" fakeplaceholder="Nom" onChange={this.onChangeNameInput} defaultValue={this.props.client?.first_name}/>
<InputField name="input field" fakeplaceholder="Prénom" onChange={this.onChangeFirstNameInput} defaultValue={this.props.client?.last_name}/>
<InputField name="input field" fakeplaceholder="E-mail" isEmail onChange={this.onChangeEmailInput} defaultValue={this.props.client?.email}/>
<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"
fakeplaceholder="Numéro de téléphone"
isPositiveNumber
onChange={this.onChangePhoneNumberInput}
defaultValue={this.props.client?.phone_number}
defaultValue={this.state.customer?.contact.phone_number}
/>
<InputField
name="birthdate"
@ -129,6 +133,11 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
);
}
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<IPropsClass, IState> {
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 <UpdateClientClass {...props} router={router} selectedFolderUid={folderUid} client={client?.customer.contact ?? null} />;
customerUid = customerUid as string;
return <UpdateClientClass {...props} router={router} selectedFolderUid={folderUid} customerUid={customerUid} />;
}

View File

@ -76,7 +76,7 @@
"EditClient": {
"enabled": true,
"props": {
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
"labelKey": "edit_informations"
}
},

View File

@ -76,7 +76,7 @@
"EditClient": {
"enabled": true,
"props": {
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
"labelKey": "edit_informations"
}
},

View File

@ -76,7 +76,7 @@
"EditClient": {
"enabled": true,
"props": {
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
"labelKey": "edit_informations"
}
},

View File

@ -76,7 +76,7 @@
"EditClient": {
"enabled": true,
"props": {
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
"labelKey": "edit_informations"
}
},