import { AlertBlock } from "@/components/shared/alert-block"; import { DialogAction } from "@/components/shared/dialog-action"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { api } from "@/utils/api"; import { format } from "date-fns"; import { KeyIcon, Loader2, MoreHorizontal, ServerIcon } from "lucide-react"; import { useTranslation } from "next-i18next"; import Link from "next/link"; import { useRouter } from "next/router"; import { toast } from "sonner"; import { ShowNodesModal } from "../cluster/nodes/show-nodes-modal"; import { TerminalModal } from "../web-server/terminal-modal"; import { ShowServerActions } from "./actions/show-server-actions"; import { HandleServers } from "./handle-servers"; import { SetupServer } from "./setup-server"; import { ShowDockerContainersModal } from "./show-docker-containers-modal"; import { ShowMonitoringModal } from "./show-monitoring-modal"; import { ShowSwarmOverviewModal } from "./show-swarm-overview-modal"; import { ShowTraefikFileSystemModal } from "./show-traefik-file-system-modal"; import { WelcomeSuscription } from "./welcome-stripe/welcome-suscription"; import { ShowSchedulesModal } from "./show-schedules-modal"; export const ShowServers = () => { const { t } = useTranslation("settings"); const router = useRouter(); const query = router.query; const { data, refetch, isLoading } = api.server.all.useQuery(); const { mutateAsync } = api.server.remove.useMutation(); const { data: sshKeys } = api.sshKey.all.useQuery(); const { data: isCloud } = api.settings.isCloud.useQuery(); const { data: canCreateMoreServers } = api.stripe.canCreateMoreServers.useQuery(); return (
{query?.success && isCloud && }
Servers Add servers to deploy your applications remotely. {isCloud && ( { router.push("/dashboard/settings/servers?success=true"); }} > Reset Onboarding )} {isLoading ? (
Loading...
) : ( <> {sshKeys?.length === 0 && data?.length === 0 ? (
No SSH Keys found. Add a SSH Key to start adding servers.{" "} Add SSH Key
) : ( <> {data?.length === 0 ? (
Start adding servers to deploy your applications remotely.
) : (
{!canCreateMoreServers && (
You cannot create more servers,{" "} Please upgrade your plan
)}
See all servers
Name {isCloud && ( Status )} IP Address Port Username SSH Key Created Actions {data?.map((server) => { const canDelete = server.totalSum === 0; const isActive = server.serverStatus === "active"; return ( {server.name} {isCloud && ( {server.serverStatus} )} {server.ipAddress} {server.port} {server.username} {server.sshKeyId ? "Yes" : "No"} {format( new Date(server.createdAt), "PPpp", )} Actions {isActive && ( <> {server.sshKeyId && ( {t( "settings.common.enterTerminal", )} )} {server.sshKeyId && ( )} )} You can not delete this server because it has active services. You have active services associated with this server, please delete them first. ) } onClick={async () => { await mutateAsync({ serverId: server.serverId, }) .then(() => { refetch(); toast.success( `Server ${server.name} deleted successfully`, ); }) .catch((err) => { toast.error(err.message); }); }} > e.preventDefault()} > Delete Server {isActive && server.sshKeyId && ( <> Extra {isCloud && ( )} )} ); })}
{data && data?.length > 0 && (
)}
)} )} )}
); };