@dmsi/wedgekit-react 0.0.161 → 0.0.163

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,112 +0,0 @@
1
- import {
2
- SelectPaymentMethod
3
- } from "./chunk-NT2ZKA4W.js";
4
- import {
5
- Modal
6
- } from "./chunk-FCREADUH.js";
7
- import {
8
- Input
9
- } from "./chunk-4T3DRGLF.js";
10
- import {
11
- formatCurrencyDisplay
12
- } from "./chunk-5UH6QUFB.js";
13
- import {
14
- Stack
15
- } from "./chunk-N6JVLYEE.js";
16
- import {
17
- Card
18
- } from "./chunk-4LXG6QNT.js";
19
- import {
20
- Paragraph
21
- } from "./chunk-HVI3CL7Y.js";
22
- import {
23
- __spreadProps,
24
- __spreadValues
25
- } from "./chunk-ORMEWXMH.js";
26
-
27
- // src/components/PaymentOnAccountModal.tsx
28
- import { useEffect, useMemo, useState } from "react";
29
- import { jsx, jsxs } from "react/jsx-runtime";
30
- function PaymentOnAccountModal(props) {
31
- const {
32
- isOpen,
33
- paymentProps,
34
- onClose,
35
- onAmountChange,
36
- cardPaymentUrl,
37
- setCardPaymentUrl,
38
- isLoadingCCiframe,
39
- testid
40
- } = props;
41
- const [amount, setAmount] = useState(paymentProps.amountToPay);
42
- const { creditCardSettings, selectedMethod } = paymentProps;
43
- useEffect(() => {
44
- setAmount(paymentProps.amountToPay);
45
- }, [paymentProps.amountToPay]);
46
- function handleAmountChange(event) {
47
- const inputValue = event.target.value.replace(/[^0-9.-]+/g, "");
48
- const value = +inputValue || 0;
49
- setAmount(value);
50
- onAmountChange == null ? void 0 : onAmountChange(value);
51
- }
52
- const creditCardSurcharge = useMemo(() => {
53
- const applySurcharge = (creditCardSettings == null ? void 0 : creditCardSettings.ApplySurcharge) || false;
54
- if (!applySurcharge || selectedMethod !== "CCPayment") {
55
- return 0;
56
- }
57
- const surchargeType = creditCardSettings == null ? void 0 : creditCardSettings.SurchargeBasisType;
58
- const surchargeRate = (creditCardSettings == null ? void 0 : creditCardSettings.SurchargeBasisAmount) || 0;
59
- if (surchargeType === "Percent") {
60
- return calculateSurcharge(amount, surchargeRate);
61
- }
62
- if (surchargeType === "Fixed") {
63
- return surchargeRate;
64
- }
65
- return 0;
66
- }, [creditCardSettings, amount, selectedMethod]);
67
- return /* @__PURE__ */ jsx(Modal, { testid, open: isOpen, onClose, title: "Payment on Account", children: /* @__PURE__ */ jsxs(Stack, { sizing: "layout-group", width: "full", children: [
68
- selectedMethod === "CCPayment" && /* @__PURE__ */ jsxs(Stack, { horizontal: true, justify: "between", items: "center", children: [
69
- /* @__PURE__ */ jsx(Paragraph, { children: "Surcharge" }),
70
- /* @__PURE__ */ jsxs(Paragraph, { testid: testid ? `${testid}-surcharge` : void 0, children: [
71
- "$",
72
- formatCurrencyDisplay(creditCardSurcharge.toFixed(2))
73
- ] })
74
- ] }),
75
- /* @__PURE__ */ jsx(Card, { className: "py-desktop-component-padding", children: /* @__PURE__ */ jsxs(Stack, { sizing: "component", justify: "between", items: "center", horizontal: true, children: [
76
- /* @__PURE__ */ jsx(Paragraph, { className: "w-full", children: "Amount to Pay" }),
77
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
78
- Input,
79
- {
80
- testid: testid ? `${testid}-amount-to-pay` : void 0,
81
- type: "number",
82
- placeholder: "$0.00",
83
- align: "right",
84
- value: amount === 0 ? "" : amount,
85
- onChange: handleAmountChange,
86
- before: "$"
87
- }
88
- ) })
89
- ] }) }),
90
- /* @__PURE__ */ jsx(
91
- SelectPaymentMethod,
92
- __spreadProps(__spreadValues({}, paymentProps), {
93
- testid: testid ? `${testid}-select-payment-method` : void 0,
94
- amountToPay: amount + creditCardSurcharge,
95
- cardPaymentUrl,
96
- setCardPaymentUrl,
97
- isLoadingCCiframe
98
- })
99
- )
100
- ] }) });
101
- }
102
- function calculateSurcharge(amountInDollars, surchargeRate) {
103
- const amountInCents = amountInDollars * 100;
104
- const surchargeInCents = amountInCents * surchargeRate / 100;
105
- const roundedSurchargeInCents = Math.round(surchargeInCents);
106
- return roundedSurchargeInCents / 100;
107
- }
108
-
109
- export {
110
- PaymentOnAccountModal,
111
- calculateSurcharge
112
- };