Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08e54f3

Browse files
committed
fix: display validation error for workspace name
1 parent fc921a5 commit 08e54f3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

+16-6
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,16 @@ export const CreateWorkspacePageViewExperimental: FC<
140140
}
141141
}, [error]);
142142

143-
const getFieldHelpers = getFormHelpers<TypesGen.CreateWorkspaceRequest>(
144-
form,
145-
error,
146-
);
143+
useEffect(() => {
144+
if (form.submitCount > 0 && form.errors) {
145+
const fieldId = `${id}-workspace-name`;
146+
const el = document.getElementById(fieldId);
147+
if (el) {
148+
el.scrollIntoView({ behavior: "smooth", block: "center" });
149+
(el as HTMLElement).focus?.();
150+
}
151+
}
152+
}, [form.submitCount, form.errors, id]);
147153

148154
const [presetOptions, setPresetOptions] = useState([
149155
{ label: "None", value: "" },
@@ -333,7 +339,7 @@ export const CreateWorkspacePageViewExperimental: FC<
333339
<Label className="text-sm" htmlFor={`${id}-workspace-name`}>
334340
Workspace name
335341
</Label>
336-
<div>
342+
<div className="flex flex-col">
337343
<Input
338344
id={`${id}-workspace-name`}
339345
value={form.values.name}
@@ -343,6 +349,11 @@ export const CreateWorkspacePageViewExperimental: FC<
343349
}}
344350
disabled={creatingWorkspace}
345351
/>
352+
{form.touched.name && form.errors.name && (
353+
<div className="text-content-destructive text-xs mt-2">
354+
{form.errors.name}
355+
</div>
356+
)}
346357
<div className="flex gap-2 text-xs text-content-secondary items-center">
347358
Need a suggestion?
348359
<Button
@@ -477,7 +488,6 @@ export const CreateWorkspacePageViewExperimental: FC<
477488

478489
return (
479490
<DynamicParameter
480-
{...getFieldHelpers(parameterInputName)}
481491
key={parameter.name}
482492
parameter={parameter}
483493
onChange={(value) =>

0 commit comments

Comments
 (0)