From 24aad9c278229d3a886d7ef8f9ef2976a7fe55d9 Mon Sep 17 00:00:00 2001 From: Tuval Simha Date: Sun, 18 Aug 2024 18:47:44 +0300 Subject: [PATCH] (2) Drop V2: Delete Collection Modal (#5312) --- .../laboratory/delete-collection-modal.tsx | 115 ++++++++++++------ .../delete-collection-modal.stories.tsx | 33 +++++ 2 files changed, 108 insertions(+), 40 deletions(-) create mode 100644 packages/web/app/src/stories/delete-collection-modal.stories.tsx diff --git a/packages/web/app/src/components/target/laboratory/delete-collection-modal.tsx b/packages/web/app/src/components/target/laboratory/delete-collection-modal.tsx index f731dca85..8d8a965b9 100644 --- a/packages/web/app/src/components/target/laboratory/delete-collection-modal.tsx +++ b/packages/web/app/src/components/target/laboratory/delete-collection-modal.tsx @@ -1,10 +1,15 @@ -import { ReactElement } from 'react'; import { useMutation } from 'urql'; import { Button } from '@/components/ui/button'; -import { Heading } from '@/components/ui/heading'; -import { Modal } from '@/components/v2'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { useToast } from '@/components/ui/use-toast'; import { graphql } from '@/gql'; -import { TrashIcon } from '@radix-ui/react-icons'; const DeleteCollectionMutation = graphql(` mutation DeleteCollection($selector: TargetSelectorInput!, $id: ID!) { @@ -39,45 +44,75 @@ export function DeleteCollectionModal(props: { organizationId: string; projectId: string; targetId: string; -}): ReactElement { +}) { + const { toast } = useToast(); const { isOpen, toggleModalOpen, collectionId } = props; const [, mutate] = useMutation(DeleteCollectionMutation); + const handleDelete = async () => { + const { error } = await mutate({ + id: collectionId, + selector: { + target: props.targetId, + organization: props.organizationId, + project: props.projectId, + }, + }); + toggleModalOpen(); + if (error) { + toast({ + title: 'Failed to delete collection', + description: error.message, + variant: 'destructive', + }); + } else { + toast({ + title: 'Collection deleted', + description: 'The collection has been successfully deleted', + variant: 'default', + }); + } + }; + return ( - - - Delete Collection -

- Are you sure you wish to delete this collection? This action is irreversible! -

-
- - -
-
+ + ); +} + +export function DeleteCollectionModalContent(props: { + isOpen: boolean; + toggleModalOpen: () => void; + handleDelete: () => void; +}) { + return ( + + + + Delete Collection + Are you sure you wish to delete this collection? + + This action is irreversible! + + + + + + + + ); } diff --git a/packages/web/app/src/stories/delete-collection-modal.stories.tsx b/packages/web/app/src/stories/delete-collection-modal.stories.tsx new file mode 100644 index 000000000..6958bebb9 --- /dev/null +++ b/packages/web/app/src/stories/delete-collection-modal.stories.tsx @@ -0,0 +1,33 @@ +import { DeleteCollectionModalContent } from '@/components/target/laboratory/delete-collection-modal'; +import { Meta, StoryFn, StoryObj } from '@storybook/react'; + +const meta: Meta = { + title: 'Modals/Delete Collection Modal', + component: DeleteCollectionModalContent, + argTypes: { + isOpen: { + control: 'boolean', + }, + toggleModalOpen: { + action: 'toggleModalOpen', + }, + handleDelete: { + action: 'onSubmit', + }, + }, +}; + +export default meta; + +type Story = StoryObj; + +const Template: StoryFn = args => { + return ; +}; + +export const Delete: Story = Template.bind({}); +Delete.args = { + isOpen: true, + toggleModalOpen: () => console.log('Close'), + handleDelete: () => console.log('Delete'), +};