From 1a76d6515a00a479318339a9514c07cbe5ca0934 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 26 Apr 2023 01:04:15 +0000 Subject: [PATCH 1/3] fix: keep "workspace create" form when rendering errors --- .../CreateWorkspacePageView.tsx | 105 +++++++++--------- 1 file changed, 50 insertions(+), 55 deletions(-) diff --git a/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx b/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx index 94957030ebc65..126a779731269 100644 --- a/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx +++ b/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx @@ -149,73 +149,68 @@ export const CreateWorkspacePageView: FC< return } - if (props.hasTemplateErrors) { - return ( - - {Boolean( - props.createWorkspaceErrors[ + return ( + + + + + {Boolean(props.hasTemplateErrors) && ( + {Boolean( + props.createWorkspaceErrors[ CreateWorkspaceErrors.GET_TEMPLATES_ERROR - ], - ) && ( - - )} - {Boolean( - props.createWorkspaceErrors[ + ], + ) && ( + + )} + {Boolean( + props.createWorkspaceErrors[ CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR - ], - ) && ( - - )} - {Boolean( - props.createWorkspaceErrors[ + ], + ) && ( + + )} + {Boolean( + props.createWorkspaceErrors[ CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR - ], - ) && ( + ], + ) && ( + + )} + + )} + + {Boolean(props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]) && ( )} - - ) - } - if ( - props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR] - ) { - return ( - - ) - } - - return ( - - {/* General info */} Date: Wed, 26 Apr 2023 01:55:38 +0000 Subject: [PATCH 2/3] fmt --- .../CreateWorkspacePageView.tsx | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx b/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx index 126a779731269..7b06cb62531c2 100644 --- a/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx +++ b/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx @@ -151,61 +151,64 @@ export const CreateWorkspacePageView: FC< return ( - - - {Boolean(props.hasTemplateErrors) && ( - {Boolean( - props.createWorkspaceErrors[ - CreateWorkspaceErrors.GET_TEMPLATES_ERROR - ], - ) && ( + {Boolean(props.hasTemplateErrors) && ( + + {Boolean( + props.createWorkspaceErrors[ + CreateWorkspaceErrors.GET_TEMPLATES_ERROR + ], + ) && ( )} - {Boolean( - props.createWorkspaceErrors[ - CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR - ], - ) && ( + {Boolean( + props.createWorkspaceErrors[ + CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR + ], + ) && ( )} - {Boolean( - props.createWorkspaceErrors[ - CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR - ], - ) && ( + {Boolean( + props.createWorkspaceErrors[ + CreateWorkspaceErrors.GET_TEMPLATE_GITAUTH_ERROR + ], + ) && ( )} - + )} - {Boolean(props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]) && ( + {Boolean( + props.createWorkspaceErrors[ + CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR + ], + ) && ( From 8027efb0e7a810c5ea79822f13477bbabdbcfe80 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 27 Apr 2023 16:22:42 +0000 Subject: [PATCH 3/3] scroll to top if errors are present --- .../CreateWorkspacePage/CreateWorkspacePageView.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx b/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx index 7b06cb62531c2..ba5a7e38eba6c 100644 --- a/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx +++ b/site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx @@ -75,6 +75,17 @@ export const CreateWorkspacePageView: FC< // to disappear. setGitAuthErrors({}) }, [props.templateGitAuth]) + + const workspaceErrors = + props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR] + + // Scroll to top of page if errors are present + useEffect(() => { + if (props.hasTemplateErrors || Boolean(workspaceErrors)) { + window.scrollTo(0, 0) + } + }, [props.hasTemplateErrors, workspaceErrors]) + const { t } = useTranslation("createWorkspacePage") const styles = useStyles()