import * as TooltipPrimitive from "@radix-ui/react-tooltip"; import { Ban, CheckCircle2, Hammer, RefreshCcw, Rocket, Terminal, } from "lucide-react"; import { useRouter } from "next/router"; import { toast } from "sonner"; import { ShowBuildChooseForm } from "@/components/dashboard/application/build/show"; import { ShowProviderForm } from "@/components/dashboard/application/general/generic/show"; import { DialogAction } from "@/components/shared/dialog-action"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Switch } from "@/components/ui/switch"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { api } from "@/utils/api"; import { DockerTerminalModal } from "../../settings/web-server/docker-terminal-modal"; interface Props { applicationId: string; } export const ShowGeneralApplication = ({ applicationId }: Props) => { const router = useRouter(); const { data, refetch } = api.application.one.useQuery( { applicationId, }, { enabled: !!applicationId }, ); const { mutateAsync: update } = api.application.update.useMutation(); const { mutateAsync: start, isLoading: isStarting } = api.application.start.useMutation(); const { mutateAsync: stop, isLoading: isStopping } = api.application.stop.useMutation(); const { mutateAsync: deploy } = api.application.deploy.useMutation(); const { mutateAsync: reload, isLoading: isReloading } = api.application.reload.useMutation(); const { mutateAsync: redeploy } = api.application.redeploy.useMutation(); return ( <> Deploy Settings { await deploy({ applicationId: applicationId, }) .then(() => { toast.success("Application deployed successfully"); refetch(); router.push( `/dashboard/project/${data?.environment.projectId}/environment/${data?.environmentId}/services/application/${applicationId}?tab=deployments`, ); }) .catch(() => { toast.error("Error deploying application"); }); }} > { await reload({ applicationId: applicationId, appName: data?.appName || "", }) .then(() => { toast.success("Application reloaded successfully"); refetch(); }) .catch(() => { toast.error("Error reloading application"); }); }} > { await redeploy({ applicationId: applicationId, }) .then(() => { toast.success("Application rebuilt successfully"); refetch(); }) .catch(() => { toast.error("Error rebuilding application"); }); }} > {data?.applicationStatus === "idle" ? ( { await start({ applicationId: applicationId, }) .then(() => { toast.success("Application started successfully"); refetch(); }) .catch(() => { toast.error("Error starting application"); }); }} > ) : ( { await stop({ applicationId: applicationId, }) .then(() => { toast.success("Application stopped successfully"); refetch(); }) .catch(() => { toast.error("Error stopping application"); }); }} > )}
Autodeploy { await update({ applicationId, autoDeploy: enabled, }) .then(async () => { toast.success("Auto Deploy Updated"); await refetch(); }) .catch(() => { toast.error("Error updating Auto Deploy"); }); }} className="flex flex-row gap-2 items-center data-[state=checked]:bg-primary" />
Clean Cache { await update({ applicationId, cleanCache: enabled, }) .then(async () => { toast.success("Clean Cache Updated"); await refetch(); }) .catch(() => { toast.error("Error updating Clean Cache"); }); }} className="flex flex-row gap-2 items-center data-[state=checked]:bg-primary" />
); };