Skip to content

Commit

Permalink
ONI-106: User HF status information. (#14)
Browse files Browse the repository at this point in the history
* ONI-106: User HF status information.

* ONI-106: HF status code review fixes.
  • Loading branch information
wzglinieckisoldevelo committed Sep 19, 2023
1 parent c93771e commit 4ab0db6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ It is dedicated to be deployed as a module of [openimis-fe_js](https://github.co

- `HomePageContainer.showHomeMessage`: a boolean configuration flag that determines whether or not a special message will be displayed on the home page. If set to true, the application will fetch and display HTML content based on the URL specified in **HomePageContainer.homeMessageURL**. By default, this is set to false. It means that no additional message will be displayed on the home page.
- `HomePageContainer.homeMessageURL`: a string configuration that specifies the URL from which to fetch the HTML payload for display on the home page. By default, this is set to an empty string (""), meaning no URL is specified. This URL is used only when **HomePageContainer.showHomeMessage** is set to true.
- `HomePageContainer.showHealthFacilityMessage`: boolean to show HF status information. It shows days to the end of the contract of a HF assigned to a current user. Default false.
50 changes: 46 additions & 4 deletions src/components/HomePageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import {
useModulesManager,
useTranslations,
} from "@openimis/fe-core";
import { DEFAULT, MODULE_NAME } from "../constants";
import { useDispatch, useSelector } from "react-redux";

import { DEFAULT, MODULE_NAME, DAYS_HF_STATUS } from "../constants";
import { useFetchData } from "../hooks/useFetchData";
import { getTimeDifferenceInDaysFromToday } from "@openimis/fe-core";

const useStyles = makeStyles((theme) => ({
container: theme.page,
Expand All @@ -22,14 +25,26 @@ const useStyles = makeStyles((theme) => ({
messageDate: {
textAlign: "center",
},
healthFacilityLongTimeActive: {
textAlign: "center",
},
healthFacilityMediumTimeActive: {
textAlign: "center",
color: "gray",
},
healthFacilityShortTimeActive: {
textAlign: "center",
color: "red",
},
}));

const HomePageContainer = () => {
const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations(
MODULE_NAME,
modulesManager
const userHealthFacility = useSelector(
(state) => state?.loc?.userHealthFacilityFullPath
);
const { formatMessage, formatMessageWithValues, formatDateFromISO } =
useTranslations(MODULE_NAME, modulesManager);
const showHomeMessage = modulesManager.getConf(
"fe-home",
"HomePageContainer.showHomeMessage",
Expand All @@ -40,6 +55,11 @@ const HomePageContainer = () => {
"HomePageContainer.homeMessageURL",
DEFAULT.HOME_MESSAGE_URL
);
const showHealthFacilityMessage = modulesManager.getConf(
"fe-home",
"HomePageContainer.showHealthFacilityMessage",
true
);

const { user } = useUserQuery();
const classes = useStyles();
Expand All @@ -53,6 +73,18 @@ const HomePageContainer = () => {
return null;
}

const dateToCheck = new Date(userHealthFacility.contractEndDate);
const timeDelta = getTimeDifferenceInDaysFromToday(dateToCheck);
const getHealthFacilityStatus = (timeDelta) => {
if (timeDelta > DAYS_HF_STATUS.DAYS_LONG_TIME_ACTIVE) {
return classes.healthFacilityLongTimeActive;
} else if (timeDelta > DAYS_HF_STATUS.DAYS_MEDIUM_TIME_ACTIVE) {
return classes.healthFacilityMediumTimeActive;
} else {
return classes.healthFacilityShortTimeActive;
}
};

return (
<Grid container className={classes.container} spacing={2}>
<Grid item xs={12}>
Expand All @@ -65,6 +97,16 @@ const HomePageContainer = () => {
</Typography>
</Box>
</Grid>
{showHealthFacilityMessage && (
<Grid item xs={12}>
<h2 className={getHealthFacilityStatus(timeDelta)}>
{formatMessageWithValues("HomePageContainer.healthFacilityStatus", {
date: `${formatDateFromISO(dateToCheck)}`,
days: `${timeDelta}`,
})}
</h2>
</Grid>
)}
{showHomeMessage && (
<Grid item xs={12}>
<ProgressOrError progress={messageLoading} error={messageError} />
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export const DEFAULT = {
HOME_MESSAGE_URL: "",
};

export const DAYS_HF_STATUS={DAYS_LONG_TIME_ACTIVE: 180, DAYS_MEDIUM_TIME_ACTIVE: 30}
export const MODULE_NAME = "home";
5 changes: 3 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"home.HomePageContainer.welcomeMessage": "Welcome {otherNames} {lastName}!",
"home.HomePageContainer.messageTitle": "Notice"
}
"home.HomePageContainer.messageTitle": "Notice",
"home.HomePageContainer.healthFacilityStatus": "Your Hospital Contract is expiring on {date}: (Remaining days: {days})"
}

0 comments on commit 4ab0db6

Please sign in to comment.