From b3007249df3dfc4aa45a1dd36855c20d673f5fef Mon Sep 17 00:00:00 2001 From: Matthias Nannt Date: Tue, 21 Feb 2023 14:14:21 +0100 Subject: [PATCH] fix delete customer on demo page --- apps/web/src/components/customers/DeleteCustomerModal.tsx | 7 ++++++- apps/web/src/lib/customers.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/customers/DeleteCustomerModal.tsx b/apps/web/src/components/customers/DeleteCustomerModal.tsx index aa7895e7c8..634c154bbe 100644 --- a/apps/web/src/components/customers/DeleteCustomerModal.tsx +++ b/apps/web/src/components/customers/DeleteCustomerModal.tsx @@ -28,7 +28,12 @@ export default function DeleteCustomerModal({ const deleteCustomerAction = async (e) => { setDeletingCustomer(true); e.preventDefault(); - await deleteCustomer(customerId, organisationId); + const res = await deleteCustomer(customerId, organisationId); + if (!res.ok) { + toast.error("Something went wrong while deleting the user."); + setOpen(false); + return; + } toast("User successfully deleted."); router.push(`/organisations/${organisationId}/customers`); }; diff --git a/apps/web/src/lib/customers.ts b/apps/web/src/lib/customers.ts index 4fd6768897..d39746ab2d 100644 --- a/apps/web/src/lib/customers.ts +++ b/apps/web/src/lib/customers.ts @@ -28,7 +28,7 @@ export const useCustomer = (organisationId: string, customerId: string) => { export const deleteCustomer = async (email: string, organisationId: string) => { try { - await fetch(`/api/organisations/${organisationId}/customers/${email}`, { + return await fetch(`/api/organisations/${organisationId}/customers/${email}`, { method: "DELETE", }); } catch (error) {