@dmsi/wedgekit-react 0.0.131 → 0.0.133

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SelectPaymentMethod
3
- } from "./chunk-ZWEKVOHD.js";
3
+ } from "./chunk-EQQMFT5H.js";
4
4
  import {
5
5
  Modal
6
6
  } from "./chunk-D2YP2BTN.js";
@@ -28,15 +28,17 @@ import {
28
28
  import { useEffect, useMemo, useState } from "react";
29
29
  import { jsx, jsxs } from "react/jsx-runtime";
30
30
  function PaymentOnAccountModal(props) {
31
- const { isOpen, paymentProps, onClose } = props;
31
+ const { isOpen, paymentProps, onClose, onAmountChange } = props;
32
32
  const [amount, setAmount] = useState(paymentProps.amountToPay);
33
33
  const { creditCardSettings, selectedMethod } = paymentProps;
34
34
  useEffect(() => {
35
35
  setAmount(paymentProps.amountToPay);
36
36
  }, [paymentProps.amountToPay]);
37
37
  function handleAmountChange(event) {
38
- const value = event.target.value.replace(/[^0-9.-]+/g, "");
39
- setAmount(+value || 0);
38
+ const inputValue = event.target.value.replace(/[^0-9.-]+/g, "");
39
+ const value = +inputValue || 0;
40
+ setAmount(value);
41
+ onAmountChange == null ? void 0 : onAmountChange(value);
40
42
  }
41
43
  const creditCardSurcharge = useMemo(() => {
42
44
  const applySurcharge = (creditCardSettings == null ? void 0 : creditCardSettings.ApplySurcharge) || false;
@@ -27,10 +27,11 @@ import {
27
27
  } from "./chunk-H6LXXGX6.js";
28
28
 
29
29
  // src/components/SelectPaymentMethod.tsx
30
- import { useState } from "react";
30
+ import { useEffect, useState } from "react";
31
31
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
32
32
  function SelectPaymentMethod(props) {
33
33
  const {
34
+ amountToPay,
34
35
  selectedMethod,
35
36
  onSelectMethod,
36
37
  selectedCredits,
@@ -43,6 +44,14 @@ function SelectPaymentMethod(props) {
43
44
  isPayLoading,
44
45
  withCredits = false
45
46
  } = props;
47
+ const payAllWithCredits = withCredits && amountToPay <= 0;
48
+ useEffect(() => {
49
+ if (payAllWithCredits) {
50
+ onSelectMethod("CreditsOnly");
51
+ } else {
52
+ onSelectMethod("ACHPayment");
53
+ }
54
+ }, [payAllWithCredits]);
46
55
  function handleToggle(method) {
47
56
  onSelectMethod(method);
48
57
  }
@@ -66,26 +75,32 @@ function SelectPaymentMethod(props) {
66
75
  }),
67
76
  customerBanks: customerBanks || [],
68
77
  onPay,
69
- isPayLoading: isPayLoading || false
78
+ isPayLoading: isPayLoading || false,
79
+ disabled: payAllWithCredits
70
80
  }
71
81
  ),
72
82
  (allowedMethods == null ? void 0 : allowedMethods.includes("CCPayment")) && /* @__PURE__ */ jsx(
73
83
  Accordion,
74
84
  {
75
- isOpen: selectedMethod === "CCPayment",
85
+ isOpen: !payAllWithCredits && selectedMethod === "CCPayment",
76
86
  title: /* @__PURE__ */ jsx(
77
87
  Radio,
78
88
  {
79
89
  label: "Pay by Credit/Debit Card",
80
- checked: selectedMethod === "CCPayment",
81
- onClick: (e) => e.preventDefault()
90
+ checked: !payAllWithCredits && selectedMethod === "CCPayment",
91
+ onChange: (e) => e.stopPropagation(),
92
+ disabled: amountToPay <= 0
82
93
  }
83
94
  ),
84
- onClick: () => handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment"),
95
+ onClick: () => {
96
+ if (payAllWithCredits) return;
97
+ handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment");
98
+ },
85
99
  children: /* @__PURE__ */ jsx(Button, { className: "w-full", onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Proceed to Payment" })
86
100
  }
87
101
  ),
88
- selectedMethod === "ACHPayment" && /* @__PURE__ */ jsx(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
102
+ selectedMethod === "ACHPayment" && /* @__PURE__ */ jsx(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" }),
103
+ payAllWithCredits && /* @__PURE__ */ jsx(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
89
104
  ] });
90
105
  }
91
106
  function ACHSelector(props) {
@@ -94,9 +109,11 @@ function ACHSelector(props) {
94
109
  handleToggle,
95
110
  selectedBankGuid,
96
111
  setSelectedBankGuid,
97
- customerBanks
112
+ customerBanks,
113
+ disabled
98
114
  } = props;
99
115
  function handleBankSelect(e, bankGuid) {
116
+ if (disabled) return;
100
117
  e.stopPropagation();
101
118
  setSelectedBankGuid(bankGuid);
102
119
  handleToggle("ACHPayment");
@@ -105,12 +122,14 @@ function ACHSelector(props) {
105
122
  Card,
106
123
  {
107
124
  onClick: (e) => handleBankSelect(e, bank.CustBankGUID),
108
- selected: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
125
+ selected: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
109
126
  children: /* @__PURE__ */ jsx(
110
127
  Radio,
111
128
  {
112
129
  label: `Pay by ${bank.AccountDisplayString}`,
113
- checked: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID
130
+ checked: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
131
+ disabled,
132
+ onChange: (e) => e.stopPropagation()
114
133
  }
115
134
  )
116
135
  },
@@ -169,7 +188,9 @@ function CreditsSelector(props) {
169
188
  ),
170
189
  /* @__PURE__ */ jsxs(Subheader, { className: " pr-desktop-component-padding", children: [
171
190
  "$",
172
- formatCurrencyDisplay(`${Math.abs(credits.InvoiceBalance)}`)
191
+ formatCurrencyDisplay(
192
+ `${Math.abs(credits.InvoiceBalanceDue)}`
193
+ )
173
194
  ] })
174
195
  ]
175
196
  },
@@ -1903,6 +1903,7 @@ function HorizontalDivider({ id, hideOnMobile }) {
1903
1903
  var import_jsx_runtime19 = require("react/jsx-runtime");
1904
1904
  function SelectPaymentMethod(props) {
1905
1905
  const {
1906
+ amountToPay,
1906
1907
  selectedMethod,
1907
1908
  onSelectMethod,
1908
1909
  selectedCredits,
@@ -1915,6 +1916,14 @@ function SelectPaymentMethod(props) {
1915
1916
  isPayLoading,
1916
1917
  withCredits = false
1917
1918
  } = props;
1919
+ const payAllWithCredits = withCredits && amountToPay <= 0;
1920
+ (0, import_react7.useEffect)(() => {
1921
+ if (payAllWithCredits) {
1922
+ onSelectMethod("CreditsOnly");
1923
+ } else {
1924
+ onSelectMethod("ACHPayment");
1925
+ }
1926
+ }, [payAllWithCredits]);
1918
1927
  function handleToggle(method) {
1919
1928
  onSelectMethod(method);
1920
1929
  }
@@ -1938,26 +1947,32 @@ function SelectPaymentMethod(props) {
1938
1947
  }),
1939
1948
  customerBanks: customerBanks || [],
1940
1949
  onPay,
1941
- isPayLoading: isPayLoading || false
1950
+ isPayLoading: isPayLoading || false,
1951
+ disabled: payAllWithCredits
1942
1952
  }
1943
1953
  ),
1944
1954
  (allowedMethods == null ? void 0 : allowedMethods.includes("CCPayment")) && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1945
1955
  Accordion,
1946
1956
  {
1947
- isOpen: selectedMethod === "CCPayment",
1957
+ isOpen: !payAllWithCredits && selectedMethod === "CCPayment",
1948
1958
  title: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1949
1959
  Radio,
1950
1960
  {
1951
1961
  label: "Pay by Credit/Debit Card",
1952
- checked: selectedMethod === "CCPayment",
1953
- onClick: (e) => e.preventDefault()
1962
+ checked: !payAllWithCredits && selectedMethod === "CCPayment",
1963
+ onChange: (e) => e.stopPropagation(),
1964
+ disabled: amountToPay <= 0
1954
1965
  }
1955
1966
  ),
1956
- onClick: () => handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment"),
1967
+ onClick: () => {
1968
+ if (payAllWithCredits) return;
1969
+ handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment");
1970
+ },
1957
1971
  children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { className: "w-full", onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Proceed to Payment" })
1958
1972
  }
1959
1973
  ),
1960
- selectedMethod === "ACHPayment" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
1974
+ selectedMethod === "ACHPayment" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" }),
1975
+ payAllWithCredits && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
1961
1976
  ] });
1962
1977
  }
