mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
73 lines
3.0 KiB
TypeScript
73 lines
3.0 KiB
TypeScript
"use client";
|
|
import useNotifications from "@/hooks/useNotifications";
|
|
import { Trash2, AlertTriangle } from "lucide-react";
|
|
import { useState } from "react";
|
|
|
|
interface DeleteNotificationProps {
|
|
notificationId: number;
|
|
onNotificationDeleted?: () => void;
|
|
onError?: (message: string) => void;
|
|
onSuccess?: (message: string) => void;
|
|
}
|
|
|
|
export default function DeleteNotification({ notificationId, onNotificationDeleted, onError, onSuccess }: DeleteNotificationProps) {
|
|
const { deleteNotification } = useNotifications();
|
|
|
|
const handleDelete = async () => {
|
|
const response = deleteNotification(notificationId);
|
|
if (typeof response === "string") {
|
|
onError && onError(response)
|
|
return
|
|
}
|
|
|
|
try {
|
|
const successMessage = await response
|
|
if (onNotificationDeleted && successMessage) {
|
|
onNotificationDeleted()
|
|
onSuccess && onSuccess(successMessage)
|
|
}
|
|
} catch (apiError: any) {
|
|
onError && onError(apiError)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<dialog id="delete_notification" className="modal">
|
|
<div className="modal-box w-11/12 max-w-md border-l-4 border-error">
|
|
<div className="flex items-center gap-3 mb-3">
|
|
<div className="bg-error text-error-content rounded-full p-2 flex items-center justify-center">
|
|
<Trash2 className="h-6 w-6" />
|
|
</div>
|
|
<h3 className="font-bold text-xl">Delete Notification Provider</h3>
|
|
</div>
|
|
|
|
<div className="bg-base-200 p-4 rounded-lg mb-4">
|
|
<p className="text-sm">
|
|
<span className="font-medium">Are you sure you want to delete this Notification Provider?</span>
|
|
</p>
|
|
<p className="text-sm mt-2">
|
|
You will no longer receive notifications from this provider.
|
|
</p>
|
|
<div className="mt-2 flex items-center gap-2 text-error">
|
|
<AlertTriangle className="h-5 w-5" />
|
|
<span className="font-bold">This action cannot be undone.</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="modal-action">
|
|
<form method="dialog" className="flex gap-2">
|
|
<button className="btn btn-outline">Cancel</button>
|
|
<button
|
|
className="btn btn-error text-error-content"
|
|
onClick={handleDelete}
|
|
>
|
|
Delete Notification Provider
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</dialog>
|
|
</div>
|
|
)
|
|
} |