Modal alert delete client with documents
This commit is contained in:
parent
97adfe3991
commit
bf054d4140
@ -11,6 +11,7 @@ import Module from "@Front/Config/Module";
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import { Note } from "le-coffre-resources/dist/Customer";
|
import { Note } from "le-coffre-resources/dist/Customer";
|
||||||
import ButtonWithSubMenu from "@Front/Components/Elements/ButtonWithSubMenu";
|
import ButtonWithSubMenu from "@Front/Components/Elements/ButtonWithSubMenu";
|
||||||
|
import Modal from "@Front/Components/DesignSystem/Modal";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
customer: ICustomer;
|
customer: ICustomer;
|
||||||
@ -23,10 +24,16 @@ type IProps = {
|
|||||||
export default function ClientBox(props: IProps) {
|
export default function ClientBox(props: IProps) {
|
||||||
const { customer, anchorStatus, folderUid, customerNote } = props;
|
const { customer, anchorStatus, folderUid, customerNote } = props;
|
||||||
|
|
||||||
const { isOpen, open, close } = useOpenable();
|
const { isOpen: isDeleteModalOpen, open: openDeleteModal, close: closeDeleteModal } = useOpenable();
|
||||||
|
const { isOpen: isErrorModalOpen, open: openErrorModal, close: closeErrorModal } = useOpenable();
|
||||||
|
|
||||||
const handleDelete = useCallback(
|
const handleDelete = useCallback(
|
||||||
(customerUid: string) => {
|
(customerUid: string) => {
|
||||||
|
if (customer.documents && customer.documents.length > 0) {
|
||||||
|
closeDeleteModal();
|
||||||
|
openErrorModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
props.onDelete(customerUid);
|
props.onDelete(customerUid);
|
||||||
},
|
},
|
||||||
[props],
|
[props],
|
||||||
@ -108,12 +115,27 @@ export default function ClientBox(props: IProps) {
|
|||||||
variant={EButtonVariant.ERROR}
|
variant={EButtonVariant.ERROR}
|
||||||
styletype={EButtonstyletype.TEXT}
|
styletype={EButtonstyletype.TEXT}
|
||||||
rightIcon={<TrashIcon />}
|
rightIcon={<TrashIcon />}
|
||||||
onClick={open}>
|
onClick={openDeleteModal}>
|
||||||
Supprimer le client
|
Supprimer le client
|
||||||
</Button>
|
</Button>
|
||||||
<DeleteCustomerModal isOpen={isOpen} onClose={close} customerUid={customer.uid ?? ""} onDelete={handleDelete} />
|
<DeleteCustomerModal
|
||||||
|
isOpen={isDeleteModalOpen}
|
||||||
|
onClose={close}
|
||||||
|
customerUid={customer.uid ?? ""}
|
||||||
|
onDelete={handleDelete}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<Modal
|
||||||
|
isOpen={isErrorModalOpen}
|
||||||
|
onClose={closeErrorModal}
|
||||||
|
title={"Suppression impossible"}
|
||||||
|
secondButton={{ children: "Fermer", onClick: closeErrorModal, fullwidth: true }}>
|
||||||
|
<Typography typo={ETypo.TEXT_MD_light}>
|
||||||
|
Ce client ne peut pas être supprimé car des documents sont associés à son dossier. Veuillez d'abord gérer ou supprimer
|
||||||
|
ces documents avant de tenter de supprimer le client.
|
||||||
|
</Typography>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user