From ece51565ca8ec662f92a91ac84591b30a4b573ef Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Thu, 12 Jan 2023 19:41:20 +0000 Subject: [PATCH 1/2] refactor: Wrap forms into dashboard layout --- site/src/AppRouter.tsx | 312 +++++++----------- .../DashboardLayout.tsx} | 9 +- .../FullPageForm/FullPageForm.stories.tsx | 1 - .../components/FullPageForm/FullPageForm.tsx | 43 ++- .../FullPageForm/FullPageHorizontalForm.tsx | 57 ++-- 5 files changed, 163 insertions(+), 259 deletions(-) rename site/src/components/{NavbarLayout/NavbarLayout.tsx => DashboardLayout/DashboardLayout.tsx} (89%) diff --git a/site/src/AppRouter.tsx b/site/src/AppRouter.tsx index bb472ca0ae91a..ee7522c05a323 100644 --- a/site/src/AppRouter.tsx +++ b/site/src/AppRouter.tsx @@ -18,7 +18,7 @@ import { Route, Routes } from "react-router-dom" import { selectPermissions } from "xServices/auth/authSelectors" import { selectFeatureVisibility } from "xServices/entitlements/entitlementsSelectors" import { XServiceContext } from "xServices/StateContext" -import { NavbarLayout } from "./components/NavbarLayout/NavbarLayout" +import { DashboardLayout } from "./components/DashboardLayout/DashboardLayout" import { RequireAuth } from "./components/RequireAuth/RequireAuth" import { SettingsLayout } from "./components/SettingsLayout/SettingsLayout" import { DeploySettingsLayout } from "components/DeploySettingsLayout/DeploySettingsLayout" @@ -134,132 +134,79 @@ export const AppRouter: FC = () => { } /> } /> - {/* Authenticated routes */} + {/* Dashboard routes */} }> - } /> + }> + } /> - } /> - } /> + } /> + } /> - - - - } - /> + } /> - - - - - } - /> - - - - - } - /> - - - - - - - } - /> - - } /> + + } /> + } /> + - - + + } /> + } /> + + - - } - /> - + } + /> + - - } - /> - } /> - } /> - - - - } /> + } /> + } /> + + } /> + - - - + + - - } - /> - } /> - + } + /> + } /> + - - + + - - } - /> - } /> - - - - } - /> - } /> - + } + /> + } /> + } /> + } /> + - - + + { > - - } - /> - + } + /> + - - + + { - - } - /> - + } + /> + { - - } - /> - + } + /> + { - - } - /> - + } + /> + { - - } - /> - + } + /> + { - - } - /> - + } + /> + { - - } - /> - + } + /> + - - + + - - } - /> - + } + /> + - - } - /> - - - - - - } - /> - - - - - - - } /> - - } /> - - } /> - - - + + + } /> + - } - /> + + + } /> + } /> + } /> + } + /> + } + /> + diff --git a/site/src/components/NavbarLayout/NavbarLayout.tsx b/site/src/components/DashboardLayout/DashboardLayout.tsx similarity index 89% rename from site/src/components/NavbarLayout/NavbarLayout.tsx rename to site/src/components/DashboardLayout/DashboardLayout.tsx index eb900dadf1bab..b55ad39978944 100644 --- a/site/src/components/NavbarLayout/NavbarLayout.tsx +++ b/site/src/components/DashboardLayout/DashboardLayout.tsx @@ -1,13 +1,14 @@ import { makeStyles } from "@material-ui/core/styles" import { useActor } from "@xstate/react" import { Loader } from "components/Loader/Loader" -import { FC, PropsWithChildren, Suspense, useContext, useEffect } from "react" +import { FC, Suspense, useContext, useEffect } from "react" import { XServiceContext } from "../../xServices/StateContext" import { Navbar } from "../Navbar/Navbar" import { UpdateCheckBanner } from "components/UpdateCheckBanner/UpdateCheckBanner" import { Margins } from "components/Margins/Margins" +import { Outlet } from "react-router-dom" -export const NavbarLayout: FC = ({ children }) => { +export const DashboardLayout: FC = () => { const styles = useStyles() const xServices = useContext(XServiceContext) const [authState] = useActor(xServices.authXService) @@ -38,7 +39,9 @@ export const NavbarLayout: FC = ({ children }) => { )}
- }>{children} + }> + +
) diff --git a/site/src/components/FullPageForm/FullPageForm.stories.tsx b/site/src/components/FullPageForm/FullPageForm.stories.tsx index 65a5f19bf1cea..bd92ea6cc974e 100644 --- a/site/src/components/FullPageForm/FullPageForm.stories.tsx +++ b/site/src/components/FullPageForm/FullPageForm.stories.tsx @@ -30,5 +30,4 @@ export const Example = Template.bind({}) Example.args = { title: "My Form", detail: "Lorem ipsum dolor", - onCancel: action("cancel"), } diff --git a/site/src/components/FullPageForm/FullPageForm.tsx b/site/src/components/FullPageForm/FullPageForm.tsx index 0887a5fe54495..8604172948117 100644 --- a/site/src/components/FullPageForm/FullPageForm.tsx +++ b/site/src/components/FullPageForm/FullPageForm.tsx @@ -1,39 +1,38 @@ -import { makeStyles } from "@material-ui/core/styles" +import { Margins } from "components/Margins/Margins" import { FC, ReactNode } from "react" -import { FormCloseButton } from "../FormCloseButton/FormCloseButton" -import { FormTitle } from "../FormTitle/FormTitle" -import { Margins } from "../Margins/Margins" +import { + PageHeader, + PageHeaderTitle, + PageHeaderSubtitle, +} from "components/PageHeader/PageHeader" +import { makeStyles } from "@material-ui/core/styles" export interface FullPageFormProps { title: string detail?: ReactNode - onCancel: () => void } -const useStyles = makeStyles(() => ({ - root: { - width: "100%", - display: "flex", - flexDirection: "column", - alignItems: "center", - }, -})) - export const FullPageForm: FC> = ({ title, detail, - onCancel, children, }) => { const styles = useStyles() + return ( -
- - - + + + {title} + {detail && {detail}} + - {children} - -
+
{children}
+ ) } + +const useStyles = makeStyles((theme) => ({ + pageHeader: { + paddingBottom: theme.spacing(2), + }, +})) diff --git a/site/src/components/FullPageForm/FullPageHorizontalForm.tsx b/site/src/components/FullPageForm/FullPageHorizontalForm.tsx index 704796f8e49d8..15c6b5ed78430 100644 --- a/site/src/components/FullPageForm/FullPageHorizontalForm.tsx +++ b/site/src/components/FullPageForm/FullPageHorizontalForm.tsx @@ -1,13 +1,12 @@ -import { FormCloseButton } from "../FormCloseButton/FormCloseButton" -import { makeStyles } from "@material-ui/core/styles" -import Typography from "@material-ui/core/Typography" import { Margins } from "components/Margins/Margins" import { FC, ReactNode } from "react" - -export interface FormTitleProps { - title: string - detail?: ReactNode -} +import { + PageHeader, + PageHeaderTitle, + PageHeaderSubtitle, +} from "components/PageHeader/PageHeader" +import Button from "@material-ui/core/Button" +import { makeStyles } from "@material-ui/core/styles" export interface FullPageHorizontalFormProps { title: string @@ -21,35 +20,25 @@ export const FullPageHorizontalForm: FC< const styles = useStyles() return ( - <> -
- - {title} - {detail && {detail}} - -
- - - -
- {children} -
- + + + Cancel + + } + > + {title} + {detail && {detail}} + + +
{children}
+
) } const useStyles = makeStyles((theme) => ({ - title: { - paddingTop: theme.spacing(6), - paddingBottom: theme.spacing(8), - - [theme.breakpoints.down("sm")]: { - paddingTop: theme.spacing(4), - paddingBottom: theme.spacing(4), - }, - }, - - main: { - paddingBottom: theme.spacing(10), + form: { + marginTop: theme.spacing(1), }, })) From 7c78e9d836bb8ec11d60f18fe0f400739ae213e3 Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Thu, 12 Jan 2023 19:56:55 +0000 Subject: [PATCH 2/2] Remove unused onCancel --- site/src/components/CreateUserForm/CreateUserForm.tsx | 2 +- .../components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx | 2 +- site/src/pages/GroupsPage/CreateGroupPageView.tsx | 2 +- site/src/pages/GroupsPage/SettingsGroupPageView.tsx | 2 +- .../src/pages/TemplateSettingsPage/TemplateSettingsPageView.tsx | 2 +- .../WorkspaceChangeVersionPageView.tsx | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/site/src/components/CreateUserForm/CreateUserForm.tsx b/site/src/components/CreateUserForm/CreateUserForm.tsx index e991c80fe1f41..dd14e5fbed95f 100644 --- a/site/src/components/CreateUserForm/CreateUserForm.tsx +++ b/site/src/components/CreateUserForm/CreateUserForm.tsx @@ -62,7 +62,7 @@ export const CreateUserForm: FC< ) return ( - +
+ {Boolean(submitScheduleError) && ( diff --git a/site/src/pages/GroupsPage/CreateGroupPageView.tsx b/site/src/pages/GroupsPage/CreateGroupPageView.tsx index e025d6263e2d8..ee0c0af65b8c2 100644 --- a/site/src/pages/GroupsPage/CreateGroupPageView.tsx +++ b/site/src/pages/GroupsPage/CreateGroupPageView.tsx @@ -39,7 +39,7 @@ export const CreateGroupPageView: FC = ({ return ( - + + = ({ } return ( - + {Boolean(errors.getTemplateError) && ( diff --git a/site/src/pages/WorkspaceChangeVersionPage/WorkspaceChangeVersionPageView.tsx b/site/src/pages/WorkspaceChangeVersionPage/WorkspaceChangeVersionPageView.tsx index 0d0511d67be5a..c555fea7640c9 100644 --- a/site/src/pages/WorkspaceChangeVersionPage/WorkspaceChangeVersionPageView.tsx +++ b/site/src/pages/WorkspaceChangeVersionPage/WorkspaceChangeVersionPageView.tsx @@ -21,7 +21,7 @@ export const WorkspaceChangeVersionPageView: FC< const { workspace, templateVersions, template, error } = context return ( - navigate(-1)}> +