@@ -12,7 +12,10 @@ import PaymentStatus from "../PaymentStatus";
12
12
import PaymentTotal from "../PaymentTotal" ;
13
13
import PeriodWorkingDays from "../PeriodWorkingDays" ;
14
14
import PeriodDetails from "../PeriodDetails" ;
15
- import { PAYMENT_STATUS } from "constants/workPeriods" ;
15
+ import {
16
+ PAYMENT_STATUS ,
17
+ REASON_DISABLED_MESSAGE_MAP ,
18
+ } from "constants/workPeriods" ;
16
19
import {
17
20
setWorkPeriodWorkingDays ,
18
21
toggleWorkingDaysUpdated ,
@@ -37,6 +40,7 @@ import styles from "./styles.module.scss";
37
40
* @param {Object } props.item object describing a working period
38
41
* @param {Object } props.data changeable working period data such as working days
39
42
* @param {Object } [props.details] object with working period details
43
+ * @param {Array } [props.reasonsDisabled] array of REASON_DISABLED values.
40
44
* @returns {JSX.Element }
41
45
*/
42
46
const PeriodItem = ( {
@@ -46,6 +50,7 @@ const PeriodItem = ({
46
50
item,
47
51
data,
48
52
details,
53
+ reasonsDisabled,
49
54
} ) => {
50
55
const dispatch = useDispatch ( ) ;
51
56
@@ -107,6 +112,15 @@ const PeriodItem = ({
107
112
[ item . projectId ]
108
113
) ;
109
114
115
+ const reasonsDisabledElement = useMemo (
116
+ ( ) => (
117
+ < span className = { styles . tooltipContent } >
118
+ { formatReasonsDisabled ( reasonsDisabled ) }
119
+ </ span >
120
+ ) ,
121
+ [ reasonsDisabled ]
122
+ ) ;
123
+
110
124
return (
111
125
< >
112
126
< tr
@@ -117,15 +131,22 @@ const PeriodItem = ({
117
131
onClick = { onToggleItemDetails }
118
132
>
119
133
< td className = { styles . toggle } >
120
- < Checkbox
121
- size = "small"
122
- isDisabled = { isDisabled }
123
- checked = { isSelected }
124
- name = { `wp_chb_${ item . id } ` }
125
- onChange = { onToggleItem }
126
- option = { { value : item . id } }
127
- stopClickPropagation = { true }
128
- />
134
+ < Tooltip
135
+ content = { reasonsDisabledElement }
136
+ isDisabled = { ! reasonsDisabled }
137
+ strategy = "fixed"
138
+ targetClassName = { styles . checkboxContainer }
139
+ >
140
+ < Checkbox
141
+ size = "small"
142
+ isDisabled = { isDisabled || ! ! reasonsDisabled }
143
+ checked = { isSelected }
144
+ name = { `wp_chb_${ item . id } ` }
145
+ onChange = { onToggleItem }
146
+ option = { { value : item . id } }
147
+ stopClickPropagation = { true }
148
+ />
149
+ </ Tooltip >
129
150
</ td >
130
151
< td className = { styles . userHandle } >
131
152
< Tooltip
@@ -235,6 +256,27 @@ PeriodItem.propTypes = {
235
256
periods : PT . array . isRequired ,
236
257
periodsIsLoading : PT . bool . isRequired ,
237
258
} ) ,
259
+ reasonsDisabled : PT . arrayOf ( PT . string ) ,
238
260
} ;
239
261
240
262
export default memo ( PeriodItem ) ;
263
+
264
+ /**
265
+ * Returns a string produced by concatenation of all provided reasons some
266
+ * working period is disabled.
267
+ *
268
+ * @param {Array } reasonIds array of REASON_DISABLED values
269
+ * @returns {?Array }
270
+ */
271
+ function formatReasonsDisabled ( reasonIds ) {
272
+ if ( ! reasonIds ) {
273
+ return null ;
274
+ }
275
+ const reasons = [ ] ;
276
+ reasons . push ( REASON_DISABLED_MESSAGE_MAP [ reasonIds [ 0 ] ] ) ;
277
+ for ( let i = 1 , len = reasonIds . length ; i < len ; i ++ ) {
278
+ reasons . push ( < br /> ) ;
279
+ reasons . push ( REASON_DISABLED_MESSAGE_MAP [ reasonIds [ i ] ] ) ;
280
+ }
281
+ return reasons ;
282
+ }
0 commit comments