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 { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import copy from "copy-to-clipboard"; import { CopyIcon, LockIcon } from "lucide-react"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; const GitProviderSchema = z.object({ repositoryURL: z.string().min(1, { message: "Repository URL is required", }), branch: z.string().min(1, "Branch required"), buildPath: z.string().min(1, "Build Path required"), }); type GitProvider = z.infer; interface Props { applicationId: string; } export const SaveGitProvider = ({ applicationId }: Props) => { const { data, refetch } = api.application.one.useQuery({ applicationId }); const { mutateAsync, isLoading } = api.application.saveGitProdiver.useMutation(); const { mutateAsync: generateSSHKey, isLoading: isGeneratingSSHKey } = api.application.generateSSHKey.useMutation(); const { mutateAsync: removeSSHKey, isLoading: isRemovingSSHKey } = api.application.removeSSHKey.useMutation(); const form = useForm({ defaultValues: { branch: "", buildPath: "/", repositoryURL: "", }, resolver: zodResolver(GitProviderSchema), }); useEffect(() => { if (data) { form.reset({ branch: data.customGitBranch || "", buildPath: data.customGitBuildPath || "/", repositoryURL: data.customGitUrl || "", }); } }, [form.reset, data, form]); const onSubmit = async (values: GitProvider) => { await mutateAsync({ customGitBranch: values.branch, customGitBuildPath: values.buildPath, customGitUrl: values.repositoryURL, applicationId, }) .then(async () => { toast.success("Git Provider Saved"); await refetch(); }) .catch(() => { toast.error("Error to save the Git provider"); }); }; return (
( Repository URL
? Private Repository If your repository is private is necessary to generate SSH Keys to add to your git provider.