Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: addressed duration input bug

Sheen Capadngan75998299ce8c
diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
index 19e9a4e7e2..8be6eeb3e8 100644
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
@@ -192,6 +192,70 @@ const STEPS = [
}
] as const;
+const DurationInput = ({
+ field,
+ error,
+ onCustomPreset
+}: {
+ field: {
+ value: number | undefined;
+ onChange: (value: number | undefined) => void;
+ onBlur: () => void;
+ name: string;
+ ref: React.Ref<HTMLInputElement>;
+ };
+ error?: { message?: string };
+ onCustomPreset: () => void;
+}) => {
+ const [localValue, setLocalValue] = useState<string>(
+ field.value !== undefined ? String(field.value) : ""
+ );
+
+ useEffect(() => {
+ if (field.value !== undefined) {
+ setLocalValue(String(field.value));
+ }
+ }, [field.value]);
+
+ return (
+ <Field className="flex-1">
+ <FieldLabel>Duration</FieldLabel>
+ <FieldContent>
+ <Input
+ type="number"
+ min={1}
+ isError={Boolean(error)}
+ value={localValue}
+ onChange={(e) => {
+ const rawValue = e.target.value;
+ setLocalValue(rawValue);
+ onCustomPreset();
+
+ if (rawValue === "") {
+ return;
+ }
+
+ const parsed = parseInt(rawValue, 10);
+ if (!Number.isNaN(parsed) && parsed > 0) {
+ field.onChange(parsed);
+ }
+ }}
+ onBlur={() => {
+ if (localValue === "" || Number.isNaN(parseInt(localValue, 10))) {
+ setLocalValue(field.value !== undefined ? String(field.value) : "365");
+ if (field.value === undefined) {
+ field.onChange(365);
+ }
+ }
+ field.onBlur();
+ }}
+ />
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ );
+};
+
const SectionToggle = ({
title,
description,
@@ -1312,23 +1376,11 @@ export const CreatePolicyModal = ({
control={control}
name="validity.maxDuration.value"
render={({ field, fieldState: { error } }) => (
- <Field className="flex-1">
- <FieldLabel>Duration</FieldLabel>
- <FieldContent>
- <Input
- type="number"
- min={1}
- isError={Boolean(error)}
- value={field.value ?? ""}
- onChange={(e) => {
- const parsed = parseInt(e.target.value, 10);
- field.onChange(Number.isNaN(parsed) ? undefined : parsed);
- markCustomPreset();
- }}
- />
- <FieldError errors={[error]} />
- </FieldContent>
- </Field>
+ <DurationInput
+ field={field}
+ error={error}
+ onCustomPreset={markCustomPreset}
+ />
)}
/>
<Controller
diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts
index 9be7dc60dd..a81055f78a 100644
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts
@@ -36,7 +36,7 @@ export const uiExtendedKeyUsagesSchema = z.object({
export const uiValiditySchema = z.object({
maxDuration: z.object({
- value: z.coerce.number().min(1, "Duration must be at least 1"),
+ value: z.number().min(1, "Duration must be at least 1"),
unit: z.nativeEnum(CertDurationUnit)
})
});