import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema"; import { HelpCircle, KeyRoundIcon, LockIcon, X } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { GitIcon } from "@/components/icons/data-tools-icons"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { api } from "@/utils/api"; const GitProviderSchema = z.object({ composePath: z.string().min(1), repositoryURL: z.string().min(1, { message: "Repository URL is required", }), branch: z.string().min(1, "Branch required"), sshKey: z.string().optional(), watchPaths: z.array(z.string()).optional(), enableSubmodules: z.boolean().default(false), }); type GitProvider = z.infer; interface Props { composeId: string; } export const SaveGitProviderCompose = ({ composeId }: Props) => { const { data, refetch } = api.compose.one.useQuery({ composeId }); const { data: sshKeys } = api.sshKey.all.useQuery(); const router = useRouter(); const { mutateAsync, isPending } = api.compose.update.useMutation(); const form = useForm({ defaultValues: { branch: "", repositoryURL: "", composePath: "./docker-compose.yml", sshKey: undefined, watchPaths: [], enableSubmodules: false, }, resolver: zodResolver(GitProviderSchema), }); useEffect(() => { if (data) { form.reset({ sshKey: data.customGitSSHKeyId || undefined, branch: data.customGitBranch || "", repositoryURL: data.customGitUrl || "", composePath: data.composePath, watchPaths: data.watchPaths || [], enableSubmodules: data.enableSubmodules ?? false, }); } }, [form.reset, data, form]); const onSubmit = async (values: GitProvider) => { await mutateAsync({ customGitBranch: values.branch, customGitUrl: values.repositoryURL, customGitSSHKeyId: values.sshKey === "none" ? null : values.sshKey, composeId, sourceType: "git", composePath: values.composePath, composeStatus: "idle", watchPaths: values.watchPaths || [], enableSubmodules: values.enableSubmodules, }) .then(async () => { toast.success("Git Provider Saved"); await refetch(); }) .catch(() => { toast.error("Error saving the Git provider"); }); }; return (
(
Repository URL {field.value?.startsWith("https://") && ( View Repository )}
)} />
{sshKeys && sshKeys.length > 0 ? ( ( SSH Key )} /> ) : ( )}
( Branch )} />
( Compose Path )} /> (
Watch Paths

Add paths to watch for changes. When files in these paths change, a new deployment will be triggered. This will work only when manual webhook is setup.

{field.value?.map((path, index) => ( {path} { const newPaths = [...(field.value || [])]; newPaths.splice(index, 1); form.setValue("watchPaths", newPaths); }} /> ))}
{ if (e.key === "Enter") { e.preventDefault(); const input = e.currentTarget; const value = input.value.trim(); if (value) { const newPaths = [...(field.value || []), value]; form.setValue("watchPaths", newPaths); input.value = ""; } } }} />
)} /> ( Enable Submodules )} />
); };