From e801976328b4c6ea1c5307b14dbab1126afa180a Mon Sep 17 00:00:00 2001 From: Nick Zelei <2420177+nickzelei@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:01:46 -0800 Subject: [PATCH] updates api key form to disable after 365 days instead of 1 year (#744) --- frontend/app/new/account-api-key/NewApiKeyForm.tsx | 6 ++++-- .../app/settings/account-api-keys/[id]/regenerate/page.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/app/new/account-api-key/NewApiKeyForm.tsx b/frontend/app/new/account-api-key/NewApiKeyForm.tsx index 4b48c875bc..c9112abb3f 100644 --- a/frontend/app/new/account-api-key/NewApiKeyForm.tsx +++ b/frontend/app/new/account-api-key/NewApiKeyForm.tsx @@ -2,7 +2,7 @@ import RequiredLabel from '@/components/labels/RequiredLabel'; import { useAccount } from '@/components/providers/account-provider'; import { Button } from '@/components/ui/button'; -import { addYears, endOfDay, format, startOfDay } from 'date-fns'; +import { endOfDay, format, startOfDay } from 'date-fns'; import { Calendar } from '@/components/ui/calendar'; import { @@ -223,7 +223,9 @@ export default function NewApiKeyForm(): ReactElement { }} disabled={(date) => date < endOfDay(new Date()) || - date > addYears(startOfDay(new Date()), 1) + // must be days instead of years to account for leap year + // backend constraints to within 365 days of the current time + date > addDays(startOfDay(new Date()), 365) } initialFocus /> diff --git a/frontend/app/settings/account-api-keys/[id]/regenerate/page.tsx b/frontend/app/settings/account-api-keys/[id]/regenerate/page.tsx index 9aa3e9d1ae..6ba0c8f0bf 100644 --- a/frontend/app/settings/account-api-keys/[id]/regenerate/page.tsx +++ b/frontend/app/settings/account-api-keys/[id]/regenerate/page.tsx @@ -41,7 +41,7 @@ import { getErrorMessage } from '@/util/util'; import { Timestamp } from '@bufbuild/protobuf'; import { yupResolver } from '@hookform/resolvers/yup'; import { CalendarIcon } from '@radix-ui/react-icons'; -import { addDays, addYears, endOfDay, format, startOfDay } from 'date-fns'; +import { addDays, endOfDay, format, startOfDay } from 'date-fns'; import { useRouter } from 'next/navigation'; import { ReactElement } from 'react'; import { useForm } from 'react-hook-form'; @@ -228,7 +228,9 @@ export default function RegenerateAccountApiKey({ }} disabled={(date) => date < endOfDay(new Date()) || - date > addYears(startOfDay(new Date()), 1) + // must be days instead of years to account for leap year + // backend constraints to within 365 days of the current time + date > addDays(startOfDay(new Date()), 365) } initialFocus />