1963
1978
  function ACHSelector(props) {
@@ -1966,9 +1981,11 @@ function ACHSelector(props) {
1966
1981
  handleToggle,
1967
1982
  selectedBankGuid,
1968
1983
  setSelectedBankGuid,
1969
- customerBanks
1984
+ customerBanks,
1985
+ disabled
1970
1986
  } = props;
1971
1987
  function handleBankSelect(e, bankGuid) {
1988
+ if (disabled) return;
1972
1989
  e.stopPropagation();
1973
1990
  setSelectedBankGuid(bankGuid);
1974
1991
  handleToggle("ACHPayment");
@@ -1977,12 +1994,14 @@ function ACHSelector(props) {
1977
1994
  Card,
1978
1995
  {
1979
1996
  onClick: (e) => handleBankSelect(e, bank.CustBankGUID),
1980
- selected: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
1997
+ selected: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
1981
1998
  children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1982
1999
  Radio,
1983
2000
  {
1984
2001
  label: `Pay by ${bank.AccountDisplayString}`,
1985
- checked: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID
2002
+ checked: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
2003
+ disabled,
2004
+ onChange: (e) => e.stopPropagation()
1986
2005
  }
1987
2006
  )
1988
2007
  },
@@ -2041,7 +2060,9 @@ function CreditsSelector(props) {
2041
2060
  ),
2042
2061
  /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(Subheader, { className: " pr-desktop-component-padding", children: [
2043
2062
  "$",
2044
- formatCurrencyDisplay(`${Math.abs(credits.InvoiceBalance)}`)
2063
+ formatCurrencyDisplay(
2064
+ `${Math.abs(credits.InvoiceBalanceDue)}`
2065
+ )
2045
2066
  ] })
2046
2067
  ]
2047
2068
  },
