Skip to content

Commit

Permalink
refactor(use check lock status): change org unit checker fn name to r…
Browse files Browse the repository at this point in the history
…eflect the check
  • Loading branch information
Mohammer5 committed Jun 7, 2023
1 parent f6739d3 commit 3b00623
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/shared/locked-status/use-check-lock-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
usePeriodId,
useDataSetId,
useOrgUnitId,
} from '../use-context-selection/use-context-selection.js'
} from '../use-context-selection/index.js'
import { useDataValueSet } from '../use-data-value-set/use-data-value-set.js'
import { useOrgUnit } from '../use-org-unit/use-organisation-unit.js'
import { LockedStates, BackendLockStatusMap } from './locked-states.js'
Expand Down Expand Up @@ -38,7 +38,17 @@ const isDataInputPeriodLocked = ({
)
}

const isOrgUnitLocked = ({
/**
* An org unit is locked not based on the current date,
* but based on the selected period.
*
* -> If org unit's close date is before the period's end date,
* then the user is not allowed to modify data.
*
* -> If the org unit's open date is after the period's start date,
* then the user is not allowed to modify data.
*/
const isOrgUnitTimeConstraintWithinDataInputPeriodConstraint = ({
orgUnitOpeningDateString,
orgUnitClosedDateString,
selectedPeriod,
Expand All @@ -61,15 +71,15 @@ const isOrgUnitLocked = ({
// if orgUnitOpeningDate exists, it must be earlier than the periodStartDate
if (orgUnitOpeningDateString) {
const orgUnitOpeningDate = new Date(orgUnitOpeningDateString)
if (!(orgUnitOpeningDate <= periodStartDate)) {
if (orgUnitOpeningDate > periodStartDate) {
return true
}
}

// if orgUnitClosedDate exists, it must be after the periodEndDate
if (orgUnitClosedDateString) {
const orgUnitClosedDate = new Date(orgUnitClosedDateString)
if (!(orgUnitClosedDate >= periodEndDate)) {
if (orgUnitClosedDate < periodEndDate) {
return true
}
}
Expand Down Expand Up @@ -112,7 +122,7 @@ export const useCheckLockStatus = () => {
}

if (
isOrgUnitLocked({
isOrgUnitTimeConstraintWithinDataInputPeriodConstraint({
orgUnitOpeningDateString,
orgUnitClosedDateString,
selectedPeriod,
Expand Down

0 comments on commit 3b00623

Please sign in to comment.