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

Commit 2046d6b

Browse files
committed
fix:issue #73
1 parent d8ed637 commit 2046d6b

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

src/constants/workPeriods.js

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export const REASON_DISABLED_MESSAGE_MAP = {
149149
"Billing Account is not set for the Resource Booking",
150150
[REASON_DISABLED.NO_DAYS_TO_PAY_FOR]: "There are no days to pay for",
151151
[REASON_DISABLED.NO_MEMBER_RATE]: "Member Rate should be greater than 0",
152+
[REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK]:
153+
"Not allow processing payments for the future weeks",
152154
};
153155

154156
export const ALERT_MESSAGE_MAP = {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const NO_BILLING_ACCOUNT = "NO_BILLING_ACCOUNT";
22
export const NO_DAYS_TO_PAY_FOR = "NO_DAYS_TO_PAY_FOR";
33
export const NO_MEMBER_RATE = "NO_MEMBER_RATE";
4+
export const NOT_ALLOW_FUTURE_WEEK = "NOT_ALLOW_FUTURE_WEEK";

src/routes/WorkPeriods/components/PeriodListHead/index.jsx

+39-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import React, { useCallback } from "react";
1+
import React, { useCallback, useMemo } from "react";
22
import { useDispatch, useSelector } from "react-redux";
3+
import Tooltip from "components/Tooltip";
34
import cn from "classnames";
5+
import moment from "moment";
46
import Checkbox from "components/Checkbox";
57
import SortingControl from "components/SortingControl";
68
import { SORT_BY } from "constants/workPeriods";
79
import {
10+
REASON_DISABLED,
11+
REASON_DISABLED_MESSAGE_MAP,
12+
} from "constants/workPeriods"
13+
import {
14+
getWorkPeriodsDateRange,
815
getWorkPeriodsIsSelectedVisible,
916
getWorkPeriodsSorting,
1017
} from "store/selectors/workPeriods";
@@ -24,6 +31,7 @@ import styles from "./styles.module.scss";
2431
const PeriodListHead = () => {
2532
const sorting = useSelector(getWorkPeriodsSorting);
2633
const isSelectedVisible = useSelector(getWorkPeriodsIsSelectedVisible);
34+
const periodsDateRange = useSelector(getWorkPeriodsDateRange);
2735
const dispatch = useDispatch();
2836
const { criteria, order } = sorting;
2937

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

50+
const reasonsDisabled = useMemo(()=> {
51+
if (periodsDateRange[0].isAfter(moment())) {
52+
return REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK;
53+
}
54+
return null
55+
}, [periodsDateRange])
56+
57+
const reasonsDisabledElement = useMemo(
58+
() => (
59+
<div className={styles.tooltipContent}>
60+
{reasonsDisabled && REASON_DISABLED_MESSAGE_MAP[reasonsDisabled]}
61+
</div>
62+
),
63+
[reasonsDisabled]
64+
);
65+
4266
return (
4367
<tr className={styles.container}>
4468
<th>
4569
<div className={styles.colHead}>
46-
<Checkbox
47-
size="small"
48-
name={"visible_periods_selected"}
49-
onChange={onToggleVisible}
50-
checked={isSelectedVisible}
51-
/>
70+
<Tooltip
71+
content={reasonsDisabledElement}
72+
isDisabled={!reasonsDisabled}
73+
strategy="fixed"
74+
targetClassName={styles.checkboxContainer}
75+
>
76+
<Checkbox
77+
size="small"
78+
isDisabled={!!reasonsDisabled}
79+
name={"visible_periods_selected"}
80+
onChange={onToggleVisible}
81+
checked={isSelectedVisible}
82+
/>
83+
</Tooltip>
5284
</div>
5385
</th>
5486
{HEAD_CELLS.map(({ id, className, label, disableSort }) => (

src/store/reducers/workPeriods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const actionHandlers = {
141141
periodEnd
142142
);
143143
periodsData[period.id] = periodData;
144-
let reasonsDisabled = findReasonsDisabled(period);
144+
let reasonsDisabled = findReasonsDisabled(period, dateRange);
145145
if (reasonsDisabled) {
146146
periodsDisabledMap.set(period.id, reasonsDisabled);
147147
}

src/utils/workPeriods.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ export function createPeriodAlerts(period, periodEnd) {
6363
* payment processing.
6464
*
6565
* @param {Object} period working period object
66+
* @param {Array} dateRange date range array
6667
* @returns {?string[]}
6768
*/
68-
export function findReasonsDisabled(period) {
69+
export function findReasonsDisabled(period, dateRange) {
6970
const reasons = [];
71+
if (dateRange && dateRange.length > 0) {
72+
if (dateRange[0].isAfter(moment())) {
73+
reasons.push(REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK);
74+
}
75+
}
7076
if (!period.billingAccountId) {
7177
reasons.push(REASON_DISABLED.NO_BILLING_ACCOUNT);
7278
}

0 commit comments

Comments
 (0)