2025-11-23 17:13:07 +01:00
|
|
|
"use client"
|
2025-11-28 23:10:37 +01:00
|
|
|
import {Filter, Megaphone} from "lucide-react";
|
2025-11-23 17:13:07 +01:00
|
|
|
|
|
|
|
|
import {useState} from "react";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogTrigger
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import {Button} from "@/components/ui/button";
|
|
|
|
|
import {AlertPolicyForm} from "@/components/wrappers/dashboard/database/alert-policy/alert-policy-form";
|
2025-11-28 23:10:37 +01:00
|
|
|
import {DatabaseWith} from "@/db/schema/07_database";
|
2025-11-23 17:13:07 +01:00
|
|
|
import {NotificationChannel} from "@/db/schema/09_notification-channel";
|
|
|
|
|
import {Separator} from "@/components/ui/separator";
|
2025-11-28 23:10:37 +01:00
|
|
|
import {Badge} from "@/components/ui/badge";
|
2025-11-23 17:13:07 +01:00
|
|
|
|
|
|
|
|
type AlertPolicyModalProps = {
|
2025-11-28 23:10:37 +01:00
|
|
|
database: DatabaseWith;
|
2025-11-23 17:13:07 +01:00
|
|
|
notificationChannels: NotificationChannel[];
|
|
|
|
|
organizationId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AlertPolicyModal = ({database, notificationChannels, organizationId}: AlertPolicyModalProps) => {
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
|
|
|
<DialogTrigger asChild>
|
2025-11-28 23:10:37 +01:00
|
|
|
<Button variant="outline" onClick={() => setOpen(true)} className="relative">
|
2025-11-23 17:13:07 +01:00
|
|
|
<Megaphone/>
|
2025-11-28 23:10:37 +01:00
|
|
|
{database.alertPolicies && database.alertPolicies.length > 0 && (
|
|
|
|
|
<Badge
|
|
|
|
|
className="absolute -top-1.5 -right-1.5 h-4 w-4 rounded-full p-0 text-[10px] flex items-center justify-center"
|
|
|
|
|
>
|
|
|
|
|
{database.alertPolicies.length}
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
2025-11-23 17:13:07 +01:00
|
|
|
</Button>
|
|
|
|
|
</DialogTrigger>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>Alert policies</DialogTitle>
|
|
|
|
|
<DialogDescription>
|
|
|
|
|
Add and manage your database alert policies
|
|
|
|
|
</DialogDescription>
|
|
|
|
|
|
|
|
|
|
<Separator className="mt-3 mb-3"/>
|
|
|
|
|
<AlertPolicyForm
|
|
|
|
|
organizationId={organizationId}
|
|
|
|
|
notificationChannels={notificationChannels}
|
|
|
|
|
database={database}
|
|
|
|
|
onSuccess={() => setOpen(false)}
|
|
|
|
|
/>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
)
|
|
|
|
|
}
|