import React from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { api } from "@/utils/api"; import { z } from "zod"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { toast } from "sonner"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import Link from "next/link"; import { Server } from "lucide-react"; import { AddSwarmSettings } from "./modify-swarm-settings"; import { AlertBlock } from "@/components/shared/alert-block"; interface Props { applicationId: string; } const AddRedirectchema = z.object({ replicas: z.number(), registryId: z.string(), }); type AddCommand = z.infer; export const ShowClusterSettings = ({ applicationId }: Props) => { const { data } = api.application.one.useQuery( { applicationId, }, { enabled: !!applicationId }, ); const { data: registries } = api.registry.all.useQuery(); const utils = api.useUtils(); const { mutateAsync, isLoading } = api.application.update.useMutation(); const form = useForm({ defaultValues: { registryId: data?.registryId || "", replicas: data?.replicas || 1, }, resolver: zodResolver(AddRedirectchema), }); useEffect(() => { if (data?.command) { form.reset({ registryId: data?.registryId || "", replicas: data?.replicas || 1, }); } }, [form, form.reset, form.formState.isSubmitSuccessful, data?.command]); const onSubmit = async (data: AddCommand) => { await mutateAsync({ applicationId, registryId: data?.registryId === "none" ? null : data?.registryId, replicas: data?.replicas, }) .then(async () => { toast.success("Command Updated"); await utils.application.one.invalidate({ applicationId, }); }) .catch(() => { toast.error("Error to update the command"); }); }; return (
Cluster Settings Add the registry and the replicas of the application
Please remember to click Redeploy after modify the cluster settings to apply the changes.
( Replicas { field.onChange(Number(e.target.value)); }} type="number" /> )} />
{registries && registries?.length === 0 ? (
To use a cluster feature, you need to configure at least a registry first. Please, go to{" "} Settings {" "} to do so.
) : ( <> ( Select a registry )} /> )}
); };