diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index a2df8dce..4e465a80 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -35,6 +35,8 @@ const buttonVariants = cva( } ) +export type ButtonVariantsProps = VariantProps; + function Button({ className, variant, diff --git a/src/components/wrappers/common/button/button-with-confirm.tsx b/src/components/wrappers/common/button/button-with-confirm.tsx index 92ff3bc0..aa0a3d40 100644 --- a/src/components/wrappers/common/button/button-with-confirm.tsx +++ b/src/components/wrappers/common/button/button-with-confirm.tsx @@ -1,45 +1,161 @@ -"use client"; - -import { Button } from "@/components/ui/button"; -import { useState } from "react"; -import { Loader2 } from "lucide-react"; - -export type VariantButton = { - secondary: string; - default: string; - outline: string; - ghost: string; - link: string; - destructive: string; -}; +// "use client"; +// +// import { Button } from "@/components/ui/button"; +// import { useState } from "react"; +// import { Loader2 } from "lucide-react"; +// +// export type VariantButton = { +// secondary: string; +// default: string; +// outline: string; +// ghost: string; +// link: string; +// destructive: string; +// }; +// +// export type ButtonWithConfirmProps = { +// icon?: any; +// text: string; +// variant?: keyof VariantButton; +// className?: string; +// onClick?: () => void; +// isPending?: boolean; +// }; +// +// export const ButtonWithConfirm = (props: ButtonWithConfirmProps) => { +// const [isConfirming, setIsConfirming] = useState(false); +// +// return ( +// +// ); +// }; +"use client" +import {Button, ButtonVariantsProps} from "@/components/ui/button"; +import {useState} from "react"; +import {Loader2} from "lucide-react"; +import {Popover, PopoverContent, PopoverTrigger} from "@/components/ui/popover"; +import {cn} from "@/lib/utils"; +import {Tooltip, TooltipContent, TooltipTrigger} from "@/components/ui/tooltip"; export type ButtonWithConfirmProps = { - icon?: any; - text: string; - variant?: keyof VariantButton; - className?: string; - onClick?: () => void; + title: string; + description: string; + button: { + main: { + className?: string; + text?: string; + icon?: any; + variant?: ButtonVariantsProps["variant"]; + size?: ButtonVariantsProps["size"]; + disabled?: boolean; + tooltipText?: string; + }; + confirm: { + className?: string; + text: string; + icon?: any; + variant?: ButtonVariantsProps["variant"]; + size?: ButtonVariantsProps["size"]; + onClick?: () => void; + }; + cancel: { + className?: string; + text: string; + icon?: any; + variant?: ButtonVariantsProps["variant"]; + size?: ButtonVariantsProps["size"]; + onClick?: () => void; + }; + }; isPending?: boolean; }; + export const ButtonWithConfirm = (props: ButtonWithConfirmProps) => { const [isConfirming, setIsConfirming] = useState(false); return ( - + + + + + + + + + + {props.button.main.tooltipText && props.button.main.disabled && ( + +

{props.button.main.tooltipText}

+
+ )} +
+ +
+
+

{props.title}

+

{props.description}

