From 4142af7d9239e3d32cfae004677b130b4f471dee Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Thu, 14 Apr 2022 18:38:55 +0200 Subject: [PATCH] fix: cleanup code in api keys --- apps/api | 2 +- .../components/apiKeys/ApiKeyDialogForm.tsx | 29 +++++++------------ .../apiKeys/ApiKeyListContainer.tsx | 6 +--- .../ee/components/apiKeys/ApiKeyListItem.tsx | 2 +- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/apps/api b/apps/api index a064983002..1405f7a861 160000 --- a/apps/api +++ b/apps/api @@ -1 +1 @@ -Subproject commit a064983002b2b6dd288788c87eb8b218063af377 +Subproject commit 1405f7a8615bfd0b7dab52bb994b7de6e6229519 diff --git a/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx b/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx index ae1823f310..75567ee023 100644 --- a/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx +++ b/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx @@ -19,20 +19,18 @@ import { TApiKeys } from "./ApiKeyListItem"; export default function ApiKeyDialogForm(props: { title: string; - defaultValues?: TApiKeys; + defaultValues?: Omit; handleClose: () => void; }) { const { t } = useLocale(); const utils = trpc.useContext(); const [neverExpires, setNeverExpires] = useState(false); - const handleNoteChange = (e: { target: { value: string } }) => { - form.setValue("note", e.target.value); - }; + const { defaultValues = { - note: "" as string | undefined, + note: "", expiresAt: dayjs().add(1, "month").toDate(), - } as Omit, + }, } = props; const [selectedDate, setSelectedDate] = useState(dayjs().add(1, "month").toDate()); @@ -97,19 +95,14 @@ export default function ApiKeyDialogForm(props: { ) : ( -
> form={form} handleSubmit={async (event) => { - try { - const newApiKey = await utils.client.mutation("viewer.apiKeys.create", event); - setNewApiKey(newApiKey); - setNewApiKeyDetails({ ...event }); - await utils.invalidateQueries(["viewer.apiKeys.list"]); - setSuccessfulNewApiKeyModal(true); - } catch (error: any) { - console.log(error); - showToast(error.message, "error"); - } + const newApiKey = await utils.client.mutation("viewer.apiKeys.create", event); + setNewApiKey(newApiKey); + setNewApiKeyDetails({ ...event }); + await utils.invalidateQueries(["viewer.apiKeys.list"]); + setSuccessfulNewApiKeyModal(true); }} className="space-y-4">
@@ -121,7 +114,7 @@ export default function ApiKeyDialogForm(props: { placeholder={t("personal_note_placeholder")} {...form.register("note")} type="text" - onChange={handleNoteChange} + // onChange={handleNoteChange} />
diff --git a/apps/web/ee/components/apiKeys/ApiKeyListContainer.tsx b/apps/web/ee/components/apiKeys/ApiKeyListContainer.tsx index ab79096e96..a7099e0272 100644 --- a/apps/web/ee/components/apiKeys/ApiKeyListContainer.tsx +++ b/apps/web/ee/components/apiKeys/ApiKeyListContainer.tsx @@ -11,7 +11,6 @@ import { QueryCell } from "@lib/QueryCell"; import { trpc } from "@lib/trpc"; import { List } from "@components/List"; -import Badge from "@components/ui/Badge"; export default function ApiKeyListContainer() { const { t } = useLocale(); @@ -27,10 +26,7 @@ export default function ApiKeyListContainer() { <>
-
-

{t("api_keys")}

- βeta -
+

{t("api_keys")}

{t("api_keys_subtitle")}

diff --git a/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx b/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx index fd89910c4c..c9f5004302 100644 --- a/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx +++ b/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx @@ -90,7 +90,7 @@ export default function ApiKeyListItem(props: { apiKey: TApiKeys; onEditApiKey: deleteApiKey.mutate({