@thecb/components 8.4.10 → 8.4.11-beta.0

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": "8.4.10",
3
+ "version": "8.4.11-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -14,28 +14,12 @@ export const createPartialAmountFormState = (
14
14
  blockPartialPaymentOverpay = false
15
15
  ) => {
16
16
  const formConfig = lineItems.reduce((acc, item) => {
17
- const validators = [
18
- required(),
19
- validateSum(
20
- numberGreaterThanOrEqualTo(minimum),
21
- lineItems
22
- .filter(lineItem => lineItem != item)
23
- .reduce((acc, curr) => [...acc, curr.id], [])
24
- )
25
- ];
26
- if (!!maximum) {
27
- validators.push(
28
- validateSum(
29
- numberLessThanOrEqualTo(maximum),
30
- lineItems
31
- .filter(lineItem => lineItem != item)
32
- .reduce((acc, curr) => [...acc, curr.id], [])
33
- )
34
- );
35
- }
36
- if (blockPartialPaymentOverpay) {
37
- validators.push(numberLessThanOrEqualTo(item.amount));
38
- }
17
+ const validators = createPartialAmountFormValidators(
18
+ lineItems,
19
+ maximum,
20
+ minimum,
21
+ blockPartialPaymentOverpay
22
+ );
39
23
  return {
40
24
  ...acc,
41
25
  [item.id]: {
@@ -54,3 +38,35 @@ export const createPartialAmountFormState = (
54
38
  partialAmountFormMapDispatchToProps: mapDispatchToProps
55
39
  };
56
40
  };
41
+
42
+ export const createPartialAmountFormValidators = (
43
+ lineItems,
44
+ maximum,
45
+ minimum = 1,
46
+ blockPartialPaymentOverpay = false
47
+ ) => {
48
+ const validators = [
49
+ required(),
50
+ validateSum(
51
+ numberGreaterThanOrEqualTo(minimum),
52
+ lineItems
53
+ .filter(lineItem => lineItem != item)
54
+ .reduce((acc, curr) => [...acc, curr.id], [])
55
+ )
56
+ ];
57
+ if (!!maximum) {
58
+ validators.push(
59
+ validateSum(
60
+ numberLessThanOrEqualTo(maximum),
61
+ lineItems
62
+ .filter(lineItem => lineItem != item)
63
+ .reduce((acc, curr) => [...acc, curr.id], [])
64
+ )
65
+ );
66
+ }
67
+ if (blockPartialPaymentOverpay) {
68
+ validators.push(numberLessThanOrEqualTo(item.amount));
69
+ }
70
+
71
+ return validators;
72
+ };
@@ -1,4 +1,11 @@
1
1
  import PartialAmountForm from "./PartialAmountForm";
2
- import { createPartialAmountFormState } from "./PartialAmountForm.state";
2
+ import {
3
+ createPartialAmountFormState,
4
+ createPartialAmountFormValidators
5
+ } from "./PartialAmountForm.state";
3
6
 
4
- export { PartialAmountForm, createPartialAmountFormState };
7
+ export {
8
+ PartialAmountForm,
9
+ createPartialAmountFormState,
10
+ createPartialAmountFormValidators
11
+ };