import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Form, FormControl, FormDescription, 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 { AlertTriangle, Container } from "lucide-react"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; const AddRegistrySchema = z.object({ username: z .string() .min(1, { message: "Username is required", }) .regex(/^[a-zA-Z0-9]+$/, { message: "Username can only contain letters and numbers", }), password: z.string().min(1, { message: "Password is required", }), registryUrl: z.string().min(1, { message: "Registry URL is required", }), }); type AddRegistry = z.infer; export const AddSelfHostedRegistry = () => { const utils = api.useUtils(); const [isOpen, setIsOpen] = useState(false); const { mutateAsync, error, isError, isLoading } = api.registry.enableSelfHostedRegistry.useMutation(); const router = useRouter(); const form = useForm({ defaultValues: { username: "", password: "", registryUrl: "", }, resolver: zodResolver(AddRegistrySchema), }); useEffect(() => { form.reset({ registryUrl: "", username: "", password: "", }); }, [form, form.reset, form.formState.isSubmitSuccessful]); const onSubmit = async (data: AddRegistry) => { await mutateAsync({ registryUrl: data.registryUrl, username: data.username, password: data.password, }) .then(async (data) => { await utils.registry.all.invalidate(); toast.success("Self Hosted Registry Created"); setIsOpen(false); }) .catch(() => { toast.error("Error to create a self hosted registry"); }); }; return ( Add a self hosted registry Fill the next fields to add a self hosted registry. {isError && (
{error?.message}
)}
( Username )} />
( Password )} />
( Registry URL Point a DNS record to the VPS IP address. )} />
); };