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

MERGING RELEASE branches #17

Merged
merged 4 commits into from
Oct 18, 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
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Sonar CI pipeline
on:
push:
branches:
- main
- 'release/**'
- develop
- 'feature/**'
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
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.
65 changes: 60 additions & 5 deletions src/components/HomePageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,46 @@ import {
useModulesManager,
useTranslations,
} from "@openimis/fe-core";
import { DEFAULT, MODULE_NAME } from "../constants";
import { 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,
messageTitle: {
textAlign: "center",
color: "red",
fontSize: "16px"
},
messageDate: {
textAlign: "center",
fontSize: "16px",
},
healthFacilityLongTimeActive: {
textAlign: "center",
},
healthFacilityMediumTimeActive: {
textAlign: "center",
color: "gray",
},
healthFacilityShortTimeActive: {
textAlign: "center",
color: "red",
},
messageNotice: {
fontSize: "16px"
}
}));

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 +60,11 @@ const HomePageContainer = () => {
"HomePageContainer.homeMessageURL",
DEFAULT.HOME_MESSAGE_URL
);
const showHealthFacilityMessage = modulesManager.getConf(
"fe-home",
"HomePageContainer.showHealthFacilityMessage",
DEFAULT.SHOW_HEALTH_FACILITY_MESSAGE
);

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

const dateToCheck = new Date(userHealthFacility?.contractEndDate ?? null);
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,14 +102,32 @@ const HomePageContainer = () => {
</Typography>
</Box>
</Grid>
{showHealthFacilityMessage && (
<Grid item xs={12}>
<h2 className={getHealthFacilityStatus(timeDelta)}>
{userHealthFacility
? formatMessageWithValues(
"HomePageContainer.healthFacilityStatus",
{
date: `${formatDateFromISO(dateToCheck)}`,
days: `${timeDelta}`,
}
)
: formatMessage("HomePageContainer.noHealthFacilityAssigned")}
</h2>
</Grid>
)}
{showHomeMessage && (
<Grid item xs={12}>
<ProgressOrError progress={messageLoading} error={messageError} />
<h3 className={classes.messageTitle}>
{formatMessage("HomePageContainer.messageTitle")}
</h3>
<p className={classes.messageDate}> {messageData?.date} </p>
<div dangerouslySetInnerHTML={{ __html: messageData?.notice }} />
<div
className={classes.messageNotice}
dangerouslySetInnerHTML={{ __html: messageData?.notice }}
/>
</Grid>
)}
<Contributions contributionKey="home.HomePage.Blocks" user={user} />
Expand Down
5 changes: 5 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export const DEFAULT = {
SHOW_HOME_MESSAGE: false,
HOME_MESSAGE_URL: "",
SHOW_HEALTH_FACILITY_MESSAGE: false,
};

export const DAYS_HF_STATUS = {
DAYS_LONG_TIME_ACTIVE: 180,
DAYS_MEDIUM_TIME_ACTIVE: 30,
};
export const MODULE_NAME = "home";
6 changes: 4 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"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})",
"home.HomePageContainer.noHealthFacilityAssigned": "User has no Health Facility assigned and there is no information on when the contract will expire."
}