import React, { useState } from "react"; import { api } from "@/src/utils/api"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogBody, } from "@/src/components/ui/dialog"; import { Button } from "@/src/components/ui/button"; import { Input } from "@/src/components/ui/input"; import { Label } from "@/src/components/ui/label"; import { Textarea } from "@/src/components/ui/textarea"; import { showSuccessToast } from "@/src/features/notifications/showSuccessToast"; import { showErrorToast } from "@/src/features/notifications/showErrorToast"; interface EditDashboardDialogProps { open: boolean; onOpenChange: (open: boolean) => void; projectId: string; dashboardId: string; initialName: string; initialDescription: string; } export function EditDashboardDialog({ open, onOpenChange, projectId, dashboardId, initialName, initialDescription, }: EditDashboardDialogProps) { const [name, setName] = useState(initialName); const [description, setDescription] = useState(initialDescription); const utils = api.useUtils(); const updateDashboard = api.dashboard.updateDashboardMetadata.useMutation({ onSuccess: () => { void utils.dashboard.invalidate(); showSuccessToast({ title: "Dashboard updated", description: "The dashboard has been updated successfully", }); onOpenChange(false); }, onError: (e) => { showErrorToast("Failed to update dashboard", e.message); }, }); const handleSave = () => { if (!name.trim()) { showErrorToast("Validation error", "Dashboard name is required"); return; } updateDashboard.mutate({ projectId, dashboardId, name: name.trim(), description: description.trim(), }); }; return ( Edit Dashboard
setName(e.target.value)} placeholder="Dashboard name" />