@@ -2057,15 +2078,17 @@ function CreditsSelector(props) {
2057
2078
  // src/components/PaymentOnAccountModal.tsx
2058
2079
  var import_jsx_runtime20 = require("react/jsx-runtime");
2059
2080
  function PaymentOnAccountModal(props) {
2060
- const { isOpen, paymentProps, onClose } = props;
2081
+ const { isOpen, paymentProps, onClose, onAmountChange } = props;
2061
2082
  const [amount, setAmount] = (0, import_react8.useState)(paymentProps.amountToPay);
2062
2083
  const { creditCardSettings, selectedMethod } = paymentProps;
2063
2084
  (0, import_react8.useEffect)(() => {
2064
2085
  setAmount(paymentProps.amountToPay);
2065
2086
  }, [paymentProps.amountToPay]);
2066
2087
  function handleAmountChange(event) {
2067
- const value = event.target.value.replace(/[^0-9.-]+/g, "");
2068
- setAmount(+value || 0);
2088
+ const inputValue = event.target.value.replace(/[^0-9.-]+/g, "");
2089
+ const value = +inputValue || 0;
2090
+ setAmount(value);
2091
+ onAmountChange == null ? void 0 : onAmountChange(value);
2069
2092
  }
2070
2093
  const creditCardSurcharge = (0, import_react8.useMemo)(() => {
2071
2094
  const applySurcharge = (creditCardSettings == null ? void 0 : creditCardSettings.ApplySurcharge) || false;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  PaymentOnAccountModal,
3
3
  calculateSurcharge
4
- } from "../chunk-QLD6SOEU.js";
5
- import "../chunk-ZWEKVOHD.js";
4
+ } from "../chunk-DIMHNC5S.js";
5
+ import "../chunk-EQQMFT5H.js";
6
6
  import "../chunk-TTO4PL7Y.js";
7
7
  import "../chunk-D2YP2BTN.js";
8
8
  import "../chunk-4RJKB7LC.js";
@@ -971,6 +971,7 @@ function HorizontalDivider({ id, hideOnMobile }) {
971
971
  var import_jsx_runtime11 = require("react/jsx-runtime");
972
972
  function SelectPaymentMethod(props) {
973
973
  const {
974
+ amountToPay,
974
975
  selectedMethod,
975
976
  onSelectMethod,
976
977
  selectedCredits,
@@ -983,6 +984,14 @@ function SelectPaymentMethod(props) {
983
984
  isPayLoading,
984
985
  withCredits = false
985
986
  } = props;
987
+ const payAllWithCredits = withCredits && amountToPay <= 0;
988
+ (0, import_react.useEffect)(() => {
989
+ if (payAllWithCredits) {
990
+ onSelectMethod("CreditsOnly");
991
+ } else {
992
+ onSelectMethod("ACHPayment");
993
+ }
994
+ }, [payAllWithCredits]);
986
995
  function handleToggle(method) {
987
996
  onSelectMethod(method);
988
997
  }
@@ -1006,26 +1015,32 @@ function SelectPaymentMethod(props) {
1006
1015
  }),
1007
1016
  customerBanks: customerBanks || [],
1008
1017
  onPay,
1009
- isPayLoading: isPayLoading || false
1018
+ isPayLoading: isPayLoading || false,
1019
+ disabled: payAllWithCredits
1010
1020
  }
1011
1021
  ),
1012
1022
  (allowedMethods == null ? void 0 : allowedMethods.includes("CCPayment")) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1013
1023
  Accordion,
1014
1024
  {
1015
- isOpen: selectedMethod === "CCPayment",
1025
+ isOpen: !payAllWithCredits && selectedMethod === "CCPayment",
1016
1026
  title: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1017
1027
  Radio,
1018
1028
  {
1019
1029
  label: "Pay by Credit/Debit Card",
1020
- checked: selectedMethod === "CCPayment",
1021
- onClick: (e) => e.preventDefault()
1030
+ checked: !payAllWithCredits && selectedMethod === "CCPayment",
1031
+ onChange: (e) => e.stopPropagation(),
1032
+ disabled: amountToPay <= 0
1022
1033
  }
1023
1034
  ),
1024
- onClick: () => handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment"),
1035
+ onClick: () => {
1036
+ if (payAllWithCredits) return;
1037
+ handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment");
1038
+ },
1025
1039
  children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Button, { className: "w-full", onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Proceed to Payment" })
1026
1040
  }
1027
1041
  ),
1028
- selectedMethod === "ACHPayment" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
1042
+ selectedMethod === "ACHPayment" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" }),
1043
+ payAllWithCredits && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
1029
1044
  ] });
