@thecb/components 7.11.0-beta.3 → 7.11.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "7.11.0-beta.3",
3
+ "version": "7.11.0-beta.5",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -47,7 +47,10 @@ const PartialAmountForm = ({
47
47
  maxAmount
48
48
  )}`;
49
49
  console.log("max amount in form is", maxAmount);
50
- errorMessages[numberLessThanOrEqualTo.error] = maxAmountError;
50
+ return {
51
+ ...errorMessages,
52
+ [numberLessThanOrEqualTo.error]: maxAmountError
53
+ };
51
54
  }
52
55
  console.log("error messages are", errorMessages);
53
56
  return errorMessages;
@@ -13,14 +13,17 @@ export const createPartialAmountFormState = (
13
13
  minimum = 1,
14
14
  blockPartialPaymentOverpay = false
15
15
  ) => {
16
+ const getPaymentMax = (maximum, itemAmount) => {
17
+ if (blockPartialPaymentOverpay) {
18
+ return !maximum || itemAmount < maximum ? itemAmount : maximum;
19
+ }
20
+ return maximum;
21
+ };
16
22
  const formConfig = lineItems.reduce((acc, item) => {
17
23
  console.log("maximum is", maximum);
18
24
  console.log("item amount is", item.amount);
19
25
  console.log("block payment overpay", blockPartialPaymentOverpay);
20
- let paymentMax = maximum;
21
- if (blockPartialPaymentOverpay) {
22
- paymentMax = !maximum || item.amount < maximum ? item.amount : maximum;
23
- }
26
+
24
27
  console.log("payment max is", paymentMax);
25
28
  const validators = [
26
29
  required(),
@@ -34,7 +37,7 @@ export const createPartialAmountFormState = (
34
37
  if (!!maximum || blockPartialPaymentOverpay) {
35
38
  validators.push(
36
39
  validateSum(
37
- numberLessThanOrEqualTo(paymentMax),
40
+ numberLessThanOrEqualTo(getPaymentMax(maximum, item.amount)),
38
41
  lineItems
39
42
  .filter(lineItem => lineItem != item)
40
43
  .reduce((acc, curr) => [...acc, curr.id], [])