diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index ff499bb..7fc08fc 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -1,22 +1,25 @@ import { useAuthActions } from "@convex-dev/auth/react"; import { useMutation, useQuery } from "convex/react"; -import { Plus } from "lucide-react"; +import { Plus, Trash2 } from "lucide-react"; import { useState } from "react"; import { toast } from "sonner"; import BuildsPanel from "@/components/BuildsPanel"; import ProfileEditor from "@/components/ProfileEditor"; import { Button } from "@/components/ui/button"; import { api } from "../../convex/_generated/api"; -import type { Id } from "../../convex/_generated/dataModel"; +import type { Doc, Id } from "../../convex/_generated/dataModel"; export default function Dashboard() { const { signOut } = useAuthActions(); const profiles = useQuery(api.profiles.list); const triggerBuild = useMutation(api.builds.triggerBuild); + const removeProfile = useMutation(api.profiles.remove); const [isEditing, setIsEditing] = useState(false); - const [editingProfile, setEditingProfile] = useState(null); + const [editingProfile, setEditingProfile] = useState | null>( + null, + ); - const handleEdit = (profile: any) => { + const handleEdit = (profile: Doc<"profiles">) => { setEditingProfile(profile); setIsEditing(true); }; @@ -39,6 +42,30 @@ export default function Dashboard() { } }; + const handleDelete = async ( + profileId: Id<"profiles">, + profileName: string, + ) => { + if ( + !confirm( + `Are you sure you want to delete "${profileName}"? This action cannot be undone.`, + ) + ) { + return; + } + + try { + await removeProfile({ id: profileId }); + toast.success("Profile deleted", { + description: `"${profileName}" has been deleted successfully.`, + }); + } catch (error) { + toast.error("Delete failed", { + description: String(error), + }); + } + }; + return (
@@ -89,6 +116,13 @@ export default function Dashboard() { +