Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

fix:issue #73 #76

Merged
merged 1 commit into from
Jul 21, 2021
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
2 changes: 2 additions & 0 deletions src/constants/workPeriods.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export const REASON_DISABLED_MESSAGE_MAP = {
"Billing Account is not set for the Resource Booking",
[REASON_DISABLED.NO_DAYS_TO_PAY_FOR]: "There are no days to pay for",
[REASON_DISABLED.NO_MEMBER_RATE]: "Member Rate should be greater than 0",
[REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK]:
"Not allow processing payments for the future weeks",
};

export const ALERT_MESSAGE_MAP = {
Expand Down
1 change: 1 addition & 0 deletions src/constants/workPeriods/reasonDisabled.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const NO_BILLING_ACCOUNT = "NO_BILLING_ACCOUNT";
export const NO_DAYS_TO_PAY_FOR = "NO_DAYS_TO_PAY_FOR";
export const NO_MEMBER_RATE = "NO_MEMBER_RATE";
export const NOT_ALLOW_FUTURE_WEEK = "NOT_ALLOW_FUTURE_WEEK";
46 changes: 39 additions & 7 deletions src/routes/WorkPeriods/components/PeriodListHead/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React, { useCallback } from "react";
import React, { useCallback, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import Tooltip from "components/Tooltip";
import cn from "classnames";
import moment from "moment";
import Checkbox from "components/Checkbox";
import SortingControl from "components/SortingControl";
import { SORT_BY } from "constants/workPeriods";
import {
REASON_DISABLED,
REASON_DISABLED_MESSAGE_MAP,
} from "constants/workPeriods"
import {
getWorkPeriodsDateRange,
getWorkPeriodsIsSelectedVisible,
getWorkPeriodsSorting,
} from "store/selectors/workPeriods";
Expand All @@ -24,6 +31,7 @@ import styles from "./styles.module.scss";
const PeriodListHead = () => {
const sorting = useSelector(getWorkPeriodsSorting);
const isSelectedVisible = useSelector(getWorkPeriodsIsSelectedVisible);
const periodsDateRange = useSelector(getWorkPeriodsDateRange);
const dispatch = useDispatch();
const { criteria, order } = sorting;

Expand All @@ -39,16 +47,40 @@ const PeriodListHead = () => {
dispatch(toggleWorkingPeriodsVisible());
}, [dispatch]);

const reasonsDisabled = useMemo(()=> {
if (periodsDateRange[0].isAfter(moment())) {
return REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK;
}
return null
}, [periodsDateRange])

const reasonsDisabledElement = useMemo(
() => (
<div className={styles.tooltipContent}>
{reasonsDisabled && REASON_DISABLED_MESSAGE_MAP[reasonsDisabled]}
</div>
),
[reasonsDisabled]
);

return (
<tr className={styles.container}>
<th>
<div className={styles.colHead}>
<Checkbox
size="small"
name={"visible_periods_selected"}
onChange={onToggleVisible}
checked={isSelectedVisible}
/>
<Tooltip
content={reasonsDisabledElement}
isDisabled={!reasonsDisabled}
strategy="fixed"
targetClassName={styles.checkboxContainer}
>
<Checkbox
size="small"
isDisabled={!!reasonsDisabled}
name={"visible_periods_selected"}
onChange={onToggleVisible}
checked={isSelectedVisible}
/>
</Tooltip>
</div>
</th>
{HEAD_CELLS.map(({ id, className, label, disableSort }) => (
Expand Down
2 changes: 1 addition & 1 deletion src/store/reducers/workPeriods.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const actionHandlers = {
periodEnd
);
periodsData[period.id] = periodData;
let reasonsDisabled = findReasonsDisabled(period);
let reasonsDisabled = findReasonsDisabled(period, dateRange);
if (reasonsDisabled) {
periodsDisabledMap.set(period.id, reasonsDisabled);
}
Expand Down
8 changes: 7 additions & 1 deletion src/utils/workPeriods.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ export function createPeriodAlerts(period, periodEnd) {
* payment processing.
*
* @param {Object} period working period object
* @param {Array} dateRange date range array
* @returns {?string[]}
*/
export function findReasonsDisabled(period) {
export function findReasonsDisabled(period, dateRange) {
const reasons = [];
if (dateRange && dateRange.length > 0) {
if (dateRange[0].isAfter(moment())) {
reasons.push(REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK);
}
}
if (!period.billingAccountId) {
reasons.push(REASON_DISABLED.NO_BILLING_ACCOUNT);
}
Expand Down