CRM_FastAPI_React / frontend /src /components /delete-learner-dialog.tsx
adwhytahumans's picture
Upload 12060 files
b08d3ae verified
Raw History Blame Contribute Delete
1.67 kB
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { useToast } from "@/components/ui/use-toast"
import { deleteLearner } from "@/lib/api"
import { LearnerOut } from "@/types/learner"
interface DeleteLearnerDialogProps {
learner: LearnerOut
open: boolean
onOpenChange: (open: boolean) => void
onSuccess?: () => void
}
export function DeleteLearnerDialog({
learner,
open,
onOpenChange,
onSuccess,
}: DeleteLearnerDialogProps) {
const { toast } = useToast()
async function handleDelete() {
try {
await deleteLearner(learner.id)
toast({
title: "Success",
description: "Learner deleted successfully",
})
onOpenChange(false)
onSuccess?.()
} catch (error) {
toast({
title: "Error",
description: "Failed to delete learner",
variant: "destructive",
})
}
}
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
<AlertDialogDescription>
This will permanently delete {learner.name}'s record. This action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete}>Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}