import { AlertBlock } from "@/components/shared/alert-block"; import { CodeEditor } from "@/components/shared/code-editor"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { FileTerminal } from "lucide-react"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; interface Props { serverId: string; } const schema = z.object({ command: z.string().min(1, { message: "Command is required", }), }); type Schema = z.infer; export const EditScript = ({ serverId }: Props) => { const [isOpen, setIsOpen] = useState(false); const { data: server } = api.server.one.useQuery( { serverId, }, { enabled: !!serverId, }, ); const { mutateAsync, isLoading } = api.server.update.useMutation(); const { data: defaultCommand } = api.server.getDefaultCommand.useQuery( { serverId, }, { enabled: !!serverId, }, ); const form = useForm({ defaultValues: { command: "", }, resolver: zodResolver(schema), }); useEffect(() => { if (server) { form.reset({ command: server.command || defaultCommand, }); } }, [server, defaultCommand]); const onSubmit = async (formData: Schema) => { if (server) { await mutateAsync({ ...server, command: formData.command || "", serverId, }) .then((_data) => { toast.success("Script modified successfully"); }) .catch(() => { toast.error("Error modifying the script"); }); } }; return ( Modify Script Modify the script which install everything necessary to deploy applications on your server, We recommend not modifying this script unless you know what you are doing.
( Command )} />
); };