From d6dd76021226802adf5295b3243d6f2ae4fa5cc2 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 10 Mar 2024 17:59:58 +0000 Subject: refactor: Move all components to the top level directory --- .../dashboard/settings/components/AddApiKey.tsx | 167 --------------------- .../settings/components/ApiKeySettings.tsx | 49 ------ .../dashboard/settings/components/DeleteApiKey.tsx | 74 --------- packages/web/app/dashboard/settings/page.tsx | 2 +- 4 files changed, 1 insertion(+), 291 deletions(-) delete mode 100644 packages/web/app/dashboard/settings/components/AddApiKey.tsx delete mode 100644 packages/web/app/dashboard/settings/components/ApiKeySettings.tsx delete mode 100644 packages/web/app/dashboard/settings/components/DeleteApiKey.tsx (limited to 'packages/web/app/dashboard/settings') diff --git a/packages/web/app/dashboard/settings/components/AddApiKey.tsx b/packages/web/app/dashboard/settings/components/AddApiKey.tsx deleted file mode 100644 index a4fd9c25..00000000 --- a/packages/web/app/dashboard/settings/components/AddApiKey.tsx +++ /dev/null @@ -1,167 +0,0 @@ -"use client"; - -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form"; - -import { - Dialog, - DialogClose, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; -import { z } from "zod"; -import { useRouter } from "next/navigation"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm, SubmitErrorHandler } from "react-hook-form"; -import { toast } from "@/components/ui/use-toast"; -import { api } from "@/lib/trpc"; -import { useState } from "react"; -import { Check, Copy } from "lucide-react"; -import { ActionButton } from "@/components/ui/action-button"; - -function ApiKeySuccess({ apiKey }: { apiKey: string }) { - const [isCopied, setCopied] = useState(false); - - const onCopy = () => { - navigator.clipboard.writeText(apiKey); - setCopied(true); - setTimeout(() => setCopied(false), 2000); - }; - - return ( -
-
- Note: please copy the key and store it somewhere safe. Once you close - the dialog, you won't be able to access it again. -
-
- - -
-
- ); -} - -function AddApiKeyForm({ onSuccess }: { onSuccess: (key: string) => void }) { - const formSchema = z.object({ - name: z.string(), - }); - const router = useRouter(); - const mutator = api.apiKeys.create.useMutation({ - onSuccess: (resp) => { - onSuccess(resp.key); - router.refresh(); - }, - onError: () => { - toast({ description: "Something went wrong", variant: "destructive" }); - }, - }); - - const form = useForm>({ - resolver: zodResolver(formSchema), - }); - - async function onSubmit(value: z.infer) { - mutator.mutate({ name: value.name }); - } - - const onError: SubmitErrorHandler> = (errors) => { - toast({ - description: Object.values(errors) - .map((v) => v.message) - .join("\n"), - variant: "destructive", - }); - }; - - return ( -
- - { - return ( - - Name - - - - - Give your API key a unique name - - - - ); - }} - /> - - Create - - - - ); -} - -export default function AddApiKey() { - const [key, setKey] = useState(undefined); - const [dialogOpen, setDialogOpen] = useState(false); - return ( - - - - - - - - {key ? "Key was successfully created" : "Create API key"} - - - {key ? ( - - ) : ( - - )} - - - - - - - - - - ); -} diff --git a/packages/web/app/dashboard/settings/components/ApiKeySettings.tsx b/packages/web/app/dashboard/settings/components/ApiKeySettings.tsx deleted file mode 100644 index 1598f25f..00000000 --- a/packages/web/app/dashboard/settings/components/ApiKeySettings.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import { api } from "@/server/api/client"; -import DeleteApiKey from "./DeleteApiKey"; -import AddApiKey from "./AddApiKey"; - -export default async function ApiKeys() { - const keys = await api.apiKeys.list(); - return ( -
- API Keys -
-
-
- -
- - - - Name - Key - Created At - Action - - - - {keys.keys.map((k) => ( - - {k.name} - **_{k.keyId}_** - {k.createdAt.toLocaleString()} - - - - - ))} - - -
-
-
- ); -} diff --git a/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx b/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx deleted file mode 100644 index 566136af..00000000 --- a/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx +++ /dev/null @@ -1,74 +0,0 @@ -"use client"; - -import { Button } from "@/components/ui/button"; -import { Trash } from "lucide-react"; - -import { - Dialog, - DialogClose, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; -import { useRouter } from "next/navigation"; -import { toast } from "@/components/ui/use-toast"; -import { api } from "@/lib/trpc"; -import { ActionButton } from "@/components/ui/action-button"; -import { useState } from "react"; - -export default function DeleteApiKey({ - name, - id, -}: { - name: string; - id: string; -}) { - const [isDialogOpen, setDialogOpen] = useState(false); - const router = useRouter(); - const mutator = api.apiKeys.revoke.useMutation({ - onSuccess: () => { - toast({ - description: "Key was successfully deleted", - }); - setDialogOpen(false); - router.refresh(); - }, - }); - - return ( - - - - - - - Delete API Key - - Are you sure you want to delete the API key "{name}"? Any - service using this API key will lose access. - - - - - - - mutator.mutate({ id })} - > - Delete - - - - - ); -} diff --git a/packages/web/app/dashboard/settings/page.tsx b/packages/web/app/dashboard/settings/page.tsx index 95637d8c..38091e6c 100644 --- a/packages/web/app/dashboard/settings/page.tsx +++ b/packages/web/app/dashboard/settings/page.tsx @@ -1,4 +1,4 @@ -import ApiKeySettings from "./components/ApiKeySettings"; +import ApiKeySettings from "@/components/dashboard/settings/ApiKeySettings"; export default async function Settings() { return (
-- cgit v1.2.3-70-g09d2