1030
1045
  }
1031
1046
  function ACHSelector(props) {
@@ -1034,9 +1049,11 @@ function ACHSelector(props) {
1034
1049
  handleToggle,
1035
1050
  selectedBankGuid,
1036
1051
  setSelectedBankGuid,
1037
- customerBanks
1052
+ customerBanks,
1053
+ disabled
1038
1054
  } = props;
1039
1055
  function handleBankSelect(e, bankGuid) {
1056
+ if (disabled) return;
1040
1057
  e.stopPropagation();
1041
1058
  setSelectedBankGuid(bankGuid);
1042
1059
  handleToggle("ACHPayment");
@@ -1045,12 +1062,14 @@ function ACHSelector(props) {
1045
1062
  Card,
1046
1063
  {
1047
1064
  onClick: (e) => handleBankSelect(e, bank.CustBankGUID),
1048
- selected: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
1065
+ selected: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
1049
1066
  children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1050
1067
  Radio,
1051
1068
  {
1052
1069
  label: `Pay by ${bank.AccountDisplayString}`,
1053
- checked: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID
1070
+ checked: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
1071
+ disabled,
1072
+ onChange: (e) => e.stopPropagation()
1054
1073
  }
1055
1074
  )
1056
1075
  },
@@ -1109,7 +1128,9 @@ function CreditsSelector(props) {
1109
1128
  ),
1110
1129
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(Subheader, { className: " pr-desktop-component-padding", children: [
1111
1130
  "$",
1112
- formatCurrencyDisplay(`${Math.abs(credits.InvoiceBalance)}`)
1131
+ formatCurrencyDisplay(
1132
+ `${Math.abs(credits.InvoiceBalanceDue)}`
1133
+ )
1113
1134
  ] })
1114
1135
  ]
1115
1136
  },
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  SelectPaymentMethod
4
- } from "../chunk-ZWEKVOHD.js";
4
+ } from "../chunk-EQQMFT5H.js";
5
5
  import "../chunk-TTO4PL7Y.js";
