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

Commit db140e4

Browse files
committed
Follow up fixes for #99
- Fixed tooltip font for actions' menu - Changed condition for disabling "Update" button for edit-payment modals - Changed how ActionsMenu handles "disabled" property of its items.
1 parent 72bc207 commit db140e4

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

src/components/ActionsMenu/index.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ const Menu = ({ close, items, referenceElement, strategy }) => {
163163
} else if (item.separator) {
164164
return <div key={index} className={compStyles.separator} />;
165165
} else {
166-
let reasonsDisabled = item.checkDisabled?.();
167-
let disabled = !!item.disabled || !!reasonsDisabled;
166+
let disabled = !!item.disabled;
167+
let reasonsDisabled = Array.isArray(item.disabled)
168+
? item.disabled
169+
: null;
168170
let attrs = {
169171
key: index,
170172
"data-action-index": index,

src/components/Tooltip/styles.module.scss

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "styles/variables";
2+
@import "styles/mixins";
23

34
.container {
45
position: relative;
@@ -17,7 +18,9 @@
1718
padding: 10px 15px;
1819
line-height: 22px;
1920
font-size: $font-size-px;
21+
@include roboto-regular;
2022
font-weight: normal;
23+
letter-spacing: normal;
2124
text-transform: none;
2225
color: $text-color;
2326
background: #fff;

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import styles from "./styles.module.scss";
2121
const PaymentModalEdit = ({ daysPaid, daysWorked, payment, removeModal }) => {
2222
const [isModalOpen, setIsModalOpen] = useState(true);
2323
const [isProcessing, setIsProcessing] = useState(false);
24-
const [isTouched, setIsTouched] = useState(false);
2524
const [days, setDays] = useState(payment.days);
2625
const dispatch = useDispatch();
2726

27+
const isChanged = days !== payment.days;
2828
const { id: paymentId, workPeriodId: periodId } = payment;
2929

3030
const maxDays =
@@ -46,7 +46,6 @@ const PaymentModalEdit = ({ daysPaid, daysWorked, payment, removeModal }) => {
4646
}, []);
4747

4848
const onChangeDays = useCallback((days) => {
49-
setIsTouched(true);
5049
setDays(days);
5150
}, []);
5251

@@ -66,7 +65,7 @@ const PaymentModalEdit = ({ daysPaid, daysWorked, payment, removeModal }) => {
6665
return (
6766
<Modal
6867
approveColor="primary"
69-
approveDisabled={!isTouched || isProcessing}
68+
approveDisabled={!isChanged || isProcessing}
7069
approveText="Update"
7170
title="Edit Payment"
7271
controls={isProcessing ? null : undefined}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import styles from "./styles.module.scss";
1818
* @returns {JSX.Element}
1919
*/
2020
const PaymentModalEditAdditional = ({ payment, removeModal }) => {
21+
const paymentAmount = payment.amount + "";
2122
const [isModalOpen, setIsModalOpen] = useState(true);
22-
const [amount, setAmount] = useState(payment.amount);
23+
const [amount, setAmount] = useState(paymentAmount);
2324
const [isAmountValid, setIsAmountValid] = useState(true);
2425
const [isProcessing, setIsProcessing] = useState(false);
25-
const [isTouched, setIsTouched] = useState(false);
2626
const dispatch = useDispatch();
2727

28+
const isChanged = amount !== paymentAmount;
2829
const { id: paymentId, workPeriodId: periodId } = payment;
2930
const amountControlId = `edit_pmt_amt_${paymentId}`;
3031

@@ -41,7 +42,6 @@ const PaymentModalEditAdditional = ({ payment, removeModal }) => {
4142
}, []);
4243

4344
const onChangeAmount = useCallback((amount) => {
44-
setIsTouched(true);
4545
setAmount(amount);
4646
}, []);
4747

@@ -77,7 +77,7 @@ const PaymentModalEditAdditional = ({ payment, removeModal }) => {
7777
return (
7878
<Modal
7979
approveColor="primary"
80-
approveDisabled={!isTouched || !isAmountValid || isProcessing}
80+
approveDisabled={!isChanged || !isAmountValid || isProcessing}
8181
approveText="Update"
8282
title="Edit Additional Payment"
8383
controls={isProcessing ? null : undefined}
@@ -102,7 +102,7 @@ const PaymentModalEditAdditional = ({ payment, removeModal }) => {
102102
isAmountValid ? null : ERROR_MESSAGE.AMOUNT_OUT_OF_BOUNDS
103103
}
104104
id={amountControlId}
105-
isTouched={isTouched}
105+
isTouched={isChanged}
106106
name="edit_payment_amount"
107107
onChange={onChangeAmount}
108108
value={amount}

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

+18-16
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,20 @@ const PeriodActions = ({ className, period, periodData }) => {
3737
action() {
3838
setIsOpenAddPaymentModal(true);
3939
},
40-
checkDisabled() {
41-
let reasonsDisabled = [];
42-
if (moment(period.start).isAfter(Date.now())) {
43-
reasonsDisabled.push(
44-
REASON_DISABLED_MESSAGE_MAP[REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK]
45-
);
46-
}
47-
if (!period.billingAccountId) {
48-
reasonsDisabled.push(
49-
REASON_DISABLED_MESSAGE_MAP[REASON_DISABLED.NO_BILLING_ACCOUNT]
50-
);
51-
}
52-
return reasonsDisabled.length ? reasonsDisabled : null;
53-
},
40+
disabled: checkDisabled(period),
5441
},
5542
];
5643
if (payments?.length) {
57-
// @ts-ignore
5844
actions.push({
5945
label: "Update BA for payments",
6046
action() {
6147
setIsOpenUpdateBAModal(true);
6248
},
49+
disabled: false,
6350
});
6451
}
6552
return actions;
66-
}, [period.billingAccountId, period.start, payments]);
53+
}, [period, payments]);
6754

6855
return (
6956
<div className={cn(styles.container, className)}>
@@ -103,3 +90,18 @@ PeriodActions.propTypes = {
10390
};
10491

10592
export default PeriodActions;
93+
94+
function checkDisabled(period) {
95+
let reasonsDisabled = [];
96+
if (moment(period.start).isAfter(Date.now())) {
97+
reasonsDisabled.push(
98+
REASON_DISABLED_MESSAGE_MAP[REASON_DISABLED.NOT_ALLOW_FUTURE_WEEK]
99+
);
100+
}
101+
if (!period.billingAccountId) {
102+
reasonsDisabled.push(
103+
REASON_DISABLED_MESSAGE_MAP[REASON_DISABLED.NO_BILLING_ACCOUNT]
104+
);
105+
}
106+
return reasonsDisabled.length ? reasonsDisabled : false;
107+
}

0 commit comments

Comments
 (0)