mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 20:46:29 +00:00
78f48d783f
Introduce client and assignment detail pages and client-side components for the Task dashboard. Adds interactive ClientDetailComponent, AssignmentDetailComponent, page entries (server + dummy variants), project-assignment form, various UI components (AssignmentTable, ClientGrid, ManageEmployee, FormUpdateStatus, ConfirmDelete, LazyImage helper), types and a dummy data hook. Update app/(dashboard)/task/page.tsx to use the new components. Update .env.development to point to dev API endpoints, bump NEXT_PUBLIC_APP_VERSION to v1.2.0 and add NEXT_PUBLIC_S3_IMAGE_URL.
64 lines
2.4 KiB
TypeScript
64 lines
2.4 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
|
|
}
|
|
|
|
export function ConfirmDelete({ endpoint, title, description, onSuccess, onCancel, method }: 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!)
|
|
|
|
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>
|
|
)
|
|
}
|