6
6
  import "../chunk-3ZUSYRI7.js";
7
7
  import "../chunk-WT5XXW6G.js";
@@ -4428,6 +4428,7 @@ function HorizontalDivider({ id, hideOnMobile }) {
4428
4428
  var import_jsx_runtime33 = require("react/jsx-runtime");
4429
4429
  function SelectPaymentMethod(props) {
4430
4430
  const {
4431
+ amountToPay,
4431
4432
  selectedMethod,
4432
4433
  onSelectMethod,
4433
4434
  selectedCredits,
@@ -4440,6 +4441,14 @@ function SelectPaymentMethod(props) {
4440
4441
  isPayLoading,
4441
4442
  withCredits = false
4442
4443
  } = props;
4444
+ const payAllWithCredits = withCredits && amountToPay <= 0;
4445
+ (0, import_react20.useEffect)(() => {
4446
+ if (payAllWithCredits) {
4447
+ onSelectMethod("CreditsOnly");
4448
+ } else {
4449
+ onSelectMethod("ACHPayment");
4450
+ }
4451
+ }, [payAllWithCredits]);
4443
4452
  function handleToggle(method) {
4444
4453
  onSelectMethod(method);
4445
4454
  }
@@ -4463,26 +4472,32 @@ function SelectPaymentMethod(props) {
4463
4472
  }),
4464
4473
  customerBanks: customerBanks || [],
4465
4474
  onPay,
4466
- isPayLoading: isPayLoading || false
4475
+ isPayLoading: isPayLoading || false,
4476
+ disabled: payAllWithCredits
4467
4477
  }
4468
4478
  ),
4469
4479
  (allowedMethods == null ? void 0 : allowedMethods.includes("CCPayment")) && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4470
4480
  Accordion,
4471
4481
  {
4472
- isOpen: selectedMethod === "CCPayment",
4482
+ isOpen: !payAllWithCredits && selectedMethod === "CCPayment",
4473
4483
  title: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4474
4484
  Radio,
4475
4485
  {
4476
4486
  label: "Pay by Credit/Debit Card",
4477
- checked: selectedMethod === "CCPayment",
4478
- onClick: (e) => e.preventDefault()
4487
+ checked: !payAllWithCredits && selectedMethod === "CCPayment",
4488
+ onChange: (e) => e.stopPropagation(),
4489
+ disabled: amountToPay <= 0
4479
4490
  }
4480
4491
  ),
4481
- onClick: () => handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment"),
4492
+ onClick: () => {
4493
+ if (payAllWithCredits) return;
4494
+ handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment");
4495
+ },
4482
4496
  children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Button, { className: "w-full", onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Proceed to Payment" })
4483
4497
  }
4484
4498
  ),
4485
- selectedMethod === "ACHPayment" && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
4499
+ selectedMethod === "ACHPayment" && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" }),
4500
+ payAllWithCredits && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Button, { block: true, onClick: onPay, disabled: isPayLoading, children: isPayLoading ? "Processing..." : "Submit Payment" })
4486
4501
  ] });
4487
4502
  }
