diff --git a/components/inputs/ButtonWithConfirm.tsx b/components/inputs/ButtonWithConfirm.tsx new file mode 100644 index 0000000..f56f2c7 --- /dev/null +++ b/components/inputs/ButtonWithConfirm.tsx @@ -0,0 +1,50 @@ +import { cn } from "@/lib/utils"; +import { ComponentProps, MouseEventHandler, useEffect, useState } from "react"; +import { Button } from "../ui/button"; + +interface ButtonWithConfirmProps extends Omit, "children"> { + readonly text: string; + readonly confirmText: string; + readonly onClick: MouseEventHandler; +} + +export default function ButtonWithConfirm({ + text, + confirmText, + onClick, + ...restProps +}: ButtonWithConfirmProps) { + const [toConfirm, setToConfirm] = useState(false); + + useEffect(() => { + if (!toConfirm) { + return; + } + + const timeout = setTimeout(() => { + setToConfirm(false); + }, 3000); + + return () => { + clearTimeout(timeout); + }; + }, [toConfirm]); + + return ( + + ); +}