Skip to content

Commit fe323a1

Browse files
authored
fix: keep "workspace create" form when rendering errors (#7289)
* fix: keep "workspace create" form when rendering errors * fmt * scroll to top if errors are present
1 parent bb0a38b commit fe323a1

File tree

1 file changed

+58
-49
lines changed

1 file changed

+58
-49
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

+58-49
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ export const CreateWorkspacePageView: FC<
7575
// to disappear.
7676
setGitAuthErrors({})
7777
}, [props.templateGitAuth])
78+
79+
const workspaceErrors =
80+
props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]
81+
82+
// Scroll to top of page if errors are present
83+
useEffect(() => {
84+
if (props.hasTemplateErrors || Boolean(workspaceErrors)) {
85+
window.scrollTo(0, 0)
86+
}
87+
}, [props.hasTemplateErrors, workspaceErrors])
88+
7889
const { t } = useTranslation("createWorkspacePage")
7990
const styles = useStyles()
8091

@@ -149,73 +160,71 @@ export const CreateWorkspacePageView: FC<
149160
return <Loader />
150161
}
151162

152-
if (props.hasTemplateErrors) {
153-
return (
154-
<Stack>
155-
{Boolean(
156-
props.createWorkspaceErrors[
157-
CreateWorkspaceErrors.GET_TEMPLATES_ERROR
158-
],
159-
) && (
160-
<AlertBanner
161-
severity="error"
162-
error={
163+
return (
164+
<FullPageHorizontalForm title="New workspace" onCancel={props.onCancel}>
165+
<HorizontalForm onSubmit={form.handleSubmit}>
166+
{Boolean(props.hasTemplateErrors) && (
167+
<Stack>
168+
{Boolean(
163169
props.createWorkspaceErrors[
164170
CreateWorkspaceErrors.GET_TEMPLATES_ERROR
165-
]
166-
}
167-
/>
168-
)}
169-
{Boolean(
170-
props.createWorkspaceErrors[
171-
CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR
172-
],
173-
) && (
174-
<AlertBanner
175-
severity="error"
176-
error={
171+
],
172+
) && (
173+
<AlertBanner
174+
severity="error"
175+
error={
176+
props.createWorkspaceErrors[
177+
CreateWorkspaceErrors.GET_TEMPLATES_ERROR
178+
]
179+
}
180+
/>
181+
)}
182+
{Boolean(
177183
props.createWorkspaceErrors[
178184
CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR
179-
]
180-
}
181-
/>
185+
],
186+
) && (
187+
<AlertBanner
188+
severity="error"
189+
error={
190+
props.createWorkspaceErrors[
191+
CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR
192+
]
193+
}
194+
/>
195+
)}
196+
{Boolean(
197+
props.createWorkspaceErrors[
198+
CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR
199+
],
200+
) && (
201+
<AlertBanner
202+
severity="error"
203+
error={
204+
props.createWorkspaceErrors[
205+
CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR
206+
]
207+
}
208+
/>
209+
)}
210+
</Stack>
182211
)}
212+
183213
{Boolean(
184214
props.createWorkspaceErrors[
185-
CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR
215+
CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR
186216
],
187217
) && (
188218
<AlertBanner
189219
severity="error"
190220
error={
191221
props.createWorkspaceErrors[
192-
CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR
222+
CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR
193223
]
194224
}
195225
/>
196226
)}
197-
</Stack>
198-
)
199-
}
200-
201-
if (
202-
props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]
203-
) {
204-
return (
205-
<AlertBanner
206-
severity="error"
207-
error={
208-
props.createWorkspaceErrors[
209-
CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR
210-
]
211-
}
212-
/>
213-
)
214-
}
215227

216-
return (
217-
<FullPageHorizontalForm title="New workspace" onCancel={props.onCancel}>
218-
<HorizontalForm onSubmit={form.handleSubmit}>
219228
{/* General info */}
220229
<FormSection
221230
title="General info"

0 commit comments

Comments
 (0)