From a019c54871a117c0ce3415c7074d081b3931e0ab Mon Sep 17 00:00:00 2001 From: Dragos DOBRE Date: Wed, 18 Oct 2023 16:06:46 +0200 Subject: [PATCH] MERGING RELEASE branches (#17) * ONI-106: User HF status information. (#14) * ONI-106: User HF status information. * ONI-106: HF status code review fixes. * ONI-106: HF status fixed if no HF assigned. (#16) * ONI-168: make a notice message larger (#18) * ONI-168: make a notice message larger * ONI-168: if user has no hf, show info about that instead of contract details * add-sonar-ci: add ci file (#19) Co-authored-by: Jan --------- Co-authored-by: wzglinieckisoldevelo <98958634+wzglinieckisoldevelo@users.noreply.github.com> Co-authored-by: olewandowski1 <109145288+olewandowski1@users.noreply.github.com> Co-authored-by: Jan Co-authored-by: Jan --- .github/workflows/ci.yaml | 23 ++++++++++ README.md | 1 + src/components/HomePageContainer.js | 65 ++++++++++++++++++++++++++--- src/constants.js | 5 +++ src/translations/en.json | 6 ++- 5 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..da93b2d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 }} diff --git a/README.md b/README.md index 514d9f1..5ad4fde 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/components/HomePageContainer.js b/src/components/HomePageContainer.js index 21391c5..24f4101 100644 --- a/src/components/HomePageContainer.js +++ b/src/components/HomePageContainer.js @@ -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", @@ -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(); @@ -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 ( @@ -65,6 +102,21 @@ const HomePageContainer = () => { + {showHealthFacilityMessage && ( + +

+ {userHealthFacility + ? formatMessageWithValues( + "HomePageContainer.healthFacilityStatus", + { + date: `${formatDateFromISO(dateToCheck)}`, + days: `${timeDelta}`, + } + ) + : formatMessage("HomePageContainer.noHealthFacilityAssigned")} +

+
+ )} {showHomeMessage && ( @@ -72,7 +124,10 @@ const HomePageContainer = () => { {formatMessage("HomePageContainer.messageTitle")}

{messageData?.date}

-
+
)} diff --git a/src/constants.js b/src/constants.js index 1f9bffb..9c75b35 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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"; diff --git a/src/translations/en.json b/src/translations/en.json index 2676505..1655279 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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." +} \ No newline at end of file