+
+
+ + +
+
+
+
); }; + diff --git a/src/components/wrappers/dashboard/agent/button-delete-agent/button-delete-agent.tsx b/src/components/wrappers/dashboard/agent/button-delete-agent/button-delete-agent.tsx index 4d0d27c3..c7788bb3 100644 --- a/src/components/wrappers/dashboard/agent/button-delete-agent/button-delete-agent.tsx +++ b/src/components/wrappers/dashboard/agent/button-delete-agent/button-delete-agent.tsx @@ -1,10 +1,10 @@ "use client"; -import { Trash2 } from "lucide-react"; -import { ButtonWithConfirm } from "@/components/wrappers/common/button/button-with-confirm"; -import { useMutation } from "@tanstack/react-query"; -import { useRouter } from "next/navigation"; -import { toast } from "sonner"; +import {Trash2} from "lucide-react"; +import {ButtonWithConfirm} from "@/components/wrappers/common/button/button-with-confirm"; +import {useMutation} from "@tanstack/react-query"; +import {useRouter} from "next/navigation"; +import {toast} from "sonner"; import {deleteAgentAction} from "@/components/wrappers/dashboard/agent/button-delete-agent/delete-agent.action"; export type ButtonDeleteAgentProps = { @@ -29,14 +29,31 @@ export const ButtonDeleteAgent = (props: ButtonDeleteAgentProps) => { return ( { - mutation.mutate(); + title={props.text ? props.text : ""} + description="Are you sure you want to remove this agent? This action cannot be undone." + button={{ + main: { + text: props.text ? props.text : "", + variant: "outline", + icon: , + }, + confirm: { + className: "w-full", + text: "Delete", + icon: , + variant: "destructive", + onClick: () => { + mutation.mutate(); + }, + }, + cancel: { + className: "w-full", + text: "Cancel", + icon: , + variant: "outline", + }, }} - variant={"destructive"} isPending={mutation.isPending} - className="gap-2" - icon={} /> ); }; diff --git a/src/components/wrappers/dashboard/organization/delete-organization/delete-organization-button.tsx b/src/components/wrappers/dashboard/organization/delete-organization/delete-organization-button.tsx index 63edd168..1fde25c1 100644 --- a/src/components/wrappers/dashboard/organization/delete-organization/delete-organization-button.tsx +++ b/src/components/wrappers/dashboard/organization/delete-organization/delete-organization-button.tsx @@ -1,11 +1,12 @@ "use client"; -import { ButtonWithConfirm } from "@/components/wrappers/common/button/button-with-confirm"; -import { deleteOrganizationAction } from "@/components/wrappers/dashboard/organization/organization.action"; -import { useMutation } from "@tanstack/react-query"; -import { setCurrentOrganizationSlug } from "@/features/dashboard/organization-cookie"; -import { useRouter } from "next/navigation"; -import { toast } from "sonner"; +import {ButtonWithConfirm} from "@/components/wrappers/common/button/button-with-confirm"; +import {deleteOrganizationAction} from "@/components/wrappers/dashboard/organization/organization.action"; +import {useMutation} from "@tanstack/react-query"; +import {setCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie"; +import {useRouter} from "next/navigation"; +import {toast} from "sonner"; import {authClient} from "@/lib/auth/auth-client"; +import {Trash2} from "lucide-react"; export type DeleteOrganizationButtonProps = { organizationSlug: string; @@ -38,13 +39,35 @@ export const DeleteOrganizationButton = (props: DeleteOrganizationButtonProps) = }); return ( + { - mutation.mutate(); + title="Delete Organization" + description="Are you sure you want to remove this organization? This action cannot be undone." + button={{ + main: { + text: "Delete Organization", + variant: "outline", + icon: , + }, + confirm: { + className: "w-full", + text: "Delete", + icon: , + variant: "destructive", + onClick: () => { + mutation.mutate(); + }, + }, + cancel: { + className: "w-full", + text: "Cancel", + icon: , + variant: "outline", + }, }} isPending={mutation.isPending} - text="Delete Organization" - variant="destructive" /> + + ); }; diff --git a/src/components/wrappers/dashboard/profile/button-delete-account/button-delete-account.tsx b/src/components/wrappers/dashboard/profile/button-delete-account/button-delete-account.tsx index 3c4a3d69..ad96f327 100644 --- a/src/components/wrappers/dashboard/profile/button-delete-account/button-delete-account.tsx +++ b/src/components/wrappers/dashboard/profile/button-delete-account/button-delete-account.tsx @@ -1,11 +1,11 @@ "use client"; -import { useMutation } from "@tanstack/react-query"; -import { Trash2 } from "lucide-react"; -import { ButtonWithConfirm } from "@/components/wrappers/common/button/button-with-confirm"; -import { signOut } from "@/lib/auth/auth-client"; -import { useRouter } from "next/navigation"; -import { deleteUserAction } from "./delete-account.action"; +import {useMutation} from "@tanstack/react-query"; +import {Trash2} from "lucide-react"; +import {ButtonWithConfirm} from "@/components/wrappers/common/button/button-with-confirm"; +import {signOut} from "@/lib/auth/auth-client"; +import {useRouter} from "next/navigation"; +import {deleteUserAction} from "./delete-account.action"; export type ButtonDeleteAccountProps = { text?: string; @@ -29,14 +29,33 @@ export const ButtonDeleteAccount = (props: ButtonDeleteAccountProps) => { return ( { - mutation.mutate(); + title={props.text ? props.text : ""} + description="Are you sure you want to delete your account ? This action cannot be undone." + button={{ + main: { + text: props.text ? props.text : "", + variant: "outline", + icon: , + }, + confirm: { + className: "w-full", + text: "Delete", + icon: , + variant: "destructive", + onClick: () => { + mutation.mutate(); + }, + }, + cancel: { + className: "w-full", + text: "Cancel", + icon: , + variant: "outline", + }, }} - variant={"destructive"} isPending={mutation.isPending} - className="gap-2" - icon={} /> + + ); }; diff --git a/src/components/wrappers/dashboard/projects/button-delete-project/button-delete-project.tsx b/src/components/wrappers/dashboard/projects/button-delete-project/button-delete-project.tsx index db156b9d..ad019839 100644 --- a/src/components/wrappers/dashboard/projects/button-delete-project/button-delete-project.tsx +++ b/src/components/wrappers/dashboard/projects/button-delete-project/button-delete-project.tsx @@ -1,11 +1,13 @@ "use client"; -import { Trash2 } from "lucide-react"; -import { ButtonWithConfirm } from "@/components/wrappers/common/button/button-with-confirm"; -import { useMutation } from "@tanstack/react-query"; -import { deleteProjectAction } from "@/components/wrappers/dashboard/projects/button-delete-project/delete-project.action"; -import { useRouter } from "next/navigation"; -import { toast } from "sonner"; +import {Trash2} from "lucide-react"; +import {ButtonWithConfirm} from "@/components/wrappers/common/button/button-with-confirm"; +import {useMutation} from "@tanstack/react-query"; +import { + deleteProjectAction +} from "@/components/wrappers/dashboard/projects/button-delete-project/delete-project.action"; +import {useRouter} from "next/navigation"; +import {toast} from "sonner"; export type ButtonDeleteProjectProps = { text?: string; @@ -27,15 +29,33 @@ export const ButtonDeleteProject = (props: ButtonDeleteProjectProps) => { }); return ( + { - mutation.mutate(); + title={props.text ? props.text : ""} + description="Are you sure you want to delete this project ? This action cannot be undone." + button={{ + main: { + text: props.text ? props.text : "", + variant: "outline", + icon: , + }, + confirm: { + className: "w-full", + text: "Delete", + icon: , + variant: "destructive", + onClick: () => { + mutation.mutate(); + }, + }, + cancel: { + className: "w-full", + text: "Cancel", + icon: , + variant: "outline", + }, }} - variant={"destructive"} isPending={mutation.isPending} - className="gap-2" - icon={} /> ); };