Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(ui): keep an invalid duration out of role form state
lobocv6d62dca9ef6a
diff --git a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/RoleAssignmentRow.tsx b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/RoleAssignmentRow.tsxindex d8e3174ac0..28ff3ed874 100644--- a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/RoleAssignmentRow.tsx+++ b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/RoleAssignmentRow.tsx@@ -1,4 +1,4 @@-import { ReactNode } from "react";+import { ReactNode, useState } from "react";import { Control, Controller, UseFormSetValue, useWatch } from "react-hook-form";import { ChevronDownIcon, ClockIcon } from "lucide-react";import ms from "ms";@@ -28,6 +28,58 @@ import { getDurationDisplay, isValidTemporaryRange, TEMPORARY_RANGE_ERROR } fromtype RoleForSelect = { slug: string; name: string; id: string };+type DurationEditorProps = {+ committedRange?: string;+ isTemporary: boolean;+ isExpired: boolean;+ onApply: (temporaryRange: string) => void;+ onRemove: () => void;+};++// The Validity input is a local draft, not a registered form field. Only the Configure/Restart+// button commits it to the form, and that button stays disabled while the value is invalid. This+// keeps a half-typed range (eg "ab") out of the form state so it can't dirty the form or block save+// from behind a closed popover.+const DurationEditor = ({+ committedRange,+ isTemporary,+ isExpired,+ onApply,+ onRemove+}: DurationEditorProps) => {+ const [draft, setDraft] = useState(committedRange ?? "1h");+ const isValid = isValidTemporaryRange(draft);+ const errorMessage = draft && !isValid ? TEMPORARY_RANGE_ERROR : undefined;++ return (+ <div className="flex flex-col space-y-4">+ <div className="border-b border-b-border pb-2 text-sm text-muted">Configure Timed Access</div>+ {isExpired && <Badge variant="danger">Expired</Badge>}+ <Field>+ <FieldLabel>+ <TtlFormLabel label="Validity" />+ </FieldLabel>+ <Input+ value={draft}+ onChange={(e) => setDraft(e.target.value)}+ isError={Boolean(errorMessage)}+ />+ {errorMessage && <FieldError>{errorMessage}</FieldError>}+ </Field>+ <div className="flex items-center space-x-2">+ <Button size="xs" variant="outline" isDisabled={!isValid} onClick={() => onApply(draft)}>+ {isTemporary ? "Restart" : "Configure"}+ </Button>+ {isTemporary && (+ <Button size="xs" variant="danger" onClick={onRemove}>+ Remove Duration+ </Button>+ )}+ </div>+ </div>+ );+};+type Props = {control: Control<any>;setValue: UseFormSetValue<any>;@@ -54,7 +106,6 @@ export const RoleAssignmentRow = ({}: Props) => {const slugName = `${namePrefix}slug`;const temporaryAccessName = `${namePrefix}temporaryAccess`;- const temporaryRangeName = `${namePrefix}temporaryAccess.temporaryRange`;const temporaryAccess = useWatch({ control, name: temporaryAccessName });const isTemporary = Boolean(temporaryAccess?.isTemporary);@@ -110,7 +161,7 @@ export const RoleAssignmentRow = ({>{isTemporary && <ClockIcon />}{text}- <ChevronDownIcon />+ <ChevronDownIcon className="ml-auto" /></Button></PopoverTrigger></TooltipTrigger>@@ -122,78 +173,30 @@ export const RoleAssignmentRow = ({onWheel={(e) => e.stopPropagation()}onOpenAutoFocus={(e) => e.preventDefault()}>- <div className="flex flex-col space-y-4">- <div className="border-b border-b-border pb-2 text-sm text-muted">- Configure Timed Access- </div>- {isExpired && <Badge variant="danger">Expired</Badge>}- <Controller- control={control}- defaultValue="1h"- name={temporaryRangeName}- render={({ field, fieldState: { error } }) => {- // The schema blocks an invalid range on save; this surfaces the same message- // while the user is still typing, before the value has been granted.- const isInvalid = Boolean(field.value) && !isValidTemporaryRange(field.value);- const errorMessage = isInvalid ? TEMPORARY_RANGE_ERROR : error?.message;-- return (- <>- <Field>- <FieldLabel>- <TtlFormLabel label="Validity" />- </FieldLabel>- <Input- {...field}- value={field.value ?? ""}- isError={Boolean(errorMessage)}- />- {errorMessage && <FieldError>{errorMessage}</FieldError>}- </Field>- <div className="flex items-center space-x-2">- <Button- size="xs"- variant="outline"- isDisabled={!isValidTemporaryRange(field.value)}- onClick={() => {- const temporaryRange = field.value;- setValue(- temporaryAccessName,- {- isTemporary: true,- temporaryAccessStartTime: new Date().toISOString(),- temporaryRange,- temporaryAccessEndTime: new Date(- new Date().getTime() + ms(temporaryRange)- ).toISOString()- },- { shouldDirty: true }- );- }}- >- {isTemporary ? "Restart" : "Grant"}- </Button>- {isTemporary && (- <Button- size="xs"- variant="danger"- onClick={() =>- setValue(- temporaryAccessName,- { isTemporary: false },- { shouldDirty: true }- )- }- >- Revoke Access- </Button>- )}- </div>- </>- );- }}- />- </div>+ <DurationEditor+ committedRange={+ temporaryAccess?.isTemporary ? temporaryAccess.temporaryRange : undefined+ }+ isTemporary={isTemporary}+ isExpired={isExpired}+ onApply={(temporaryRange) =>+ setValue(+ temporaryAccessName,+ {+ isTemporary: true,+ temporaryAccessStartTime: new Date().toISOString(),+ temporaryRange,+ temporaryAccessEndTime: new Date(+ new Date().getTime() + ms(temporaryRange)+ ).toISOString()+ },+ { shouldDirty: true }+ )+ }+ onRemove={() =>+ setValue(temporaryAccessName, { isTemporary: false }, { shouldDirty: true })+ }+ /></PopoverContent></Popover></Field>