@thecb/components 7.11.0-beta.0 → 7.11.0-beta.2

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.0",
3
+ "version": "7.11.0-beta.2",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -18,6 +18,7 @@ const PartialAmountForm = ({
18
18
  lineItems,
19
19
  maximum,
20
20
  minimum = 1,
21
+ blockPartialPaymentOverpay,
21
22
  clearOnDismount,
22
23
  fields,
23
24
  actions,
@@ -37,6 +38,18 @@ const PartialAmountForm = ({
37
38
  )}`
38
39
  };
39
40
 
41
+ const getPartialAmountFormErrors = (maximum, itemAmount) => {
42
+ let errorMessages = amountErrors;
43
+ if (blockPartialPaymentOverpay) {
44
+ let maxAmount = !maximum || itemAmount < maximum ? itemAmount : maximum;
45
+ const maxAmountError = `There is a maximum payment of ${displayCurrency(
46
+ maxAmount
47
+ )}`;
48
+ errorMessages[numberLessThanOrEqualTo.error] = maxAmountError;
49
+ }
50
+ return errorMessages;
51
+ };
52
+
40
53
  const lineItemsNew = Array.isArray(lineItems) ? lineItems : [];
41
54
  return (
42
55
  <FormContainer variant={variant} role="form" aria-label="Other amount">
@@ -53,7 +66,7 @@ const PartialAmountForm = ({
53
66
  field={fields[li.id]}
54
67
  fieldActions={actions.fields[li.id]}
55
68
  showErrors={showErrors}
56
- errorMessages={amountErrors}
69
+ errorMessages={getPartialAmountFormErrors(maximum, li.amount)}
57
70
  style={{ textAlign: "right" }}
58
71
  placeholder="$0.00"
59
72
  formatter={moneyFormat}
@@ -14,6 +14,9 @@ export const createPartialAmountFormState = (
14
14
  blockPartialPaymentOverpay = false
15
15
  ) => {
16
16
  const formConfig = lineItems.reduce((acc, item) => {
17
+ console.log("maximum is", maximum);
18
+ console.log("item amount is", item.amount);
19
+ console.log("block payment overpay", blockPartialPaymentOverpay);
17
20
  let paymentMax = maximum;
18
21
  if (blockPartialPaymentOverpay) {
19
22
  paymentMax = !maximum || item.amount < maximum ? item.amount : maximum;
@@ -30,7 +33,7 @@ export const createPartialAmountFormState = (
30
33
  if (!!maximum || blockPartialPaymentOverpay) {
31
34
  validators.push(
32
35
  validateSum(
33
- numberLessThanOrEqualTo(maximum),
36
+ numberLessThanOrEqualTo(paymentMax),
34
37
  lineItems
35
38
  .filter(lineItem => lineItem != item)
36
39
  .reduce((acc, curr) => [...acc, curr.id], [])