import type React from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import dynamic from "next/dynamic"; import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; import { api } from "@/utils/api"; import { toast } from "sonner"; import { z } from "zod"; import { useEffect, useState } from "react"; import { Textarea } from "@/components/ui/textarea"; import { RemoveSSHPrivateKey } from "./remove-ssh-private-key"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; const Terminal = dynamic(() => import("./terminal").then((e) => e.Terminal), { ssr: false, }); const addSSHPrivateKey = z.object({ sshPrivateKey: z .string({ required_error: "SSH private key is required", }) .min(1, "SSH private key is required"), }); type AddSSHPrivateKey = z.infer; interface Props { children?: React.ReactNode; } export const TerminalModal = ({ children }: Props) => { const { data, refetch } = api.admin.one.useQuery(); const [user, setUser] = useState("root"); const [terminalUser, setTerminalUser] = useState("root"); const { mutateAsync, isLoading } = api.settings.saveSSHPrivateKey.useMutation(); const form = useForm({ defaultValues: { sshPrivateKey: "", }, resolver: zodResolver(addSSHPrivateKey), }); useEffect(() => { if (data) { form.reset({}); } }, [data, form, form.reset]); const onSubmit = async (formData: AddSSHPrivateKey) => { await mutateAsync({ sshPrivateKey: formData.sshPrivateKey, }) .then(async () => { toast.success("SSH Key Updated"); await refetch(); }) .catch(() => { toast.error("Error to Update the ssh key"); }); }; return ( e.preventDefault()} > {children}
Terminal Easy way to access the server
{data?.haveSSH && (
)}
{!data?.haveSSH ? (
{ return ( SSH Private Key In order to access the server you need to add an ssh private key