Skip to content

Commit

Permalink
updates api key form to disable after 365 days instead of 1 year (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei authored Dec 5, 2023
1 parent 80b5dab commit e801976
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions frontend/app/new/account-api-key/NewApiKeyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
/>
Expand Down

0 comments on commit e801976

Please sign in to comment.