From 5d48895383f1d55b55ca134e3858f175321834c9 Mon Sep 17 00:00:00 2001 From: olewandowski1 Date: Mon, 11 Mar 2024 13:52:48 +0100 Subject: [PATCH 1/2] OP-1792: include status when evaluating policy --- src/components/ClaimMasterPanelExt.js | 34 ++++++++++++++++----------- src/constants.js | 1 + 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/components/ClaimMasterPanelExt.js b/src/components/ClaimMasterPanelExt.js index 4b919e2..517c61c 100644 --- a/src/components/ClaimMasterPanelExt.js +++ b/src/components/ClaimMasterPanelExt.js @@ -23,7 +23,7 @@ import { clearLastClaimWithSameDiagnosis, fetchLastClaimWithSameDiagnosis, } from "../actions"; -import { DEFAULT } from "../constants"; +import { DEFAULT, POLICY_ACTIVE_STATUS } from "../constants"; import AdditionalPanelHeaders from "./AdditionalPanelHeaders"; import AdditionalPanelInsuree from "./AdditionalPanelInsuree"; import AdditionalPanelClaim from "./AdditionalPanelClaim"; @@ -85,19 +85,27 @@ class ClaimMasterPanelExt extends Component { clearLastClaimAt(); } - getPolicyStatusLabel(timeDelta) { - return timeDelta >= 0 ? ACTIVE_LABEL : INACTIVE_LABEL; - } - - getPolicyStatusLabelStyle(timeDelta, classes) { - return timeDelta >= 0 ? classes.activeLabel : classes.inactiveLabel; - } - goToClaimUuid(uuid) { const { modulesManager, history } = this.props; historyPush(modulesManager, history, "claim.route.claimEdit", [uuid], true); } + valuatePolicyValidity = (currentPolicy) => { + const { classes } = this.props; + + if (!currentPolicy || !currentPolicy.length) { + return { policyInfoLabel: INACTIVE_LABEL, policyInfoStyle: classes.inactiveLabel }; + } + + const validityPeriod = getTimeDifferenceInDaysFromToday(currentPolicy[0].expiryDate); + const isPolicyActive = currentPolicy[0].status === POLICY_ACTIVE_STATUS; + + return { + policyInfoLabel: validityPeriod >= 0 && isPolicyActive ? ACTIVE_LABEL : INACTIVE_LABEL, + policyInfoStyle: validityPeriod >= 0 && isPolicyActive ? classes.activeLabel : classes.inactiveLabel, + }; + }; + render() { const { classes, @@ -118,15 +126,13 @@ class ClaimMasterPanelExt extends Component { dateFrom, insuree, } = this.props; - const timeDelta = getTimeDifferenceInDaysFromToday(currentPolicy ? currentPolicy?.[0]?.expiryDate : null); - const policyStatusLabel = currentPolicy ? this.getPolicyStatusLabel(timeDelta) : DEFAULT_LABEL; - const policyStatusLabelStyle = currentPolicy ? this.getPolicyStatusLabelStyle(timeDelta, classes) : classes.item; + const { policyInfoLabel, policyInfoStyle } = this.valuatePolicyValidity(currentPolicy); return ( - - + + diff --git a/src/constants.js b/src/constants.js index 747f541..536e5e9 100644 --- a/src/constants.js +++ b/src/constants.js @@ -42,6 +42,7 @@ export const RIGHT_RESTORE = 111012; export const CLAIMS_WITH_AT_LEAST_ENTERED_STATUS = 'status_Gt: 2'; export const DEFAULT_ADDITIONAL_DIAGNOSIS_NUMBER = 4; +export const POLICY_ACTIVE_STATUS = 2; export const DEFAULT = { IS_ADDITIONAL_PANEL_ENABLED: false, From 3006c406976119e250e1a8ee4c2cf0da6bef71eb Mon Sep 17 00:00:00 2001 From: olewandowski1 Date: Mon, 11 Mar 2024 14:05:46 +0100 Subject: [PATCH 2/2] OP-1792: sonar fix --- src/components/ClaimMasterPanelExt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ClaimMasterPanelExt.js b/src/components/ClaimMasterPanelExt.js index 517c61c..d9bea9f 100644 --- a/src/components/ClaimMasterPanelExt.js +++ b/src/components/ClaimMasterPanelExt.js @@ -93,7 +93,7 @@ class ClaimMasterPanelExt extends Component { valuatePolicyValidity = (currentPolicy) => { const { classes } = this.props; - if (!currentPolicy || !currentPolicy.length) { + if (!currentPolicy?.length) { return { policyInfoLabel: INACTIVE_LABEL, policyInfoStyle: classes.inactiveLabel }; }