Skip to content

Commit

Permalink
Cmdct 4125 - refactor report page footer (#11930)
Browse files Browse the repository at this point in the history
  • Loading branch information
britt-mo authored Nov 20, 2024
1 parent 94cb7de commit 0e056be
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 56 deletions.
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"];

0 comments on commit 0e056be

Please sign in to comment.