From d2434700290d561acc02e81755ce969bdef31fda Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Thu, 25 Jul 2024 19:32:02 +0200 Subject: [PATCH] feat: link field with application --- .../general/generic/save-git-provider.tsx | 281 +- .../settings/ssh-keys/add-ssh-key.tsx | 8 +- .../settings/ssh-keys/show-ssh-keys.tsx | 92 +- .../settings/ssh-keys/update-ssh-key.tsx | 3 +- drizzle/0026_yielding_king_cobra.sql | 15 + drizzle/meta/0026_snapshot.json | 2997 +++++++++++++++++ drizzle/meta/_journal.json | 7 + server/api/routers/application.ts | 13 +- server/db/schema/application.ts | 21 +- server/db/schema/ssh-key.ts | 6 + 10 files changed, 3218 insertions(+), 225 deletions(-) create mode 100644 drizzle/0026_yielding_king_cobra.sql create mode 100644 drizzle/meta/0026_snapshot.json diff --git a/components/dashboard/application/general/generic/save-git-provider.tsx b/components/dashboard/application/general/generic/save-git-provider.tsx index 28828e7c..bcce4c83 100644 --- a/components/dashboard/application/general/generic/save-git-provider.tsx +++ b/components/dashboard/application/general/generic/save-git-provider.tsx @@ -1,13 +1,5 @@ +import { AddSSHKey } from "@/components/dashboard/settings/ssh-keys/add-ssh-key"; import { Button } from "@/components/ui/button"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; import { Form, FormControl, @@ -17,12 +9,24 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import { Textarea } from "@/components/ui/textarea"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; -import copy from "copy-to-clipboard"; -import { CopyIcon, LockIcon } from "lucide-react"; +import { SelectSeparator } from "@radix-ui/react-select"; +import { KeyRoundIcon, LockIcon } from "lucide-react"; +import Link from "next/link"; +import { useRouter } from "next/router"; + import { useEffect } from "react"; +import { flushSync } from "react-dom"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; @@ -33,6 +37,7 @@ const GitProviderSchema = z.object({ }), branch: z.string().min(1, "Branch required"), buildPath: z.string().min(1, "Build Path required"), + sshKey: z.string(), }); type GitProvider = z.infer; @@ -43,19 +48,22 @@ interface Props { export const SaveGitProvider = ({ applicationId }: Props) => { const { data, refetch } = api.application.one.useQuery({ applicationId }); + const { data: sshKeys } = api.sshKey.all.useQuery(); + const router = useRouter(); const { mutateAsync, isLoading } = api.application.saveGitProdiver.useMutation(); - const { mutateAsync: generateSSHKey, isLoading: isGeneratingSSHKey } = - api.application.generateSSHKey.useMutation(); + // const { mutateAsync: generateSSHKey, isLoading: isGeneratingSSHKey } = + // api.application.generateSSHKey.useMutation(); - const { mutateAsync: removeSSHKey, isLoading: isRemovingSSHKey } = - api.application.removeSSHKey.useMutation(); + // const { mutateAsync: removeSSHKey, isLoading: isRemovingSSHKey } = + // api.application.removeSSHKey.useMutation(); const form = useForm({ defaultValues: { branch: "", buildPath: "/", repositoryURL: "", + sshKey: "", }, resolver: zodResolver(GitProviderSchema), }); @@ -63,6 +71,7 @@ export const SaveGitProvider = ({ applicationId }: Props) => { useEffect(() => { if (data) { form.reset({ + sshKey: data.customGitSSHKeyId || "", branch: data.customGitBranch || "", buildPath: data.customGitBuildPath || "/", repositoryURL: data.customGitUrl || "", @@ -75,6 +84,7 @@ export const SaveGitProvider = ({ applicationId }: Props) => { customGitBranch: values.branch, customGitBuildPath: values.buildPath, customGitUrl: values.repositoryURL, + customGitSSHKeyId: values.sshKey, applicationId, }) .then(async () => { @@ -92,160 +102,103 @@ export const SaveGitProvider = ({ applicationId }: Props) => { onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-4" > -
-
- ( - - - Repository URL -
- - - ? - - - - Private Repository - - If your repository is private is necessary to - generate SSH Keys to add to your git provider. - - -
-
-