From 4160f013a0dd1bf945d2969ec22584fe6a32c4a4 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Wed, 21 Feb 2024 17:23:07 +0000 Subject: [PATCH] fix(site): fix error when typing long number on ttl --- .../WorkspaceSchedulePage/WorkspaceScheduleForm.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.tsx b/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.tsx index a5af7c72f0806..2c2970a30618f 100644 --- a/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.tsx +++ b/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.tsx @@ -428,7 +428,7 @@ export const WorkspaceScheduleForm: FC = ({ !template.allow_user_autostop || !form.values.autostopEnabled } - inputProps={{ min: 0, step: "any" }} + inputProps={{ min: 0, step: "any", maxLength: 5 }} label={Language.ttlLabel} type="number" fullWidth @@ -452,10 +452,17 @@ export const ttlShutdownAt = (formTTL: number): string => { if (formTTL === 0) { // Passing an empty value for TTL in the form results in a number that is not zero but less than 1. return "Your workspace will not automatically shut down."; - } else { + } + + try { return `Your workspace will shut down ${formatDuration( intervalToDuration({ start: 0, end: formTTL * 60 * 60 * 1000 }), { delimiter: " and " }, )} after its next start. We delay shutdown by 1 hour whenever we detect activity.`; + } catch (e) { + if (e instanceof RangeError) { + return Language.errorTtlMax; + } + throw e; } };