2024-12-01 11:11:27 +01:00
|
|
|
"use client"
|
2024-12-16 20:01:30 +01:00
|
|
|
|
2024-12-01 11:11:27 +01:00
|
|
|
import {Trash2} from "lucide-react";
|
2024-12-16 20:01:30 +01:00
|
|
|
import {ButtonWithConfirm} from "@/components/wrappers/common/button/button-with-confirm";
|
2024-12-17 19:42:02 +01:00
|
|
|
import {useMutation} from "@tanstack/react-query";
|
|
|
|
|
import {deleteProjectAction} from "@/components/wrappers/dashboard/projects/ButtonDeleteProject/delete-project.action";
|
|
|
|
|
import {useRouter} from "next/navigation";
|
|
|
|
|
import {toast} from "sonner";
|
2024-12-01 11:11:27 +01:00
|
|
|
|
|
|
|
|
export type ButtonDeleteProjectProps = {
|
|
|
|
|
text? : string
|
2024-12-17 19:42:02 +01:00
|
|
|
projectId: string
|
2024-12-01 11:11:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ButtonDeleteProject = (props: ButtonDeleteProjectProps) => {
|
2024-12-17 19:42:02 +01:00
|
|
|
const router = useRouter()
|
|
|
|
|
const mutation = useMutation({
|
|
|
|
|
mutationFn: () => deleteProjectAction(props.projectId),
|
|
|
|
|
onSuccess: async (result) => {
|
2024-12-31 10:54:18 +01:00
|
|
|
router.push("/dashboard")
|
2024-12-17 19:42:02 +01:00
|
|
|
if(result.data.success) {
|
|
|
|
|
toast.success(result.data.actionSuccess.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
2024-12-01 11:11:27 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ButtonWithConfirm
|
|
|
|
|
text={props.text ? props.text : ""}
|
|
|
|
|
onClick={() => {
|
2024-12-17 19:42:02 +01:00
|
|
|
mutation.mutate()
|
2024-12-01 11:11:27 +01:00
|
|
|
}}
|
|
|
|
|
variant={"destructive"}
|
2024-12-17 19:42:02 +01:00
|
|
|
isPending={mutation.isPending}
|
2024-12-01 11:11:27 +01:00
|
|
|
className="gap-2"
|
|
|
|
|
icon={<Trash2/>}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|