-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
136de34
commit e90075b
Showing
17 changed files
with
538 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useState, cloneElement, ReactElement } from "react"; | ||
import { Dialog, DialogContent, DialogTrigger, DialogHeader, DialogTitle, DialogDescription, Button, DialogFooter } from "../ui"; | ||
|
||
type DoubleConfirmationDialogProps = { | ||
title?: string; | ||
message?: string; | ||
children: ReactElement; | ||
}; | ||
|
||
export const DoubleConfirmationDialog = ({ | ||
title = "Are you sure?", | ||
message = "This action cannot be undone.", | ||
children, | ||
}: DoubleConfirmationDialogProps) => { | ||
const [isOpen, setOpen] = useState(false); | ||
const [onConfirm, setOnConfirm] = useState<(() => void) | null>(null); | ||
|
||
const handleClick = (event: React.MouseEvent) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
if (children.props.onClick) { | ||
setOnConfirm(() => children.props.onClick); | ||
} | ||
|
||
setOpen(true); | ||
}; | ||
|
||
const handleConfirm = () => { | ||
if (onConfirm) onConfirm(); | ||
setOpen(false); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={setOpen}> | ||
<DialogTrigger asChild> | ||
{cloneElement(children, { onClick: handleClick })} | ||
</DialogTrigger> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>{title}</DialogTitle> | ||
<DialogDescription> | ||
{message} | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<div className="flex flex-row gap-4 justify-between"> | ||
<Button variant="ghost" onClick={handleCancel}> | ||
Cancel | ||
</Button> | ||
<Button variant="destructive" onClick={handleConfirm}> | ||
Confirm | ||
</Button> | ||
</div> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.