This commit is contained in:
Hugo Lextrait 2023-05-03 17:05:46 +02:00
commit 78ec354c9c
7 changed files with 113 additions and 162 deletions

View File

@ -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) {

View File

@ -7,6 +7,13 @@
width: 100%; width: 100%;
border: 1px solid $grey-medium; border: 1px solid $grey-medium;
&[data-disabled="true"]{
.container-label{
cursor: not-allowed;
}
opacity: 0.6;
}
.container-label { .container-label {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -17,6 +24,8 @@
padding: 24px; padding: 24px;
z-index: 1; z-index: 1;
&[data-border-right-collapsed="true"] { &[data-border-right-collapsed="true"] {
border-radius: 8px 0 0 8px; border-radius: 8px 0 0 8px;
} }

View File

@ -9,12 +9,13 @@ import classes from "./classes.module.scss";
type IProps = { type IProps = {
selectedOption?: IOption; selectedOption?: IOption;
onChange: (selectedOption: IOption) => void; onChange?: (selectedOption: IOption) => void;
options: IOption[]; options: IOption[];
hasBorderRightCollapsed?: boolean; hasBorderRightCollapsed?: boolean;
placeholder?: string; placeholder?: string;
className?: string; className?: string;
name?: string; name?: string;
disabled: boolean;
}; };
export type IOption = { export type IOption = {
@ -35,6 +36,10 @@ export default class Select extends React.Component<IProps, IState> {
private rootRef = React.createRef<HTMLDivElement>(); private rootRef = React.createRef<HTMLDivElement>();
private removeOnresize = () => {}; private removeOnresize = () => {};
static defaultProps = {
disabled: false,
};
constructor(props: IProps) { constructor(props: IProps) {
super(props); super(props);
this.state = { this.state = {
@ -50,7 +55,10 @@ export default class Select extends React.Component<IProps, IState> {
public override render(): JSX.Element { public override render(): JSX.Element {
const selectedOption = this.state.selectedOption ?? this.props.selectedOption; const selectedOption = this.state.selectedOption ?? this.props.selectedOption;
return ( return (
<div className={classNames(classes["root"], this.props.className)} ref={this.rootRef}> <div
className={classNames(classes["root"], this.props.className)}
ref={this.rootRef}
data-disabled={this.props.disabled.toString()}>
{selectedOption && <input type="text" defaultValue={selectedOption.value as string} name={this.props.name} hidden />} {selectedOption && <input type="text" defaultValue={selectedOption.value as string} name={this.props.name} hidden />}
<label <label
className={classNames(classes["container-label"])} className={classNames(classes["container-label"])}
@ -126,6 +134,7 @@ export default class Select extends React.Component<IProps, IState> {
} }
private toggle(e: FormEvent) { private toggle(e: FormEvent) {
if (this.props.disabled) return;
e.preventDefault(); e.preventDefault();
let listHeight = 0; let listHeight = 0;
let listWidth = this.rootRef.current?.scrollWidth ?? 0; let listWidth = this.rootRef.current?.scrollWidth ?? 0;
@ -140,6 +149,7 @@ export default class Select extends React.Component<IProps, IState> {
} }
private onSelect(option: IOption, e: React.MouseEvent<HTMLLIElement, MouseEvent>) { private onSelect(option: IOption, e: React.MouseEvent<HTMLLIElement, MouseEvent>) {
if (this.props.disabled) return;
this.props.onChange && this.props.onChange(option); this.props.onChange && this.props.onChange(option);
this.setState({ this.setState({
selectedOption: option, selectedOption: option,

View File

@ -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() {

View File

@ -4,6 +4,7 @@ import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders";
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";
import Select, { IOption } from "@Front/Components/DesignSystem/Select";
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 DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
@ -39,6 +40,11 @@ class UpdateFolderMetadataClass extends BasePage<IPropsClass, IState> {
const backwardPath = Module.getInstance() const backwardPath = Module.getInstance()
.get() .get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.state.selectedFolder?.uid!); .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.state.selectedFolder?.uid!);
const deedOption = {
label: this.state.selectedFolder?.deed?.deed_type?.name,
value: this.state.selectedFolder?.deed?.deed_type?.uid,
} as IOption;
const openingDate = new Date(this.state.selectedFolder?.created_at ?? "");
return ( return (
<DefaultNotaryDashboard title={"Ajouter client(s)"} onSelectedFolder={this.onSelectedFolder}> <DefaultNotaryDashboard title={"Ajouter client(s)"} onSelectedFolder={this.onSelectedFolder}>
<div className={classes["root"]}> <div className={classes["root"]}>
@ -55,6 +61,12 @@ class UpdateFolderMetadataClass extends BasePage<IPropsClass, IState> {
fakeplaceholder="Numéro de dossier" fakeplaceholder="Numéro de dossier"
defaultValue={this.state.selectedFolder?.folder_number} defaultValue={this.state.selectedFolder?.folder_number}
/> />
<Select options={[]} placeholder={"Type d'acte"} selectedOption={deedOption} disabled />
<InputField
fakeplaceholder="Ouverture du dossier"
defaultValue={openingDate.toLocaleDateString("fr-FR")}
disabled
/>
</div> </div>
<div className={classes["button-container"]}> <div className={classes["button-container"]}>
@ -73,21 +85,23 @@ class UpdateFolderMetadataClass extends BasePage<IPropsClass, IState> {
const folder = await this.getFolder(); const folder = await this.getFolder();
this.setState({ this.setState({
selectedFolder: folder, selectedFolder: folder,
}) });
} }
private async onFormSubmit( private async onFormSubmit(
e: React.FormEvent<HTMLFormElement> | null, e: React.FormEvent<HTMLFormElement> | null,
values: { values: {
[key: string]: string; [key: string]: string;
} },
) { ) {
try{ try {
await Folders.getInstance().put(this.props.folderUid, values); await Folders.getInstance().put(this.props.folderUid, values);
const url = Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid); const url = Module.getInstance()
.get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid);
this.props.router.push(url); this.props.router.push(url);
}catch(e){ } catch (e) {
console.error(e) console.error(e);
} }
} }
@ -112,5 +126,5 @@ export default function UpdateFolderMetadata(props: IProps) {
const router = useRouter(); const router = useRouter();
let { folderUid } = router.query; let { folderUid } = router.query;
folderUid = folderUid as string; folderUid = folderUid as string;
return <UpdateFolderMetadataClass folderUid={folderUid} router={router}/>; return <UpdateFolderMetadataClass folderUid={folderUid} router={router} />;
} }

View File

@ -1,56 +0,0 @@
@import "@Themes/constants.scss";
.root {
display: flex;
flex-direction: column;
min-height: 100%;
align-items: flex-start;
width: fit-content;
.back-arrow {
margin-bottom: 24px;
}
.form {
width: 100%;
.content {
margin-top: 32px;
>:not(:last-child) {
margin-bottom: 24px;
}
}
.button-container {
width: 100%;
display: flex;
text-align: center;
margin-top: 24px;
.cancel-button {
display: flex;
margin-right: 32px;
}
@media (max-width: $screen-m) {
display: flex;
flex-direction: column-reverse;
.cancel-button {
margin-left: 0;
margin-top: 12px;
>* {
flex: 1;
}
}
>* {
width: 100%;
}
}
}
}
}

View File

@ -1,67 +0,0 @@
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
import Form from "@Front/Components/DesignSystem/Form";
import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField";
import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
import BackArrow from "@Front/Components/Elements/BackArrow";
import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
import { useRouter } from "next/router";
import BasePage from "../../Base";
import classes from "./classes.module.scss";
import Link from "next/link";
import Module from "@Front/Config/Module";
type IProps = {
selectedFolderUid: string;
};
type IState = {
selectedFolder: IDashBoardFolder | null;
};
class UpdateFolderDescriptionClass extends BasePage<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = {
selectedFolder: null,
};
this.onSelectedFolder = this.onSelectedFolder.bind(this);
}
public override render(): JSX.Element {
const backwardPath = Module.getInstance()
.get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid);
return (
<DefaultNotaryDashboard title={"Ajouter client(s)"} onSelectedFolder={this.onSelectedFolder}>
<div className={classes["root"]}>
<div className={classes["back-arrow"]}>
<BackArrow url={backwardPath} />
</div>
<Typography typo={ITypo.H1Bis}>Modifier la note du dossier</Typography>
<Form className={classes["form"]}>
<div className={classes["content"]}>
<InputField name="input field" fakeplaceholder="Note du dossier" textarea />
</div>
<div className={classes["button-container"]}>
<Link href={backwardPath} className={classes["cancel-button"]}>
<Button variant={EButtonVariant.GHOST}>Annuler</Button>
</Link>
<Button type="submit">Enregistrer</Button>
</div>
</Form>
</div>
</DefaultNotaryDashboard>
);
}
private onSelectedFolder(folder: IDashBoardFolder): void {
this.setState({ selectedFolder: folder });
}
}
export default function UpdateFolderDescription() {
const router = useRouter();
let { folderUid } = router.query;
folderUid = folderUid as string;
return <UpdateFolderDescriptionClass selectedFolderUid={folderUid} />;
}