4488
4503
  function ACHSelector(props) {
@@ -4491,9 +4506,11 @@ function ACHSelector(props) {
4491
4506
  handleToggle,
4492
4507
  selectedBankGuid,
4493
4508
  setSelectedBankGuid,
4494
- customerBanks
4509
+ customerBanks,
4510
+ disabled
4495
4511
  } = props;
4496
4512
  function handleBankSelect(e, bankGuid) {
4513
+ if (disabled) return;
4497
4514
  e.stopPropagation();
4498
4515
  setSelectedBankGuid(bankGuid);
4499
4516
  handleToggle("ACHPayment");
@@ -4502,12 +4519,14 @@ function ACHSelector(props) {
4502
4519
  Card,
4503
4520
  {
4504
4521
  onClick: (e) => handleBankSelect(e, bank.CustBankGUID),
4505
- selected: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
4522
+ selected: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
4506
4523
  children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4507
4524
  Radio,
4508
4525
  {
4509
4526
  label: `Pay by ${bank.AccountDisplayString}`,
4510
- checked: selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID
4527
+ checked: !disabled && selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID,
4528
+ disabled,
4529
+ onChange: (e) => e.stopPropagation()
4511
4530
  }
4512
4531
  )
4513
4532
  },
@@ -4566,7 +4585,9 @@ function CreditsSelector(props) {
4566
4585
  ),
4567
4586
  /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(Subheader, { className: " pr-desktop-component-padding", children: [
4568
4587
  "$",
4569
- formatCurrencyDisplay(`${Math.abs(credits.InvoiceBalance)}`)
4588
+ formatCurrencyDisplay(
4589
+ `${Math.abs(credits.InvoiceBalanceDue)}`
4590
+ )
4570
4591
  ] })
4571
4592
  ]
4572
4593
  },
