import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import React, { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { AlertBlock } from "@/components/shared/alert-block"; const addResourcesMysql = z.object({ memoryReservation: z.number().nullable().optional(), cpuLimit: z.number().nullable().optional(), memoryLimit: z.number().nullable().optional(), cpuReservation: z.number().nullable().optional(), }); interface Props { mysqlId: string; } type AddResourcesMysql = z.infer; export const ShowMysqlResources = ({ mysqlId }: Props) => { const { data, refetch } = api.mysql.one.useQuery( { mysqlId, }, { enabled: !!mysqlId }, ); const { mutateAsync, isLoading } = api.mysql.update.useMutation(); const form = useForm({ defaultValues: {}, resolver: zodResolver(addResourcesMysql), }); useEffect(() => { if (data) { form.reset({ cpuLimit: data?.cpuLimit || undefined, cpuReservation: data?.cpuReservation || undefined, memoryLimit: data?.memoryLimit || undefined, memoryReservation: data?.memoryReservation || undefined, }); } }, [data, form, form.reset]); const onSubmit = async (formData: AddResourcesMysql) => { await mutateAsync({ mysqlId, cpuLimit: formData.cpuLimit || null, cpuReservation: formData.cpuReservation || null, memoryLimit: formData.memoryLimit || null, memoryReservation: formData.memoryReservation || null, }) .then(async () => { toast.success("Resources Updated"); await refetch(); }) .catch(() => { toast.error("Error to Update the resources"); }); }; return ( Resources If you want to decrease or increase the resources to a specific application or database Please remember to click Redeploy after modify the resources to apply the changes.
( Memory Reservation { const value = e.target.value; if (value === "") { // Si el campo está vacío, establece el valor como null. field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { // Solo actualiza el valor si se convierte a un número válido. field.onChange(number); } } }} /> )} /> { return ( Memory Limit { const value = e.target.value; if (value === "") { // Si el campo está vacío, establece el valor como null. field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { // Solo actualiza el valor si se convierte a un número válido. field.onChange(number); } } }} /> ); }} /> { return ( Cpu Limit { const value = e.target.value; if (value === "") { // Si el campo está vacío, establece el valor como null. field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { // Solo actualiza el valor si se convierte a un número válido. field.onChange(number); } } }} /> ); }} /> { return ( Cpu Reservation { const value = e.target.value; if (value === "") { // Si el campo está vacío, establece el valor como null. field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { // Solo actualiza el valor si se convierte a un número válido. field.onChange(number); } } }} /> ); }} />
); };