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

Cmdct 4125 - refactor report page footer #11930

Merged
merged 24 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1f25617
validateDOMnesting console error fix
britt-mo Jul 16, 2024
a212be7
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Jul 18, 2024
66f35cf
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Jul 22, 2024
acc67b2
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Jul 24, 2024
ff9c461
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Aug 1, 2024
696609d
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Aug 9, 2024
7773cc0
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Aug 13, 2024
08bee35
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Aug 20, 2024
421c436
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Aug 28, 2024
6478fb8
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Sep 19, 2024
b973df2
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 3, 2024
4787fbf
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 8, 2024
84715dd
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 8, 2024
416b351
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 15, 2024
4fe6762
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 21, 2024
d087628
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 22, 2024
2ebb048
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 24, 2024
29dd81e
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Oct 28, 2024
e082d06
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Nov 6, 2024
e3f313c
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Nov 7, 2024
8c388b8
Merge branch 'main' of https://github.com/Enterprise-CMCS/macpro-mdct…
britt-mo Nov 18, 2024
cb0b921
refactor reportPageFooter component
britt-mo Nov 18, 2024
b890f0e
update from PR review
britt-mo Nov 19, 2024
261560c
update per PR comment
britt-mo Nov 19, 2024
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
111 changes: 55 additions & 56 deletions services/ui-src/src/components/reports/ReportPageFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { useNavigate } from "react-router-dom";
import { Box, Button, Flex, Image, Spinner } from "@chakra-ui/react";
// utils
import { parseCustomHtml, useFindRoute, useStore } from "utils";
import { CustomHtmlElement, FormJson } from "types";
import { CustomHtmlElement, FormJson, ReportStatus } from "types";
// assets
import nextIcon from "assets/icons/icon_next_white.png";
import previousIcon from "assets/icons/icon_previous_blue.png";
import { INITIAL_REPORT_ROUTES } from "../../constants";

export const ReportPageFooter = ({
submitting,
Expand All @@ -20,56 +21,57 @@ export const ReportPageFooter = ({
report?.formTemplate.flatRoutes,
report?.formTemplate.basePath
);
const hidePrevious = previousRoute === "/mcpar" || previousRoute === "/mlr";

const { userIsAdmin, userIsReadOnly } = useStore().user ?? {};
const { userIsAdmin, userIsReadOnly, userIsEndUser } = useStore().user ?? {};
const isAdminUserType = userIsAdmin || userIsReadOnly;
const formIsDisabled = isAdminUserType && !form?.editableByAdmins;
const hidePrevious = INITIAL_REPORT_ROUTES.includes(previousRoute);
const reportWithSubmittedStatus = report?.status === ReportStatus.SUBMITTED;
const formIsDisabled =
(isAdminUserType && !form?.editableByAdmins) ||
(userIsEndUser && reportWithSubmittedStatus);
const isReadOnly = !form?.id || formIsDisabled;

const prevButton = (
<Button
onClick={() => navigate(previousRoute)}
variant="outline"
leftIcon={<Image src={previousIcon} alt="Previous" sx={sx.arrowIcon} />}
>
Previous
</Button>
);

const nextButtonNavOnly = (
<Button
onClick={() => navigate(nextRoute)}
sx={sx.nextButton}
rightIcon={<Image src={nextIcon} alt="Next" sx={sx.arrowIcon} />}
>
Continue
</Button>
);

const nextButtonSubmit = (
<Button
form={form?.id}
type="submit"
sx={sx.nextButton}
rightIcon={
!submitting ? (
<Image src={nextIcon} alt="Next" sx={sx.arrowIcon} />
) : undefined
}
>
{submitting ? <Spinner size="sm" /> : "Continue"}
</Button>
);

return (
<Box sx={sx.footerBox} {...props}>
<Box>
<Flex sx={hidePrevious ? sx.floatButtonRight : sx.buttonFlex}>
{!hidePrevious && (
<Button
onClick={() => navigate(previousRoute)}
variant="outline"
leftIcon={
<Image src={previousIcon} alt="Previous" sx={sx.arrowIcon} />
}
>
Previous
</Button>
)}
{!form?.id || formIsDisabled ? (
<Button
onClick={() => navigate(nextRoute)}
rightIcon={
submitting ? (
<></>
) : (
<Image src={nextIcon} alt="Next" sx={sx.arrowIcon} />
)
}
>
Continue
</Button>
) : (
<Button
form={form.id}
type="submit"
sx={sx.button}
rightIcon={
!submitting ? (
<Image src={nextIcon} alt="Next" sx={sx.arrowIcon} />
) : undefined
}
>
{submitting ? <Spinner size="sm" /> : "Continue"}
</Button>
)}
</Flex>
</Box>
<Flex>
{!hidePrevious ? prevButton : null}
{isReadOnly ? nextButtonNavOnly : nextButtonSubmit}
</Flex>
{praDisclosure && (
<Box sx={sx.praStatement}>{parseCustomHtml(praDisclosure)}</Box>
)}
Expand All @@ -86,24 +88,21 @@ interface Props {

const sx = {
footerBox: {
marginTop: "3.5rem",
},
buttonFlex: {
justifyContent: "space-between",
marginY: "1.5rem",
},
floatButtonRight: {
justifyContent: "right",
marginY: "1.5rem",
marginTop: "2.5rem",
paddingTop: "1.5rem",
},
arrowIcon: {
width: "1rem",
},
button: {
width: "8.25rem",
},
nextButton: {
minWidth: "8.25rem",
marginLeft: "auto",
},
praStatement: {
fontSize: "0.875rem",
paddingTop: "2rem",
marginTop: "2rem",
},
};
3 changes: 3 additions & 0 deletions services/ui-src/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ export enum States {
// TIMEOUT PARAMS
export const IDLE_WINDOW = 30 * 60 * 1000; // ms
export const PROMPT_AT = 29 * 60 * 1000; //ms

// REPORT ROUTES FOR FIRST SECTION OF A PROGRAM
export const INITIAL_REPORT_ROUTES = ["/mcpar", "/mlr", "/naaar"];
Loading