mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
fccb901e2a
This update changes assignment deletion labels to prefer WO/IM names, adds a configurable payload to ConfirmDelete for non-DELETE API calls, and switches team member removal to a PUT endpoint with status REMOVED. It also shortens project autofill toast duration, cleans out stale commented code on the client detail page, and updates the task error badge wording to better reflect app-level failures.
65 lines
2.5 KiB
TypeScript
65 lines
2.5 KiB
TypeScript
import { useState } from "react";
|
|
import { toast } from "sonner";
|
|
import {
|
|
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
|
|
} from "@/components/ui/alert-dialog"
|
|
import { Button } from "@/components/ui/button";
|
|
import { Loader2 } from "lucide-react";
|
|
import { serverApiCall } from "@/lib/server-api";
|
|
|
|
interface Props {
|
|
endpoint?: string
|
|
onSuccess?: () => void;
|
|
onCancel?: () => void;
|
|
title?: string
|
|
description?: string,
|
|
method?: any
|
|
payload?: any
|
|
}
|
|
|
|
export function ConfirmDelete({ endpoint, title, description, onSuccess, onCancel, method, payload }: Props) {
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
const handleDelete = async () => {
|
|
setIsLoading(true)
|
|
const toastId = toast.loading('Deleting data...');
|
|
try {
|
|
const res = await serverApiCall(method || 'DELETE', endpoint!, payload)
|
|
|
|
if (res.success) {
|
|
toast.success("Data deleted successfully ☺️", { id: toastId });
|
|
onSuccess!()
|
|
} else {
|
|
toast.error("Oops sorry, error has occurred 😢", {
|
|
description: `(${res.code}) ${res.message || "An unexpected error occurred while saving data. Please try again later."}`,
|
|
id: toastId
|
|
})
|
|
}
|
|
} catch (error: any) {
|
|
toast.error(error.message, { id: toastId })
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<AlertDialog open={true}>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
{description || "This action cannot be undone. This will permanently delete this data and remove our servers."}
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel onClick={onCancel}>Cancel</AlertDialogCancel>
|
|
<Button onClick={handleDelete} disabled={isLoading} variant='destructive'>
|
|
{isLoading && <Loader2 className="animate-spin" />}
|
|
{isLoading ? "Deleting..." : "Continue"}
|
|
</Button>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
)
|
|
}
|