@@ -4582,15 +4603,17 @@ function CreditsSelector(props) {
4582
4603
  // src/components/PaymentOnAccountModal.tsx
4583
4604
  var import_jsx_runtime34 = require("react/jsx-runtime");
4584
4605
  function PaymentOnAccountModal(props) {
4585
- const { isOpen, paymentProps, onClose } = props;
4606
+ const { isOpen, paymentProps, onClose, onAmountChange } = props;
4586
4607
  const [amount, setAmount] = (0, import_react21.useState)(paymentProps.amountToPay);
4587
4608
  const { creditCardSettings, selectedMethod } = paymentProps;
4588
4609
  (0, import_react21.useEffect)(() => {
4589
4610
  setAmount(paymentProps.amountToPay);
4590
4611
  }, [paymentProps.amountToPay]);
4591
4612
  function handleAmountChange(event) {
4592
- const value = event.target.value.replace(/[^0-9.-]+/g, "");
4593
- setAmount(+value || 0);
4613
+ const inputValue = event.target.value.replace(/[^0-9.-]+/g, "");
4614
+ const value = +inputValue || 0;
4615
+ setAmount(value);
4616
+ onAmountChange == null ? void 0 : onAmountChange(value);
4594
4617
  }
4595
4618
  const creditCardSurcharge = (0, import_react21.useMemo)(() => {
4596
4619
  const applySurcharge = (creditCardSettings == null ? void 0 : creditCardSettings.ApplySurcharge) || false;
@@ -6,8 +6,8 @@ import {
6
6
  } from "../chunk-Y4HUYAI5.js";
7
7
  import {
8
8
  PaymentOnAccountModal
9
- } from "../chunk-QLD6SOEU.js";
10
- import "../chunk-ZWEKVOHD.js";
9
+ } from "../chunk-DIMHNC5S.js";
10
+ import "../chunk-EQQMFT5H.js";
11
11
  import "../chunk-TTO4PL7Y.js";
12
12
  import "../chunk-D2YP2BTN.js";
13
13
  import "../chunk-4RJKB7LC.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dmsi/wedgekit-react",
3
3
  "private": false,
4
- "version": "0.0.131",
4
+ "version": "0.0.133",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup",
@@ -14,9 +14,10 @@ type PaymentOnAccountModalProps = {
14
14
  isOpen: boolean;
15
15
  onClose: () => void;
16
16
  paymentProps: SelectPaymentMethodProps;
17
+ onAmountChange?: (amount: number) => void;
17
18
  };
18
19
  export function PaymentOnAccountModal(props: PaymentOnAccountModalProps) {
19
- const { isOpen, paymentProps, onClose } = props;
20
+ const { isOpen, paymentProps, onClose, onAmountChange } = props;
20
21
  const [amount, setAmount] = useState<number>(paymentProps.amountToPay);
21
22
  const { creditCardSettings, selectedMethod } =
22
23
  paymentProps as typeof paymentProps & {
@@ -32,8 +33,10 @@ export function PaymentOnAccountModal(props: PaymentOnAccountModalProps) {
32
33
  }, [paymentProps.amountToPay]);
33
34
 
34
35
  function handleAmountChange(event: React.ChangeEvent<HTMLInputElement>) {
35
- const value = event.target.value.replace(/[^0-9.-]+/g, "");
36
- setAmount(+value || 0);
36
+ const inputValue = event.target.value.replace(/[^0-9.-]+/g, "");
37
+ const value = +inputValue || 0;
38
+ setAmount(value);
39
+ onAmountChange?.(value)
37
40
  }
38
41
 
39
42
  const creditCardSurcharge = useMemo(() => {
@@ -1,10 +1,9 @@
1
1
  "use client";
2
2
 
3
- import { useState } from "react";
3
+ import { useEffect, useState } from "react";
4
4
  import { Accordion } from "./Accordion";
5
5
  import { Button } from "./Button";
6
6
  import { Card } from "./Card";
7
- import { Paragraph } from "./Paragraph";
8
7
  import { Radio } from "./Radio";
9
8
  import { Stack } from "./Stack";
10
9
  import { Checkbox } from "./Checkbox";
@@ -12,7 +11,7 @@ import { Subheader } from "./Subheader";
12
11
  import { formatCurrencyDisplay } from "../utils/formatting";
13
12
  import { HorizontalDivider } from "./HorizontalDivider";
14
13
 
15
- export type PaymentMethodType = "ACHPayment" | "CCPayment";
14
+ export type PaymentMethodType = "ACHPayment" | "CCPayment" | "CreditsOnly";
16
15
  export type CustomerBank = {
17
16
  CustBankGUID: string;
18
17
  BankName: string;
@@ -38,9 +37,10 @@ export type SelectPaymentMethodProps = {
38
37
  setSelectedCredits?: React.Dispatch<React.SetStateAction<unknown[]>>;
39
38
  setSelectedACHBankGuid?: (guid: string | null) => void;
40
39
  };
41
- // TODO: Create story
40
+
42
41
  export function SelectPaymentMethod(props: SelectPaymentMethodProps) {
43
42
  const {
43
+ amountToPay,
44
44
  selectedMethod,
45
45
  onSelectMethod,
46
46
  selectedCredits,
@@ -54,6 +54,16 @@ export function SelectPaymentMethod(props: SelectPaymentMethodProps) {
54
54
  withCredits = false,
55
55
  } = props;
56
56
 
57
+ const payAllWithCredits = withCredits && amountToPay <= 0;
58
+
59
+ useEffect(() => {
60
+ if (payAllWithCredits) {
61
+ onSelectMethod("CreditsOnly");
62
+ } else {
63
+ onSelectMethod("ACHPayment");
64
+ }
65
+ }, [payAllWithCredits]);
66
+
57
67
  function handleToggle(method: PaymentMethodType | null) {
58
68
  onSelectMethod(method);
59
69
  }
@@ -75,21 +85,24 @@ export function SelectPaymentMethod(props: SelectPaymentMethodProps) {
75
85
  customerBanks={customerBanks || []}
76
86
  onPay={onPay}
77
87
  isPayLoading={isPayLoading || false}
88
+ disabled={payAllWithCredits}
78
89
  />
79
90
  )}
80
91
  {allowedMethods?.includes("CCPayment") && (
81
92
  <Accordion
82
- isOpen={selectedMethod === "CCPayment"}
93
+ isOpen={!payAllWithCredits && selectedMethod === "CCPayment"}
83
94
  title={
84
95
  <Radio
85
96
  label="Pay by Credit/Debit Card"
86
- checked={selectedMethod === "CCPayment"}
87
- onClick={(e) => e.preventDefault()}
97
+ checked={!payAllWithCredits && selectedMethod === "CCPayment"}
98
+ onChange={(e) => e.stopPropagation()}
99
+ disabled={amountToPay <= 0}
88
100
  />
89
101
  }
90
- onClick={() =>
91
- handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment")
92
- }
102
+ onClick={() => {
103
+ if (payAllWithCredits) return;
104
+ handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment");
105
+ }}
93
106
  >
94
107
  <Button className="w-full" onClick={onPay} disabled={isPayLoading}>
95
108
  {isPayLoading ? "Processing..." : "Proceed to Payment"}
@@ -102,6 +115,11 @@ export function SelectPaymentMethod(props: SelectPaymentMethodProps) {
102
115
  {isPayLoading ? "Processing..." : "Submit Payment"}
103
116
  </Button>
104
117
  )}
118
+ {payAllWithCredits && (
119
+ <Button block onClick={onPay} disabled={isPayLoading}>
120
+ {isPayLoading ? "Processing..." : "Submit Payment"}
121
+ </Button>
122
+ )}
105
123
  </Stack>
106
124
  );
107
125
  }
@@ -114,6 +132,7 @@ type ACHSelectorProps = {
114
132
  customerBanks: CustomerBank[];
115
133
  onPay?: () => void;
116
134
  isPayLoading?: boolean;
135
+ disabled?: boolean;
117
136
  };
118
137
  function ACHSelector(props: ACHSelectorProps) {
119
138
  const {
@@ -122,31 +141,45 @@ function ACHSelector(props: ACHSelectorProps) {
122
141
  selectedBankGuid,
123
142
  setSelectedBankGuid,
124
143
  customerBanks,
144
+ disabled,
125
145
  } = props;
126
146
 
127
147
  function handleBankSelect(
128
148
  e: React.MouseEvent<HTMLDivElement>,
129
149
  bankGuid: string | null,
130
150
  ) {
151
+ if (disabled) return;
131
152
  e.stopPropagation();
132
153
  setSelectedBankGuid(bankGuid);
133
154
  handleToggle("ACHPayment");
134
155
  }
135
156
 
136
- return <>
137
- {customerBanks.map((bank) => (
138
- <Card
139
- key={bank.CustBankGUID}
140
- onClick={(e) => handleBankSelect(e, bank.CustBankGUID)}
141
- selected={selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID}
142
- >
143
- <Radio
144
- label={`Pay by ${bank.AccountDisplayString}`}
145
- checked={selectedMethod === "ACHPayment" && selectedBankGuid === bank.CustBankGUID}
146
- />
147
- </Card>
148
- ))}
149
- </>;
157
+ return (
158
+ <>
159
+ {customerBanks.map((bank) => (
160
+ <Card
161
+ key={bank.CustBankGUID}
162
+ onClick={(e) => handleBankSelect(e, bank.CustBankGUID)}
163
+ selected={
164
+ !disabled &&
165
+ selectedMethod === "ACHPayment" &&
166
+ selectedBankGuid === bank.CustBankGUID
167
+ }
168
+ >
169
+ <Radio
170
+ label={`Pay by ${bank.AccountDisplayString}`}
171
+ checked={
172
+ !disabled &&
173
+ selectedMethod === "ACHPayment" &&
174
+ selectedBankGuid === bank.CustBankGUID
175
+ }
176
+ disabled={disabled}
177
+ onChange={(e) => e.stopPropagation()}
178
+ />
179
+ </Card>
180
+ ))}
181
+ </>
182
+ );
150
183
  }
151
184
  type CreditsSelectorProps = {
152
185
  selectedCredits: unknown[];
@@ -185,7 +218,7 @@ function CreditsSelector(props: CreditsSelectorProps) {
185
218
  allCredits as unknown as {
186
219
  InvoiceNumber: string;
187
220
  AROpenGUID: string;
188
- InvoiceBalance: number;
221
+ InvoiceBalanceDue: number;
189
222
  }[]
190
223
  ).map((credits) => (
191
224
  <Stack
@@ -209,7 +242,10 @@ function CreditsSelector(props: CreditsSelectorProps) {
209
242
  </Stack>
210
243
 
211
244
  <Subheader className=" pr-desktop-component-padding">
212
- ${formatCurrencyDisplay(`${Math.abs(credits.InvoiceBalance)}`)}
245
+ $
246
+ {formatCurrencyDisplay(
247
+ `${Math.abs(credits.InvoiceBalanceDue)}`,
248
+ )}
213
249
  </Subheader>
214
250
  </Stack>
215
251
  ))}