Skip to content
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

CRDCDH-92 Restructure FormView to support redesign #6

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
141 changes: 87 additions & 54 deletions src/content/questionnaire/FormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
unstable_useBlocker as useBlocker, unstable_Blocker as Blocker
} from 'react-router-dom';
import { isEqual } from 'lodash';
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@mui/material';
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Stack } from '@mui/material';
import { LoadingButton } from '@mui/lab';
import { WithStyles, withStyles } from "@mui/styles";
import ForwardArrowIcon from '@mui/icons-material/ArrowForwardIos';
Expand Down Expand Up @@ -73,7 +73,6 @@ const FormView: FC<Props> = ({ section, classes } : Props) => {

useEffect(() => {
setActiveSection(validateSection(section) ? section : "A");
window.scrollTo(0, 0);
}, [section]);

/**
Expand Down Expand Up @@ -159,53 +158,77 @@ const FormView: FC<Props> = ({ section, classes } : Props) => {
}

return (
<div className={classes.formContainer}>
<StatusBar />
<ProgressBar />
<Section section={activeSection} refs={refs} />
<>
<div className={classes.header}>
<i>Questionnaire Header</i>
</div>

<div className={classes.formControls}>
<Link to={prevSection} style={{ pointerEvents: prevSection ? "initial" : "none" }}>
<Button
variant="outlined"
type="button"
disabled={status === FormStatus.SAVING || !prevSection}
size="large"
startIcon={<BackwardArrowIcon />}
>
Back
</Button>
</Link>
<LoadingButton
variant="outlined"
type="button"
ref={refs.saveFormRef}
size="large"
loading={status === FormStatus.SAVING}
onClick={saveForm}
>
Save
</LoadingButton>
<LoadingButton
variant="outlined"
type="submit"
ref={refs.submitFormRef}
size="large"
<Stack direction="row" justifyContent="center">
<Stack
className={classes.sidebar}
direction="row"
justifyContent="center"
alignSelf="flex-start"
>
Submit
</LoadingButton>
<Link to={nextSection} style={{ pointerEvents: nextSection ? "initial" : "none" }}>
<Button
variant="outlined"
type="button"
disabled={status === FormStatus.SAVING || !nextSection}
size="large"
endIcon={<ForwardArrowIcon />}
<ProgressBar />
<Divider className={classes.divider} orientation="vertical" />
</Stack>

<Stack className={classes.content} direction="column" spacing={2}>
<StatusBar />

<Section section={activeSection} refs={refs} />

<Stack
className={classes.controls}
direction="row"
justifyContent="center"
alignItems="center"
spacing={2}
>
Next
</Button>
</Link>
</div>
<Link to={prevSection} style={{ pointerEvents: prevSection ? "initial" : "none" }}>
<Button
variant="outlined"
type="button"
disabled={status === FormStatus.SAVING || !prevSection}
size="large"
startIcon={<BackwardArrowIcon />}
>
Back
</Button>
</Link>
<LoadingButton
variant="outlined"
type="button"
ref={refs.saveFormRef}
size="large"
loading={status === FormStatus.SAVING}
onClick={saveForm}
>
Save
</LoadingButton>
<LoadingButton
variant="outlined"
type="submit"
ref={refs.submitFormRef}
size="large"
>
Submit
</LoadingButton>
<Link to={nextSection} style={{ pointerEvents: nextSection ? "initial" : "none" }}>
<Button
variant="outlined"
type="button"
disabled={status === FormStatus.SAVING || !nextSection}
size="large"
endIcon={<ForwardArrowIcon />}
>
Next
</Button>
</Link>
</Stack>
</Stack>
</Stack>

<Dialog open={blockedNavigate}>
<DialogTitle>
Expand All @@ -223,20 +246,30 @@ const FormView: FC<Props> = ({ section, classes } : Props) => {
<Button onClick={discardAndNavigate} disabled={status === FormStatus.SAVING} color="error">Discard</Button>
</DialogActions>
</Dialog>
</div>
</>
);
};

const styles = () => ({
formContainer: {
header: {
width: "100%",
height: "300px",
background: "#F2F4F8",
},
sidebar: {
position: "sticky" as const, // Ignore TS error
top: "25px",
},
divider: {
height: "250px",
width: "1px",
borderRightWidth: "2px",
margin: "0 15px",
},
content: {
maxWidth: "900px", // TODO: Update per design spec
},
formControls: {
display: "flex",
justifyContent: "center",
alignItems: "center",
background: "transparent",
margin: "25px 0",
controls: {
color: "#000000",
"& button": {
margin: "0 6px",
Expand Down
10 changes: 1 addition & 9 deletions src/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@ const Layout: FC<LayoutProps> = ({ children }) => {
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Public+Sans:wght@300;400;500;600;700&family=Rubik:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<style>
{`
html, body { height: 100%; }
body { background: linear-gradient(180deg, #F8FBFF 0%, #F4F8FD 47.4%, #EBEEF4 100%); background-attachment: fixed; }
`}
</style>
</Helmet>
<Header />
<Container maxWidth="lg">
<Box display="flex">
{children || <Outlet />}
</Box>
{children || <Outlet />}
</Container>
<Footer />
</>
Expand Down