Skip to content

Commit

Permalink
Differentiate between cancel and confirm alert for delete issue popov…
Browse files Browse the repository at this point in the history
…er (#87)
  • Loading branch information
maximilianruesch authored Dec 7, 2023
1 parent 5b2c6c4 commit 0f49163
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/components/BacklogView/Issue/DeleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export function DeleteButton({
}} />
<DeleteIssueAlert
issueKey={issueKey}
closeModal={() => setIssuePopoverOpened(false)}
cancelAlert={() => setIssuePopoverOpened(false)}
confirmAlert={() => setIssuePopoverOpened(false)}
/>
</Popover.Dropdown>
</Popover>
Expand Down
23 changes: 20 additions & 3 deletions src/components/DetailView/Components/DeleteIssue/DeleteIssue.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Popover } from "@mantine/core"
import { IconTrash } from "@tabler/icons"
import {useState} from "react";
import { DeleteIssueAlert } from "./DeleteIssueAlert"

export function DeleteIssue({
Expand All @@ -9,10 +10,22 @@ export function DeleteIssue({
issueKey: string
closeModal: () => void
}) {
const [issuePopoverOpened, setIssuePopoverOpened] = useState(false)

return (
<Popover width="40vh" trapFocus position="bottom" withArrow shadow="md">
<Popover
width="40vh"
trapFocus
position="bottom"
withArrow
shadow="md"
opened={issuePopoverOpened}
>
<Popover.Target>
<Button color="red" rightIcon={<IconTrash size={16} />}>
<Button color="red" rightIcon={<IconTrash size={16} />} onClick={(e) => {
e.stopPropagation()
setIssuePopoverOpened(!issuePopoverOpened)
}}>
Delete
</Button>
</Popover.Target>
Expand All @@ -22,7 +35,11 @@ export function DeleteIssue({
theme.colorScheme === "dark" ? theme.colors.dark[7] : theme.white,
})}
>
<DeleteIssueAlert issueKey={issueKey} closeModal={closeModal} />
<DeleteIssueAlert
issueKey={issueKey}
cancelAlert={() => setIssuePopoverOpened(false)}
confirmAlert={closeModal}
/>
</Popover.Dropdown>
</Popover>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { deleteIssueMutation } from "./queries"

export function DeleteIssueAlert({
issueKey,
closeModal,
cancelAlert,
confirmAlert,
}: {
issueKey: string
closeModal: () => void
cancelAlert: () => void
confirmAlert: () => void
}) {
const queryClient = useQueryClient()
const deleteIssue = deleteIssueMutation(queryClient)

return (
<Stack onMouseLeave={closeModal}>
<Stack onMouseLeave={cancelAlert}>
<Alert
icon={<IconAlertCircle size={16} />}
title="Attention!"
Expand All @@ -26,7 +28,7 @@ export function DeleteIssueAlert({
onClick={(e) => {
e.stopPropagation()
deleteIssue.mutate(issueKey)
closeModal()
confirmAlert()
}}
>
Confirm
Expand Down

0 comments on commit 0f49163

Please sign in to comment.