import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; import { Card, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { api } from "@/utils/api"; import { AlertTriangle, BookIcon, ExternalLinkIcon, FolderInput, MoreHorizontalIcon, TrashIcon, } from "lucide-react"; import Link from "next/link"; import { toast } from "sonner"; import { UpdateProject } from "./update"; import { DateTooltip } from "@/components/shared/date-tooltip"; export const ShowProjects = () => { const utils = api.useUtils(); const { data } = api.project.all.useQuery(); const { data: auth } = api.auth.get.useQuery(); const { data: user } = api.user.byAuthId.useQuery( { authId: auth?.id || "", }, { enabled: !!auth?.id && auth?.rol === "user", }, ); const { mutateAsync } = api.project.remove.useMutation(); return ( <> {data?.length === 0 && (
No projects added yet. Click on Create project.
)}
{data?.map((project) => { const emptyServices = project?.mariadb.length === 0 && project?.mongo.length === 0 && project?.mysql.length === 0 && project?.postgres.length === 0 && project?.redis.length === 0 && project?.applications.length === 0; const totalServices = project?.mariadb.length + project?.mongo.length + project?.mysql.length + project?.postgres.length + project?.redis.length + project?.applications.length; return (
{project.name}
{project.description}
Actions {(auth?.rol === "admin" || user?.canDeleteProjects) && ( e.preventDefault()} > Delete Are you sure to delete this project? {!emptyServices ? (
You have active services, please delete them first
) : ( This action cannot be undone )}
Cancel { await mutateAsync({ projectId: project.projectId, }) .then(() => { toast.success( "Project delete succesfully", ); }) .catch(() => { toast.error( "Error to delete this project", ); }) .finally(() => { utils.project.all.invalidate(); }); }} > Delete
)}
Created {totalServices}{" "} {totalServices === 1 ? "service" : "services"}
); })}
); };