Skip to content

refactor: User settings page #5661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create a new section for the settings layout
  • Loading branch information
BrunoQuaresma committed Jan 10, 2023
commit 7bb69388c5dce2fb8a9098387fef23542a252989
19 changes: 16 additions & 3 deletions site/src/components/Section/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeStyles } from "@material-ui/core/styles"
import Typography from "@material-ui/core/Typography"
import { FC } from "react"
import { combineClasses } from "../../util/combineClasses"
import { SectionAction } from "../SectionAction/SectionAction"

type SectionLayout = "fixed" | "fluid"
Expand Down Expand Up @@ -30,7 +31,7 @@ export const Section: SectionFC = ({
}) => {
const styles = useStyles({ layout })
return (
<section className={className}>
<section className={combineClasses([styles.root, className])}>
<div className={styles.inner}>
{(title || description) && (
<div className={styles.header}>
Expand Down Expand Up @@ -59,21 +60,33 @@ export const Section: SectionFC = ({
Section.Action = SectionAction

const useStyles = makeStyles((theme) => ({
root: {
backgroundColor: theme.palette.background.paper,
boxShadow: theme.shadows[6],
marginBottom: theme.spacing(1),
padding: theme.spacing(6),
borderRadius: theme.shape.borderRadius,
border: `1px solid ${theme.palette.divider}`,

[theme.breakpoints.down("sm")]: {
padding: theme.spacing(4, 3, 4, 3),
},
},
inner: ({ layout }: { layout: SectionLayout }) => ({
maxWidth: layout === "fluid" ? "100%" : 500,
}),
alert: {
marginBottom: theme.spacing(1),
},
header: {
marginBottom: theme.spacing(3),
marginBottom: theme.spacing(4),
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
},
description: {
color: theme.palette.text.secondary,
fontSize: 16,
marginTop: theme.spacing(0.5),
marginTop: theme.spacing(2),
},
}))
79 changes: 79 additions & 0 deletions site/src/components/SettingsLayout/Section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { makeStyles } from "@material-ui/core/styles"
import Typography from "@material-ui/core/Typography"
import { FC } from "react"
import { SectionAction } from "../SectionAction/SectionAction"

type SectionLayout = "fixed" | "fluid"

export interface SectionProps {
title?: React.ReactNode | string
description?: React.ReactNode
toolbar?: React.ReactNode
alert?: React.ReactNode
layout?: SectionLayout
className?: string
children?: React.ReactNode
}

type SectionFC = FC<React.PropsWithChildren<SectionProps>> & {
Action: typeof SectionAction
}

export const Section: SectionFC = ({
title,
description,
toolbar,
alert,
className = "",
children,
layout = "fixed",
}) => {
const styles = useStyles({ layout })
return (
<section className={className}>
<div className={styles.inner}>
{(title || description) && (
<div className={styles.header}>
<div>
{title && <Typography variant="h4">{title}</Typography>}
{description && typeof description === "string" && (
<Typography className={styles.description}>
{description}
</Typography>
)}
{description && typeof description !== "string" && (
<div className={styles.description}>{description}</div>
)}
</div>
{toolbar && <div>{toolbar}</div>}
</div>
)}
{alert && <div className={styles.alert}>{alert}</div>}
{children}
</div>
</section>
)
}

// Sub-components
Section.Action = SectionAction

const useStyles = makeStyles((theme) => ({
inner: ({ layout }: { layout: SectionLayout }) => ({
maxWidth: layout === "fluid" ? "100%" : 500,
}),
alert: {
marginBottom: theme.spacing(1),
},
header: {
marginBottom: theme.spacing(3),
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
},
description: {
color: theme.palette.text.secondary,
fontSize: 16,
marginTop: theme.spacing(0.5),
},
}))
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useActor } from "@xstate/react"
import React, { useContext } from "react"
import { Section } from "../../../components/Section/Section"
import { Section } from "../../../components/SettingsLayout/Section"
import { AccountForm } from "../../../components/SettingsAccountForm/SettingsAccountForm"
import { XServiceContext } from "../../../xServices/StateContext"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useActor } from "@xstate/react"
import React, { useContext, useEffect } from "react"
import { ConfirmDialog } from "../../../components/Dialogs/ConfirmDialog/ConfirmDialog"
import { Section } from "../../../components/Section/Section"
import { Section } from "../../../components/SettingsLayout/Section"
import { XServiceContext } from "../../../xServices/StateContext"
import { SSHKeysPageView } from "./SSHKeysPageView"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMachine } from "@xstate/react"
import { useMe } from "hooks/useMe"
import React from "react"
import { userSecuritySettingsMachine } from "xServices/userSecuritySettings/userSecuritySettingsXService"
import { Section } from "../../../components/Section/Section"
import { Section } from "../../../components/SettingsLayout/Section"
import { SecurityForm } from "../../../components/SettingsSecurityForm/SettingsSecurityForm"

export const Language = {
Expand Down