diff --git a/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx b/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx index 75567ee023..6c511d7637 100644 --- a/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx +++ b/apps/web/ee/components/apiKeys/ApiKeyDialogForm.tsx @@ -1,7 +1,7 @@ import { ClipboardCopyIcon } from "@heroicons/react/solid"; import dayjs from "dayjs"; import { useState } from "react"; -import { useForm } from "react-hook-form"; +import { Controller, useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; @@ -19,16 +19,16 @@ import { TApiKeys } from "./ApiKeyListItem"; export default function ApiKeyDialogForm(props: { title: string; - defaultValues?: Omit; + defaultValues?: Omit & { neverExpires: boolean }; handleClose: () => void; }) { const { t } = useLocale(); const utils = trpc.useContext(); - const [neverExpires, setNeverExpires] = useState(false); const { defaultValues = { note: "", + nexerExpires: false, expiresAt: dayjs().add(1, "month").toDate(), }, } = props; @@ -51,6 +51,8 @@ export default function ApiKeyDialogForm(props: { const form = useForm({ defaultValues, }); + const watchNeverExpires = form.watch("neverExpires"); + return ( <> {successfulNewApiKeyModal ? ( @@ -95,7 +97,7 @@ export default function ApiKeyDialogForm(props: { ) : ( - > + & { neverExpires: boolean }> form={form} handleSubmit={async (event) => { const newApiKey = await utils.client.mutation("viewer.apiKeys.create", event); @@ -114,30 +116,23 @@ export default function ApiKeyDialogForm(props: { placeholder={t("personal_note_placeholder")} {...form.register("note")} type="text" - // onChange={handleNoteChange} />
{t("expire_date")} - { - if (isChecked) { - form.setValue("expiresAt", null); - setNeverExpires(true); - } else { - setNeverExpires(false); - form.setValue("expiresAt", form.getValues().expiresAt || new Date()); - } - }} + ( + + )} />
+
diff --git a/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx b/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx index c9f5004302..ea5b8d0037 100644 --- a/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx +++ b/apps/web/ee/components/apiKeys/ApiKeyListItem.tsx @@ -35,7 +35,7 @@ export default function ApiKeyListItem(props: { apiKey: TApiKeys; onEditApiKey:
- {props?.apiKey?.note ? props?.apiKey?.note : t("api_key_no_note")} + {props?.apiKey?.note ? props.apiKey.note : t("api_key_no_note")} {!neverExpires && isExpired && (