WIP Put in customer
This commit is contained in:
parent
86702bac30
commit
a58a08a603
81
src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts
Normal file
81
src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import classes from "./classes.module.scss";
|
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 Typography, { ITypo } from "../../Typography";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import PenIcon from "@Assets/Icons/pen.svg";
|
import PenIcon from "@Assets/Icons/pen.svg";
|
||||||
@ -10,14 +10,7 @@ import Module from "@Front/Config/Module";
|
|||||||
import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
contact: {
|
customer: Customer;
|
||||||
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"];
|
|
||||||
};
|
|
||||||
folder: IDashBoardFolder;
|
folder: IDashBoardFolder;
|
||||||
isArchived?: boolean;
|
isArchived?: boolean;
|
||||||
};
|
};
|
||||||
@ -31,31 +24,31 @@ export default class UserFolderHeader extends React.Component<IProps, IState> {
|
|||||||
const redirectPath = Module.getInstance()
|
const redirectPath = Module.getInstance()
|
||||||
.get()
|
.get()
|
||||||
.modules.pages.Folder.pages.EditClient.props.path.replace("[folderUid]", this.props.folder.uid ?? "")
|
.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 (
|
return (
|
||||||
<div className={classes["root"]}>
|
<div className={classes["root"]}>
|
||||||
<div className={classes["content"]}>
|
<div className={classes["content"]}>
|
||||||
<div className={classes["container"]}>
|
<div className={classes["container"]}>
|
||||||
<Typography typo={ITypo.NAV_INPUT_16}>Nom</Typography>
|
<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>
|
||||||
|
|
||||||
<div className={classes["container"]}>
|
<div className={classes["container"]}>
|
||||||
<Typography typo={ITypo.NAV_INPUT_16}>Prénom</Typography>
|
<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>
|
||||||
|
|
||||||
<div className={classes["container"]}>
|
<div className={classes["container"]}>
|
||||||
<Typography typo={ITypo.NAV_INPUT_16}>Numéro de téléphone</Typography>
|
<Typography typo={ITypo.NAV_INPUT_16}>Numéro de téléphone</Typography>
|
||||||
<Typography typo={ITypo.P_18}>
|
<Typography typo={ITypo.P_18}>
|
||||||
{this.formatPhoneNumber(this.props.contact.phone_number ?? "") ??
|
{this.formatPhoneNumber(this.props.customer.contact.phone_number ?? "") ??
|
||||||
this.formatPhoneNumber(this.props.contact.cell_phone_number)}
|
this.formatPhoneNumber(this.props.customer.contact.cell_phone_number)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={classes["container"]}>
|
<div className={classes["container"]}>
|
||||||
<Typography typo={ITypo.NAV_INPUT_16}>E-mail</Typography>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
{!this.props.isArchived && (
|
{!this.props.isArchived && (
|
||||||
@ -71,7 +64,7 @@ export default class UserFolderHeader extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private hasPendingFiles(){
|
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") ?? [];
|
const notAskedDocuments = documents.filter((document) => document.document_status === "PENDING") ?? [];
|
||||||
return notAskedDocuments.length > 0;
|
return notAskedDocuments.length > 0;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
|||||||
|
|
||||||
<div className={classes["header"]} onClick={this.toggleOpen}>
|
<div className={classes["header"]} onClick={this.toggleOpen}>
|
||||||
<UserFolderHeader
|
<UserFolderHeader
|
||||||
contact={this.props.customer.contact}
|
customer={this.props.customer}
|
||||||
folder={this.props.folder}
|
folder={this.props.folder}
|
||||||
isArchived={this.props.isArchived}
|
isArchived={this.props.isArchived}
|
||||||
/>
|
/>
|
||||||
|
@ -6,23 +6,23 @@ import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField"
|
|||||||
import Confirm from "@Front/Components/DesignSystem/Modal/Confirm";
|
import Confirm from "@Front/Components/DesignSystem/Modal/Confirm";
|
||||||
import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
|
||||||
import BackArrow from "@Front/Components/Elements/BackArrow";
|
import BackArrow from "@Front/Components/Elements/BackArrow";
|
||||||
import { folders } from "@Front/Components/Layouts/DesignSystem/dummyData";
|
|
||||||
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 { 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 = {};
|
||||||
|
|
||||||
type IPropsClass = IProps & {
|
type IPropsClass = IProps & {
|
||||||
selectedFolderUid: string;
|
selectedFolderUid: string;
|
||||||
router: NextRouter;
|
router: NextRouter;
|
||||||
client: Contact | null;
|
customerUid: string;
|
||||||
};
|
};
|
||||||
type IState = {
|
type IState = {
|
||||||
selectedFolder: IDashBoardFolder | null;
|
selectedFolder: IDashBoardFolder | null;
|
||||||
@ -34,6 +34,8 @@ type IState = {
|
|||||||
doesInputHaveValues: boolean;
|
doesInputHaveValues: boolean;
|
||||||
inputBirthdate: Date | null;
|
inputBirthdate: Date | null;
|
||||||
inputAddress: string;
|
inputAddress: string;
|
||||||
|
folder: IDashBoardFolder | null;
|
||||||
|
customer: Customer | null;
|
||||||
};
|
};
|
||||||
class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
||||||
constructor(props: IPropsClass) {
|
constructor(props: IPropsClass) {
|
||||||
@ -48,6 +50,8 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
doesInputHaveValues: false,
|
doesInputHaveValues: false,
|
||||||
inputBirthdate: null,
|
inputBirthdate: null,
|
||||||
inputAddress: "",
|
inputAddress: "",
|
||||||
|
folder: null,
|
||||||
|
customer: null,
|
||||||
};
|
};
|
||||||
this.onSelectedFolder = this.onSelectedFolder.bind(this);
|
this.onSelectedFolder = this.onSelectedFolder.bind(this);
|
||||||
this.onChangeNameInput = this.onChangeNameInput.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>
|
<Typography typo={ITypo.H1Bis}>Modifier les informations du client</Typography>
|
||||||
<Form className={classes["form"]}>
|
<Form className={classes["form"]}>
|
||||||
<div className={classes["content"]}>
|
<div className={classes["content"]}>
|
||||||
<InputField name="input field" fakeplaceholder="Nom" onChange={this.onChangeNameInput} defaultValue={this.props.client?.first_name}/>
|
<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.props.client?.last_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.props.client?.email}/>
|
<InputField name="input field" fakeplaceholder="E-mail" isEmail onChange={this.onChangeEmailInput} defaultValue={this.state.customer?.contact.email}/>
|
||||||
<InputField
|
<InputField
|
||||||
name="input field"
|
name="input field"
|
||||||
fakeplaceholder="Numéro de téléphone"
|
fakeplaceholder="Numéro de téléphone"
|
||||||
isPositiveNumber
|
isPositiveNumber
|
||||||
onChange={this.onChangePhoneNumberInput}
|
onChange={this.onChangePhoneNumberInput}
|
||||||
defaultValue={this.props.client?.phone_number}
|
defaultValue={this.state.customer?.contact.phone_number}
|
||||||
/>
|
/>
|
||||||
<InputField
|
<InputField
|
||||||
name="birthdate"
|
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() {
|
private leavePage() {
|
||||||
this.props.router.push(this.backwardPath);
|
this.props.router.push(this.backwardPath);
|
||||||
}
|
}
|
||||||
@ -179,13 +188,8 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
|||||||
|
|
||||||
export default function UpdateClient(props: IProps) {
|
export default function UpdateClient(props: IProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
let { folderUid, clientUid } = router.query;
|
let { folderUid, customerUid } = router.query;
|
||||||
folderUid = folderUid as string;
|
folderUid = folderUid as string;
|
||||||
|
customerUid = customerUid as string;
|
||||||
let client = null;
|
return <UpdateClientClass {...props} router={router} selectedFolderUid={folderUid} customerUid={customerUid} />;
|
||||||
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} />;
|
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
"EditClient": {
|
"EditClient": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
|
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
|
||||||
"labelKey": "edit_informations"
|
"labelKey": "edit_informations"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
"EditClient": {
|
"EditClient": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
|
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
|
||||||
"labelKey": "edit_informations"
|
"labelKey": "edit_informations"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
"EditClient": {
|
"EditClient": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
|
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
|
||||||
"labelKey": "edit_informations"
|
"labelKey": "edit_informations"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
"EditClient": {
|
"EditClient": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"props": {
|
"props": {
|
||||||
"path": "/folders/[folderUid]/edit/clients/[clientUid]",
|
"path": "/folders/[folderUid]/edit/clients/[customerUid]",
|
||||||
"labelKey": "edit_informations"
|
"labelKey": "edit_informations"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user