diff --git a/frontend/src/pages/organization/SecretSharingSettingsPage/components/OrgSecretShareLimitSection/OrgSecretShareLimitSection.tsx b/frontend/src/pages/organization/SecretSharingSettingsPage/components/OrgSecretShareLimitSection/OrgSecretShareLimitSection.tsx index d65b76b16..648ad031c 100644 --- a/frontend/src/pages/organization/SecretSharingSettingsPage/components/OrgSecretShareLimitSection/OrgSecretShareLimitSection.tsx +++ b/frontend/src/pages/organization/SecretSharingSettingsPage/components/OrgSecretShareLimitSection/OrgSecretShareLimitSection.tsx @@ -71,7 +71,8 @@ const formSchema = z maxLifetimeUnit: z.enum(["m", "h", "d"], { invalid_type_error: "Please select a valid time unit" }), - maxViewLimit: z.string() + maxViewLimit: z.string(), + shouldLimitView: z.boolean() }) .superRefine((data, ctx) => { const { maxLifetimeValue, maxLifetimeUnit } = data; @@ -112,8 +113,8 @@ const formSchema = z type TForm = z.infer; const viewLimitOptions = [ - { label: "1", value: 1 }, - { label: "Unlimited", value: -1 } + { label: "Unlimited", value: false }, + { label: "Limited", value: true } ]; export const OrgSecretShareLimitSection = () => { @@ -125,13 +126,15 @@ export const OrgSecretShareLimitSection = () => { return { maxLifetimeValue: initialLifetime.maxLifetimeValue, maxLifetimeUnit: initialLifetime.maxLifetimeUnit, - maxViewLimit: currentOrg?.maxSharedSecretViewLimit?.toString() || "-1" + maxViewLimit: currentOrg?.maxSharedSecretViewLimit?.toString() || "1", + shouldLimitView: Boolean(currentOrg?.maxSharedSecretViewLimit) }; }; const { control, formState: { isSubmitting, isDirty }, + watch, handleSubmit, reset } = useForm({ @@ -139,6 +142,8 @@ export const OrgSecretShareLimitSection = () => { defaultValues: getDefaultFormValues() }); + const shouldLimitView = watch("shouldLimitView"); + useEffect(() => { if (currentOrg) { reset(getDefaultFormValues()); @@ -154,8 +159,7 @@ export const OrgSecretShareLimitSection = () => { await mutateAsync({ orgId: currentOrg.id, - maxSharedSecretViewLimit: - formData.maxViewLimit === "-1" ? null : Number(formData.maxViewLimit), + maxSharedSecretViewLimit: formData.shouldLimitView ? Number(formData.maxViewLimit) : null, maxSharedSecretLifetime: maxSharedSecretLifetimeSeconds }); @@ -249,26 +253,32 @@ export const OrgSecretShareLimitSection = () => { )} /> -
+
( + name="shouldLimitView" + render={({ field: { onChange, value, ...field }, fieldState: { error } }) => ( + + )} + /> + )}
{!isPublic && (