Merge branch 'dev' into staging

This commit is contained in:
Maxime Lalo 2024-07-29 13:52:23 +02:00
commit 9ef6224049
4 changed files with 222 additions and 239 deletions

View File

@ -11,11 +11,18 @@ type IProps = {
}; };
export default function Footer({ className, hasLeftPadding = false, isSticky = false }: IProps) { export default function Footer({ className, hasLeftPadding = false, isSticky = false }: IProps) {
const footerRef = React.useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
document.documentElement.style.setProperty("--footer-height", `43px`); if (!footerRef.current) return;
const footerHeight = footerRef.current.clientHeight + 1;
document.documentElement.style.setProperty("--footer-height", `${footerHeight}px`);
}); });
return ( return (
<footer className={[classes["root"], className].join(" ")} data-has-left-padding={hasLeftPadding} data-is-sticky={isSticky}> <footer
className={[classes["root"], className].join(" ")}
data-has-left-padding={hasLeftPadding}
data-is-sticky={isSticky}
ref={footerRef}>
<Mobile className={classes["mobile"]} /> <Mobile className={classes["mobile"]} />
<Tablet className={classes["tablet"]} /> <Tablet className={classes["tablet"]} />
<Desktop className={classes["desktop"]} /> <Desktop className={classes["desktop"]} />

View File

@ -5,7 +5,7 @@
.content { .content {
display: flex; display: flex;
.sides { .sides {
min-height: calc(100vh - var(--header-height)); min-height: calc(100vh - var(--header-height) - var(--footer-height));
width: 50%; width: 50%;
@media (max-width: $screen-m) { @media (max-width: $screen-m) {
width: 100%; width: 100%;

View File

@ -3,10 +3,10 @@
.root { .root {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: 100%;
align-items: flex-start; align-items: flex-start;
width: fit-content; width: 472px;
margin: auto;
margin-top: 24px;
.back-arrow { .back-arrow {
margin-bottom: 24px; margin-bottom: 24px;
} }
@ -22,7 +22,6 @@
.form { .form {
width: 100%; width: 100%;
.button-container { .button-container {
width: 100%; width: 100%;
display: flex; display: flex;
@ -42,12 +41,12 @@
margin-left: 0; margin-left: 0;
margin-top: 12px; margin-top: 12px;
>* { > * {
flex: 1; flex: 1;
} }
} }
>* { > * {
width: 100%; width: 100%;
} }
} }

View File

@ -8,153 +8,127 @@ import TextField from "@Front/Components/DesignSystem/Form/TextField";
import RadioBox from "@Front/Components/DesignSystem/RadioBox"; import RadioBox from "@Front/Components/DesignSystem/RadioBox";
import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography";
import BackArrow from "@Front/Components/Elements/BackArrow"; import BackArrow from "@Front/Components/Elements/BackArrow";
import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
import Module from "@Front/Config/Module"; import Module from "@Front/Config/Module";
import { ValidationError } from "class-validator"; import { ValidationError } from "class-validator";
import { ECivility } from "le-coffre-resources/dist/Customer/Contact"; import { ECivility } from "le-coffre-resources/dist/Customer/Contact";
import { Contact, Customer, OfficeFolder } from "le-coffre-resources/dist/Notary"; import { Contact, Customer, OfficeFolder } from "le-coffre-resources/dist/Notary";
import Link from "next/link"; import Link from "next/link";
import { NextRouter, useRouter } from "next/router"; import { useRouter } from "next/router";
import backgroundImage from "@Assets/images/background_refonte.svg";
import BasePage from "../../Base";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import { useCallback, useEffect, useState } from "react";
import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage";
enum ESelectedOption { enum ESelectedOption {
EXISTING_CUSTOMER = "existing_customer", EXISTING_CUSTOMER = "existing_customer",
NEW_CUSTOMER = "new_customer", NEW_CUSTOMER = "new_customer",
} }
type IProps = {}; type IProps = {};
type IState = {
selectedOption: ESelectedOption;
availableCustomers: Customer[];
selectedCustomers: IOption[];
existingCustomers: IOption[];
isLoaded: boolean;
validationError: ValidationError[];
};
type IPropsClass = IProps & { export default function AddClientToFolder(props: IProps) {
selectedFolderUid: string; const router = useRouter();
router: NextRouter; let { folderUid } = router.query;
};
class AddClientToFolderClass extends BasePage<IPropsClass, IState> {
constructor(props: IPropsClass) {
super(props);
this.state = {
selectedOption: ESelectedOption.EXISTING_CUSTOMER,
availableCustomers: [],
selectedCustomers: [],
existingCustomers: [],
isLoaded: false,
validationError: [],
};
this.onExistingClientSelected = this.onExistingClientSelected.bind(this);
this.onNewClientSelected = this.onNewClientSelected.bind(this);
this.onMutiSelectChange = this.onMutiSelectChange.bind(this);
this.onFormSubmit = this.onFormSubmit.bind(this);
}
public override render(): JSX.Element {
const selectOptions: IOption[] = this.getSelectedOptions();
const backwardPath = Module.getInstance() const [selectedOption, setSelectedOption] = useState<ESelectedOption>(ESelectedOption.EXISTING_CUSTOMER);
.get() const [availableCustomers, setAvailableCustomers] = useState<Customer[]>([]);
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid); const [selectedCustomers, setSelectedCustomers] = useState<IOption[]>([]);
return ( const [existingCustomers, setExistingCustomers] = useState<IOption[]>([]);
<DefaultNotaryDashboard title={"Ajouter client(s)"}> const [isLoaded, setIsLoaded] = useState<boolean>(false);
<div className={classes["root"]}> const [validationError, setValidationError] = useState<ValidationError[]>([]);
<div className={classes["back-arrow"]}>
<BackArrow url={backwardPath} />
</div>
<Typography typo={ETypo.TITLE_H1}>Associer un ou plusieurs client(s)</Typography>
{this.state.isLoaded && (
<>
<div className={classes["radiobox-container"]}>
{this.state.availableCustomers.length !== 0 && (
<RadioBox
name="client"
onChange={this.onExistingClientSelected}
checked={this.state.selectedOption === "existing_customer"}
value={"existing client"}>
<Typography typo={ETypo.TEXT_LG_REGULAR}>Client existant</Typography>
</RadioBox>
)}
<RadioBox const onFormSubmit = useCallback(
name="client" async (
onChange={this.onNewClientSelected} e: React.FormEvent<HTMLFormElement> | null,
checked={this.state.selectedOption === "new_customer"} values: {
value={"new client"}> [key: string]: any;
<Typography typo={ETypo.TEXT_LG_REGULAR}>Nouveau client</Typography> },
</RadioBox> ) => {
</div> values["civility"] = ECivility.MALE; // TODO: should maybe be deleted later or added to the form
<Form className={classes["form"]} onSubmit={this.onFormSubmit}> const allCustomersToLink = selectedCustomers.concat(existingCustomers);
{this.state.selectedOption === "existing_customer" && ( let customersToLink: Partial<Customer>[] = allCustomersToLink.map((customer) => {
<div className={classes["existing-client"]}> return Customer.hydrate<Customer>({ uid: customer.id as string });
<AutocompleteMultiSelect }) as Partial<Customer>[];
label="Clients"
options={selectOptions}
selectedOptions={this.state.selectedCustomers}
onSelectionChange={this.onMutiSelectChange}
/>
<div className={classes["button-container"]}> if (selectedOption === "new_customer") {
<Link href={backwardPath} className={classes["cancel-button"]}> try {
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}> // remove every space from the phone number
Annuler values["cell_phone_number"] = values["cell_phone_number"].replace(/\s/g, "");
</Button> values["cell_phone_number"] = values["cell_phone_number"].replace(/\./g, "");
</Link> if (values["cell_phone_number"] && values["cell_phone_number"].length === 10) {
<Button type="submit">Associer au dossier</Button> // get the first digit of the phone number
</div> const firstDigit = values["cell_phone_number"].charAt(0);
</div> // if the first digit is a 0 replace it by +33
)} if (firstDigit === "0") {
values["cell_phone_number"] = "+33" + values["cell_phone_number"].substring(1);
}
}
const contactToCreate = Contact.hydrate<Customer>(values);
await contactToCreate.validateOrReject?.({ groups: ["createCustomer"], forbidUnknownValues: false });
} catch (validationErrors) {
setValidationError(validationErrors as ValidationError[]);
return;
}
{this.state.selectedOption === "new_customer" && ( try {
<div className={classes["new-client"]}> const customer: Customer = await Customers.getInstance().post({
<TextField contact: values,
name="last_name" });
placeholder="Nom" if (!customer.uid) return;
validationError={this.state.validationError.find((error) => error.property === "last_name")} customersToLink?.push({ uid: customer.uid } as Partial<Customer>);
/> } catch (backError) {
<TextField if (!Array.isArray(backError)) return;
name="first_name" setValidationError(backError as ValidationError[]);
placeholder="Prénom" return;
validationError={this.state.validationError.find((error) => error.property === "first_name")} }
/> }
<TextField
name="email"
placeholder="E-mail"
validationError={this.state.validationError.find((error) => error.property === "email")}
/>
<TextField
name="cell_phone_number"
placeholder="Numéro de téléphone"
validationError={this.state.validationError.find(
(error) => error.property === "cell_phone_number",
)}
/>
<div className={classes["button-container"]}>
<Link href={backwardPath} className={classes["cancel-button"]}>
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}>
Annuler
</Button>
</Link>
<Button type="submit">Associer au dossier</Button>
</div>
</div>
)}
</Form>
</>
)}
</div>
</DefaultNotaryDashboard>
);
}
public override async componentDidMount() { if (customersToLink) {
const body = OfficeFolder.hydrate<OfficeFolder>({
customers: customersToLink.map((customer) => {
return Customer.hydrate<Customer>(customer);
}),
});
await Folders.getInstance().put(folderUid as string, body);
router.push(`/folders/${folderUid}`);
}
},
[existingCustomers, folderUid, router, selectedCustomers, selectedOption],
);
const getFolderPreSelectedCustomers = useCallback(
async (folderUid: string): Promise<IOption[] | undefined> => {
const query = {
q: {
customers: {
include: {
contact: true,
},
},
},
};
let preExistingCustomers: IOption[] = [];
try {
const folder = await Folders.getInstance().getByUid(folderUid, query);
preExistingCustomers = folder.customers!.map((customer) => {
return {
label: customer.contact?.first_name + " " + customer.contact?.last_name,
id: customer.uid ?? "",
};
});
} catch (error) {
router.push(Module.getInstance().get().modules.pages["404"].props.path);
return;
}
return preExistingCustomers;
},
[router],
);
const loadCustomers = useCallback(async () => {
const query = {}; const query = {};
const availableCustomers = await Customers.getInstance().get(query); const availableCustomers = await Customers.getInstance().get(query);
let preExistingCustomers: IOption[] | undefined = await this.getFolderPreSelectedCustomers(this.props.selectedFolderUid); let preExistingCustomers: IOption[] | undefined = await getFolderPreSelectedCustomers(folderUid as string);
const existingCustomers = preExistingCustomers ?? []; const existingCustomers = preExistingCustomers ?? [];
existingCustomers.forEach((customer) => { existingCustomers.forEach((customer) => {
@ -167,37 +141,14 @@ class AddClientToFolderClass extends BasePage<IPropsClass, IState> {
selectedOption = ESelectedOption.NEW_CUSTOMER; selectedOption = ESelectedOption.NEW_CUSTOMER;
} }
this.setState({ availableCustomers, existingCustomers, isLoaded: true, selectedOption }); setAvailableCustomers(availableCustomers);
} setExistingCustomers(existingCustomers);
setIsLoaded(true);
setSelectedOption(selectedOption);
}, [folderUid, getFolderPreSelectedCustomers]);
private async getFolderPreSelectedCustomers(folderUid: string): Promise<IOption[] | undefined> { const getSelectedOptions = useCallback((): IOption[] => {
const query = { let options = availableCustomers?.map((customer) => {
q: {
customers: {
include: {
contact: true,
},
},
},
};
let preExistingCustomers: IOption[] = [];
try {
const folder = await Folders.getInstance().getByUid(folderUid, query);
preExistingCustomers = folder.customers!.map((customer) => {
return {
label: customer.contact?.first_name + " " + customer.contact?.last_name,
id: customer.uid ?? "",
};
});
} catch (error) {
this.props.router.push(Module.getInstance().get().modules.pages["404"].props.path);
return;
}
return preExistingCustomers;
}
private getSelectedOptions(): IOption[] {
let options = this.state.availableCustomers?.map((customer) => {
return { return {
label: customer.contact?.first_name + " " + customer.contact?.last_name, label: customer.contact?.first_name + " " + customer.contact?.last_name,
id: customer.uid ?? "", id: customer.uid ?? "",
@ -205,85 +156,111 @@ class AddClientToFolderClass extends BasePage<IPropsClass, IState> {
}); });
if (!options) options = []; if (!options) options = [];
return options; return options;
} }, [availableCustomers]);
private onMutiSelectChange(selectedCustomers: IOption[] | null): void { const onMutiSelectChange = (selectedCustomers: IOption[] | null): void => {
selectedCustomers && this.setState({ selectedCustomers }); if (!selectedCustomers) return;
} setSelectedCustomers(selectedCustomers);
};
private onExistingClientSelected(): void { const onExistingClientSelected = (): void => setSelectedOption(ESelectedOption.EXISTING_CUSTOMER);
this.setState({ selectedOption: ESelectedOption.EXISTING_CUSTOMER }); const onNewClientSelected = (): void => setSelectedOption(ESelectedOption.NEW_CUSTOMER);
}
private onNewClientSelected(): void { useEffect(() => {
this.setState({ selectedOption: ESelectedOption.NEW_CUSTOMER }); loadCustomers();
} }, [loadCustomers]);
private async onFormSubmit( const selectOptions: IOption[] = getSelectedOptions();
e: React.FormEvent<HTMLFormElement> | null,
values: {
[key: string]: any;
},
) {
values["civility"] = ECivility.MALE; // TODO: should maybe be deleted later or added to the form
const allCustomersToLink = this.state.selectedCustomers.concat(this.state.existingCustomers); const backwardPath = Module.getInstance()
let customersToLink: Partial<Customer>[] = allCustomersToLink.map((customer) => { .get()
return Customer.hydrate<Customer>({ uid: customer.id as string }); .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid as string);
}) as Partial<Customer>[]; return (
<DefaultDoubleSidePage title={"Ajouter client(s)"} image={backgroundImage} showHeader>
<div className={classes["root"]}>
<div className={classes["back-arrow"]}>
<BackArrow url={backwardPath} />
</div>
<Typography typo={ETypo.TITLE_H1}>Associer un ou plusieurs client(s)</Typography>
{isLoaded && (
<>
<div className={classes["radiobox-container"]}>
{availableCustomers.length !== 0 && (
<RadioBox
name="client"
onChange={onExistingClientSelected}
checked={selectedOption === "existing_customer"}
value={"existing client"}>
<Typography typo={ETypo.TEXT_LG_REGULAR}>Client existant</Typography>
</RadioBox>
)}
if (this.state.selectedOption === "new_customer") { <RadioBox
try { name="client"
// remove every space from the phone number onChange={onNewClientSelected}
values["cell_phone_number"] = values["cell_phone_number"].replace(/\s/g, ""); checked={selectedOption === "new_customer"}
values["cell_phone_number"] = values["cell_phone_number"].replace(/\./g, ""); value={"new client"}>
if (values["cell_phone_number"] && values["cell_phone_number"].length === 10) { <Typography typo={ETypo.TEXT_LG_REGULAR}>Nouveau client</Typography>
// get the first digit of the phone number </RadioBox>
const firstDigit = values["cell_phone_number"].charAt(0); </div>
// if the first digit is a 0 replace it by +33
if (firstDigit === "0") {
values["cell_phone_number"] = "+33" + values["cell_phone_number"].substring(1);
}
}
const contactToCreate = Contact.hydrate<Customer>(values);
await contactToCreate.validateOrReject?.({ groups: ["createCustomer"], forbidUnknownValues: false });
} catch (validationErrors) {
this.setState({
validationError: validationErrors as ValidationError[],
});
return;
}
try { <Form className={classes["form"]} onSubmit={onFormSubmit}>
const customer: Customer = await Customers.getInstance().post({ {selectedOption === "existing_customer" && (
contact: values, <div className={classes["existing-client"]}>
}); <AutocompleteMultiSelect
if (!customer.uid) return; label="Clients"
customersToLink?.push({ uid: customer.uid } as Partial<Customer>); options={selectOptions}
} catch (backError) { selectedOptions={selectedCustomers}
if (!Array.isArray(backError)) return; onSelectionChange={onMutiSelectChange}
this.setState({ />
validationError: backError as ValidationError[],
});
return;
}
}
if (customersToLink) { <div className={classes["button-container"]}>
const body = OfficeFolder.hydrate<OfficeFolder>({ <Link href={backwardPath} className={classes["cancel-button"]}>
customers: customersToLink.map((customer) => { <Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}>
return Customer.hydrate<Customer>(customer); Annuler
}), </Button>
}); </Link>
await Folders.getInstance().put(this.props.selectedFolderUid, body); <Button type="submit">Associer au dossier</Button>
this.props.router.push(`/folders/${this.props.selectedFolderUid}`); </div>
} </div>
} )}
}
{selectedOption === "new_customer" && (
export default function AddClientToFolder(props: IProps) { <div className={classes["new-client"]}>
const router = useRouter(); <TextField
let { folderUid } = router.query; name="last_name"
folderUid = folderUid as string; placeholder="Nom"
return <AddClientToFolderClass {...props} selectedFolderUid={folderUid} router={router} />; validationError={validationError.find((error) => error.property === "last_name")}
/>
<TextField
name="first_name"
placeholder="Prénom"
validationError={validationError.find((error) => error.property === "first_name")}
/>
<TextField
name="email"
placeholder="E-mail"
validationError={validationError.find((error) => error.property === "email")}
/>
<TextField
name="cell_phone_number"
placeholder="Numéro de téléphone"
validationError={validationError.find((error) => error.property === "cell_phone_number")}
/>
<div className={classes["button-container"]}>
<Link href={backwardPath} className={classes["cancel-button"]}>
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}>
Annuler
</Button>
</Link>
<Button type="submit">Associer au dossier</Button>
</div>
</div>
)}
</Form>
</>
)}
</div>
</DefaultDoubleSidePage>
);
} }