From d29aed92eb6ccd03fec88e0ff1adde4440fd97d4 Mon Sep 17 00:00:00 2001 From: aruay99 Date: Fri, 24 Nov 2023 19:08:00 +0600 Subject: [PATCH 1/2] feat: separate DeleteAll into separate component --- .../products/components/DeleteAllProducts.tsx | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/features/products/components/DeleteAllProducts.tsx diff --git a/src/features/products/components/DeleteAllProducts.tsx b/src/features/products/components/DeleteAllProducts.tsx new file mode 100644 index 00000000..36148bdf --- /dev/null +++ b/src/features/products/components/DeleteAllProducts.tsx @@ -0,0 +1,55 @@ +import React from 'react'; +import { Button, Dialog } from '~/components'; +import { Icons } from '~/lib/phosphor'; + +const DeleteAllProducts = ({ onClick, disabled, n, onConfirm }) => { + const openDialog = () => onClick(true); + + const nString = `${n} product${n === 1 ? '' : 's'}`; + + return ( + <> + + onClick(false)} + title={`Delete ${nString}`} + actions={[ + , + , + ]} + > + You are about to delete {nString}. +
+
+ This action cannot be undone. +
+ + ); +}; + +export default DeleteAllProducts; From 0869d9e5f546d54c0334116203074dae79ee4a74 Mon Sep 17 00:00:00 2001 From: aruay99 Date: Fri, 24 Nov 2023 19:40:49 +0600 Subject: [PATCH 2/2] fix: fix the bug --- .../products/components/DeleteAllProducts.tsx | 32 +++++++++----- src/features/products/routes/Products.tsx | 44 ++----------------- 2 files changed, 25 insertions(+), 51 deletions(-) diff --git a/src/features/products/components/DeleteAllProducts.tsx b/src/features/products/components/DeleteAllProducts.tsx index 36148bdf..14d3682f 100644 --- a/src/features/products/components/DeleteAllProducts.tsx +++ b/src/features/products/components/DeleteAllProducts.tsx @@ -1,9 +1,22 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Button, Dialog } from '~/components'; import { Icons } from '~/lib/phosphor'; -const DeleteAllProducts = ({ onClick, disabled, n, onConfirm }) => { - const openDialog = () => onClick(true); +interface DeleteAllProductsProps { + disabled: boolean; + n: number; + onConfirm: () => void; +} + +const DeleteAllProducts: React.FC = ({ + disabled, + n, + onConfirm, +}) => { + const [isDialogOpen, setIsDialogOpen] = useState(false); + + const openDialog = () => setIsDialogOpen(true); + const closeDialog = () => setIsDialogOpen(false); const nString = `${n} product${n === 1 ? '' : 's'}`; @@ -14,28 +27,25 @@ const DeleteAllProducts = ({ onClick, disabled, n, onConfirm }) => { disabled={disabled} color="danger" variant="primary" + // icon size should match the size specified here icon={} > Delete All onClick(false)} + open={isDialogOpen} + onClose={closeDialog} title={`Delete ${nString}`} actions={[ - , - setIsDialogOpen(false)} - title={`Delete ${nString}`} - actions={[ - , - , - ]} - > - You are about to delete {nString}. -
-
- This action cannot be undone. -
+ {/* TODO: add tooltip? Not sure if we need it. Find examples of this*/} + {/*// size="md" TODO: match the size of the icon to the size specified here. */} + mutate()} />