import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { useState, useEffect } from "react"; import { CorsEntry } from "@/lib/features/cors/corsSlice"; interface CorsEditDialogProps { open: boolean; onOpenChange: (open: boolean) => void; entry: CorsEntry | null; type: "whitelist" | "blacklist"; onUpdate: (id: string, origin: string, note: string) => Promise; } export function CorsEditDialog({ open, onOpenChange, entry, type, onUpdate }: CorsEditDialogProps) { const [origin, setOrigin] = useState(""); const [note, setNote] = useState(""); // Description or Reason const [loading, setLoading] = useState(false); useEffect(() => { if (entry) { setOrigin(entry.origin); setNote(entry.description || entry.reason || ""); } }, [entry]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!entry) return; setLoading(true); try { await onUpdate(entry.id, origin, note); onOpenChange(false); } catch (error) { console.error(error); } finally { setLoading(false); } }; const typeLabel = type === "whitelist" ? "Whitelist" : "Blacklist"; const noteLabel = type === "whitelist" ? "Açıklama" : "Sebep"; return ( {typeLabel} Güncelle Mevcut kaydı düzenleyin.
setOrigin(e.target.value)} required />
setNote(e.target.value)} />
); }