✨ Delete client working
This commit is contained in:
parent
e77a7b262f
commit
0767d16491
@ -7,21 +7,15 @@ type IProps = {
|
||||
isOpen: boolean;
|
||||
onClose?: () => void;
|
||||
|
||||
onDeleteSuccess: (uid: string) => void;
|
||||
onDelete: (customerUid: string) => void;
|
||||
};
|
||||
|
||||
export default function DeleteCustomerModal(props: IProps) {
|
||||
const { isOpen, onClose, customerUid, onDeleteSuccess } = props;
|
||||
const { isOpen, onClose, onDelete } = props;
|
||||
|
||||
const onDelete = useCallback(
|
||||
() => onDeleteSuccess(customerUid),
|
||||
// Documents.getInstance()
|
||||
// .delete(documentUid)
|
||||
// .then(() => onDeleteSuccess(documentUid))
|
||||
// .then(onClose)
|
||||
// .catch((error) => console.warn(error)),
|
||||
[customerUid, onDeleteSuccess],
|
||||
);
|
||||
const handleDelete = useCallback(() => {
|
||||
onDelete(props.customerUid);
|
||||
}, [onDelete, props.customerUid]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
@ -29,7 +23,7 @@ export default function DeleteCustomerModal(props: IProps) {
|
||||
onClose={onClose}
|
||||
title={"Êtes-vous sûr de vouloir supprimer ce client du dossier ?"}
|
||||
firstButton={{ children: "Annuler", onClick: onClose }}
|
||||
secondButton={{ children: "Supprimer le client", onClick: onDelete }}>
|
||||
secondButton={{ children: "Supprimer le client", onClick: handleDelete }}>
|
||||
<Typography typo={ETypo.TEXT_MD_light}>
|
||||
Cette action retirera le client de ce dossier. Vous ne pourrez plus récupérer les informations associées à ce client dans ce
|
||||
dossier une fois supprimées.
|
||||
|
@ -10,11 +10,13 @@ import classes from "./classes.module.scss";
|
||||
import DeleteCustomerModal from "./DeleteCustomerModal";
|
||||
import Link from "next/link";
|
||||
import Module from "@Front/Config/Module";
|
||||
import { useCallback } from "react";
|
||||
|
||||
type IProps = {
|
||||
customer: ICustomer;
|
||||
anchorStatus: AnchorStatus;
|
||||
folderUid: string | undefined;
|
||||
onDelete: (customerUid: string) => void;
|
||||
};
|
||||
|
||||
export default function ClientBox(props: IProps) {
|
||||
@ -22,7 +24,12 @@ export default function ClientBox(props: IProps) {
|
||||
|
||||
const { isOpen, open, close } = useOpenable();
|
||||
|
||||
console.log("customer", customer);
|
||||
const handleDelete = useCallback(
|
||||
(customerUid: string) => {
|
||||
props.onDelete(customerUid);
|
||||
},
|
||||
[props],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={classes["root"]}>
|
||||
@ -76,7 +83,7 @@ export default function ClientBox(props: IProps) {
|
||||
onClick={open}>
|
||||
Supprimer le client
|
||||
</Button>
|
||||
<DeleteCustomerModal isOpen={isOpen} onClose={close} customerUid={customer.uid ?? ""} onDeleteSuccess={() => {}} />
|
||||
<DeleteCustomerModal isOpen={isOpen} onClose={close} customerUid={customer.uid ?? ""} onDelete={handleDelete} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
@ -2,7 +2,7 @@ import Tabs from "@Front/Components/Elements/Tabs";
|
||||
import Customer from "le-coffre-resources/dist/Customer";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
|
||||
import { AnchorStatus } from "..";
|
||||
import classes from "./classes.module.scss";
|
||||
@ -13,6 +13,7 @@ import Module from "@Front/Config/Module";
|
||||
import Link from "next/link";
|
||||
import NoDocument from "./NoDocument";
|
||||
import DocumentTables from "./DocumentTables";
|
||||
import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders";
|
||||
|
||||
type IProps = {
|
||||
folder: OfficeFolder;
|
||||
@ -47,6 +48,21 @@ export default function ClientView(props: IProps) {
|
||||
|
||||
const doesCustomerHaveDocument = useMemo(() => customer.documents && customer.documents.length > 0, [customer]);
|
||||
|
||||
const handleClientDelete = useCallback(
|
||||
(customerUid: string) => {
|
||||
if (!folder.uid) return;
|
||||
Folders.getInstance().put(
|
||||
folder.uid,
|
||||
OfficeFolder.hydrate<OfficeFolder>({
|
||||
...folder,
|
||||
customers: folder.customers?.filter((customer) => customer.uid !== customerUid),
|
||||
}),
|
||||
);
|
||||
window.location.reload();
|
||||
},
|
||||
[folder],
|
||||
);
|
||||
|
||||
return (
|
||||
<section className={classes["root"]}>
|
||||
<div className={classes["tab-container"]}>
|
||||
@ -68,7 +84,7 @@ export default function ClientView(props: IProps) {
|
||||
</div>
|
||||
<div className={classes["content"]}>
|
||||
<div className={classes["client-box"]}>
|
||||
<ClientBox customer={customer} anchorStatus={anchorStatus} folderUid={folder.uid} />
|
||||
<ClientBox customer={customer} anchorStatus={anchorStatus} folderUid={folder.uid} onDelete={handleClientDelete} />
|
||||
{anchorStatus === AnchorStatus.NOT_ANCHORED && (
|
||||
<Link
|
||||
href={Module.getInstance()
|
||||
|
Loading…
x
Reference in New Issue
Block a user