@dmsi/wedgekit-react 0.0.161 → 0.0.162

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,22 +0,0 @@
1
- "use client";
2
- import {
3
- SelectPaymentMethod
4
- } from "../chunk-NT2ZKA4W.js";
5
- import "../chunk-WFGKIR5A.js";
6
- import "../chunk-BATIOCXB.js";
7
- import "../chunk-PLMGI5K5.js";
8
- import "../chunk-EPQLWHCL.js";
9
- import "../chunk-WFQEE2OO.js";
10
- import "../chunk-5UH6QUFB.js";
11
- import "../chunk-CYZL57LH.js";
12
- import "../chunk-WSS2DFTP.js";
13
- import "../chunk-N6JVLYEE.js";
14
- import "../chunk-4LXG6QNT.js";
15
- import "../chunk-HVI3CL7Y.js";
16
- import "../chunk-FKMKHLQH.js";
17
- import "../chunk-NKUETCDA.js";
18
- import "../chunk-RDLEIAQU.js";
19
- import "../chunk-ORMEWXMH.js";
20
- export {
21
- SelectPaymentMethod
22
- };
@@ -1,121 +0,0 @@
1
- import { Modal } from "./Modal";
2
- import { Stack } from "./Stack";
3
- import { Paragraph } from "./Paragraph";
4
- import { Input } from "./Input";
5
- import { Card } from "./Card";
6
- import { useEffect, useMemo, useState } from "react";
7
- import {
8
- SelectPaymentMethod,
9
- SelectPaymentMethodProps,
10
- } from "./SelectPaymentMethod";
11
- import { formatCurrencyDisplay } from "../utils/formatting";
12
-
13
- type PaymentOnAccountModalProps = {
14
- isOpen: boolean;
15
- onClose: () => void;
16
- paymentProps: SelectPaymentMethodProps;
17
- onAmountChange?: (amount: number) => void;
18
- cardPaymentUrl: string | null;
19
- setCardPaymentUrl: (url: string | null) => void;
20
- isLoadingCCiframe?: boolean;
21
- testid?: string;
22
- };
23
- export function PaymentOnAccountModal(props: PaymentOnAccountModalProps) {
24
- const {
25
- isOpen,
26
- paymentProps,
27
- onClose,
28
- onAmountChange,
29
- cardPaymentUrl,
30
- setCardPaymentUrl,
31
- isLoadingCCiframe,
32
- testid
33
- } = props;
34
- const [amount, setAmount] = useState<number>(paymentProps.amountToPay);
35
- const { creditCardSettings, selectedMethod } =
36
- paymentProps as typeof paymentProps & {
37
- creditCardSettings: {
38
- ApplySurcharge: boolean;
39
- SurchargeBasisType: string;
40
- SurchargeBasisAmount: number;
41
- };
42
- };
43
-
44
- useEffect(() => {
45
- setAmount(paymentProps.amountToPay);
46
- }, [paymentProps.amountToPay]);
47
-
48
- function handleAmountChange(event: React.ChangeEvent<HTMLInputElement>) {
49
- const inputValue = event.target.value.replace(/[^0-9.-]+/g, "");
50
- const value = +inputValue || 0;
51
- setAmount(value);
52
- onAmountChange?.(value);
53
- }
54
-
55
- const creditCardSurcharge = useMemo(() => {
56
- const applySurcharge = creditCardSettings?.ApplySurcharge || false;
57
- if (!applySurcharge || selectedMethod !== "CCPayment") {
58
- return 0;
59
- }
60
- const surchargeType = creditCardSettings?.SurchargeBasisType;
61
- const surchargeRate = creditCardSettings?.SurchargeBasisAmount || 0;
62
-
63
- if (surchargeType === "Percent") {
64
- return calculateSurcharge(amount, surchargeRate);
65
- }
66
- if (surchargeType === "Fixed") {
67
- return surchargeRate;
68
- }
69
- return 0;
70
- }, [creditCardSettings, amount, selectedMethod]);
71
-
72
- return (
73
- <Modal testid={testid} open={isOpen} onClose={onClose} title="Payment on Account">
74
- <Stack sizing="layout-group" width="full">
75
- {selectedMethod === "CCPayment" && (
76
- <Stack horizontal justify="between" items="center">
77
- <Paragraph>Surcharge</Paragraph>
78
- <Paragraph testid={testid ? `${testid}-surcharge` : undefined}>
79
- ${formatCurrencyDisplay(creditCardSurcharge.toFixed(2))}
80
- </Paragraph>
81
- </Stack>
82
- )}
83
- <Card className="py-desktop-component-padding">
84
- <Stack sizing="component" justify="between" items="center" horizontal>
85
- <Paragraph className="w-full">Amount to Pay</Paragraph>
86
- <div>
87
- <Input
88
- testid={testid ? `${testid}-amount-to-pay` : undefined}
89
- type="number"
90
- placeholder="$0.00"
91
- align="right"
92
- value={amount === 0 ? "" : amount}
93
- onChange={handleAmountChange}
94
- before={"$"}
95
- />
96
- </div>
97
- </Stack>
98
- </Card>
99
- <SelectPaymentMethod
100
- {...paymentProps}
101
- testid={testid ? `${testid}-select-payment-method` : undefined}
102
- amountToPay={amount + creditCardSurcharge}
103
- cardPaymentUrl={cardPaymentUrl}
104
- setCardPaymentUrl={setCardPaymentUrl}
105
- isLoadingCCiframe={isLoadingCCiframe}
106
- />
107
- </Stack>
108
- </Modal>
109
- );
110
- }
111
-
112
- export function calculateSurcharge(
113
- amountInDollars: number,
114
- surchargeRate: number,
115
- ): number {
116
- const amountInCents = amountInDollars * 100;
117
- const surchargeInCents = (amountInCents * surchargeRate) / 100;
118
- const roundedSurchargeInCents = Math.round(surchargeInCents);
119
-
120
- return roundedSurchargeInCents / 100;
121
- }
@@ -1,315 +0,0 @@
1
- "use client";
2
-
3
- import { useEffect, useState } from "react";
4
- import { Accordion } from "./Accordion";
5
- import { Button } from "./Button";
6
- import { Card } from "./Card";
7
- import { Radio } from "./Radio";
8
- import { Stack } from "./Stack";
9
- import { Checkbox } from "./Checkbox";
10
- import { Subheader } from "./Subheader";
11
- import { formatCurrencyDisplay, formatDecimalValue } from "../utils/formatting";
12
- import { HorizontalDivider } from "./HorizontalDivider";
13
- import { Spinner } from "./Spinner";
14
- import { WorldpayIframe } from "./WorldpayIframe";
15
-
16
- export type PaymentMethodType = "ACHPayment" | "CCPayment" | "CreditsOnly";
17
- export type CustomerBank = {
18
- CustBankGUID: string;
19
- BankName: string;
20
- AccountDisplayString: string;
21
- };
22
-
23
- export type SelectPaymentMethodProps = {
24
- amountToPay: number;
25
- selectedMethod: PaymentMethodType | null;
26
- allowedMethods: PaymentMethodType[];
27
- selectedCredits?: unknown[];
28
- selectedACHBankGuid?: string | null;
29
- customerBanks?: CustomerBank[];
30
- allCredits?: unknown[];
31
- isPayLoading?: boolean;
32
- selectedInvoices?: unknown[];
33
- allInvoices?: unknown[];
34
- creditCardSettings?: unknown;
35
- withCredits?: boolean;
36
- cardPaymentUrl?: string | null;
37
- isLoadingCCiframe?: boolean;
38
- testid?: string;
39
-
40
- setCardPaymentUrl?: (url: string | null) => void;
41
- onSelectMethod: (method: PaymentMethodType | null) => void;
42
- onPay: () => void;
43
- setSelectedCredits?: React.Dispatch<React.SetStateAction<unknown[]>>;
44
- setSelectedACHBankGuid?: (guid: string | null) => void;
45
- };
46
-
47
- export function SelectPaymentMethod(props: SelectPaymentMethodProps) {
48
- const {
49
- amountToPay,
50
- selectedMethod,
51
- onSelectMethod,
52
- selectedCredits,
53
- allCredits,
54
- allowedMethods,
55
- selectedACHBankGuid,
56
- setSelectedACHBankGuid,
57
- customerBanks,
58
- onPay,
59
- isPayLoading,
60
- withCredits = false,
61
- isLoadingCCiframe,
62
- cardPaymentUrl,
63
- testid,
64
- } = props;
65
-
66
- const payAllWithCredits = withCredits && amountToPay <= 0;
67
-
68
- useEffect(() => {
69
- if (payAllWithCredits) {
70
- onSelectMethod("CreditsOnly");
71
- } else {
72
- onSelectMethod(null);
73
- }
74
- }, [onSelectMethod, payAllWithCredits]);
75
-
76
- function handleToggle(method: PaymentMethodType | null) {
77
- onSelectMethod(method);
78
- }
79
- return (
80
- <Stack sizing="layout-group" width="full" minWidth={400}>
81
- {!!allCredits?.length && withCredits && (
82
- <CreditsSelector
83
- testid={testid ? `${testid}-credit-selector` : undefined}
84
- selectedCredits={selectedCredits || []}
85
- allCredits={allCredits || []}
86
- setSelectedCredits={props.setSelectedCredits || (() => {})}
87
- />
88
- )}
89
- {allowedMethods?.includes("ACHPayment") && !!customerBanks?.length && (
90
- <ACHSelector
91
- testid={testid ? `${testid}-ach-selector` : undefined}
92
- selectedMethod={selectedMethod}
93
- handleToggle={handleToggle}
94
- selectedBankGuid={selectedACHBankGuid || null}
95
- setSelectedBankGuid={setSelectedACHBankGuid || (() => {})}
96
- customerBanks={customerBanks || []}
97
- onPay={onPay}
98
- isPayLoading={isPayLoading || false}
99
- disabled={payAllWithCredits || !amountToPay}
100
- />
101
- )}
102
- {allowedMethods?.includes("CCPayment") && (
103
- <Accordion
104
- testid={testid ? `${testid}-cc-payment` : undefined}
105
- isOpen={!payAllWithCredits && selectedMethod === "CCPayment"}
106
- title={
107
- <Radio
108
- testid={testid ? `${testid}-cc-payment-radio` : undefined}
109
- label="Pay by Credit/Debit Card"
110
- checked={!payAllWithCredits && selectedMethod === "CCPayment"}
111
- onChange={(e) => e.stopPropagation()}
112
- disabled={payAllWithCredits || !amountToPay}
113
- />
114
- }
115
- onClick={() => {
116
- if (payAllWithCredits || !amountToPay) return;
117
- handleToggle(selectedMethod === "CCPayment" ? null : "CCPayment");
118
- }}
119
- disabled={payAllWithCredits || !amountToPay}
120
- >
121
- <Stack
122
- sizing="layout-group"
123
- width="full"
124
- items="center"
125
- justify="center"
126
- style={{
127
- flex: 1,
128
- }}
129
- minHeight={245}
130
- >
131
- {!isLoadingCCiframe && cardPaymentUrl ? (
132
- <WorldpayIframe url={cardPaymentUrl} />
133
- ) : (
134
- <Spinner />
135
- )}
136
- </Stack>
137
- </Accordion>
138
- )}
139
-
140
- {selectedMethod === "ACHPayment" && (
141
- <Button
142
- block
143
- onClick={onPay}
144
- disabled={isPayLoading || amountToPay <= 0}
145
- testid={testid ? `${testid}-submit-payment-button` : undefined}
146
- >
147
- {isPayLoading ? "Processing..." : "Submit Payment"}
148
- </Button>
149
- )}
150
- {payAllWithCredits && (
151
- <Button
152
- testid={testid ? `${testid}-submit-payment-button` : undefined}
153
- block
154
- onClick={onPay}
155
- disabled={isPayLoading}
156
- >
157
- {isPayLoading ? "Processing..." : "Submit Payment"}
158
- </Button>
159
- )}
160
- </Stack>
161
- );
162
- }
163
-
164
- type ACHSelectorProps = {
165
- selectedMethod: PaymentMethodType | null;
166
- handleToggle: (method: PaymentMethodType | null) => void;
167
- selectedBankGuid: string | null;
168
- setSelectedBankGuid: (guid: string | null) => void;
169
- customerBanks: CustomerBank[];
170
- onPay?: () => void;
171
- isPayLoading?: boolean;
172
- disabled?: boolean;
173
- testid?: string;
174
- };
175
- function ACHSelector(props: ACHSelectorProps) {
176
- const {
177
- selectedMethod,
178
- handleToggle,
179
- selectedBankGuid,
180
- setSelectedBankGuid,
181
- customerBanks,
182
- disabled,
183
- testid,
184
- } = props;
185
-
186
- function handleBankSelect(
187
- e: React.MouseEvent<HTMLDivElement>,
188
- bankGuid: string | null,
189
- ) {
190
- if (disabled) return;
191
- e.stopPropagation();
192
- setSelectedBankGuid(bankGuid);
193
- handleToggle("ACHPayment");
194
- }
195
-
196
- return (
197
- <>
198
- {customerBanks.map((bank) => (
199
- <Card
200
- testid={testid ? `${testid}-bank-${bank.CustBankGUID}` : undefined}
201
- key={bank.CustBankGUID}
202
- onClick={(e) => handleBankSelect(e, bank.CustBankGUID)}
203
- selected={
204
- !disabled &&
205
- selectedMethod === "ACHPayment" &&
206
- selectedBankGuid === bank.CustBankGUID
207
- }
208
- >
209
- <Radio
210
- label={`Pay by ${bank.AccountDisplayString}`}
211
- checked={
212
- !disabled &&
213
- selectedMethod === "ACHPayment" &&
214
- selectedBankGuid === bank.CustBankGUID
215
- }
216
- disabled={disabled}
217
- onChange={(e) => e.stopPropagation()}
218
- />
219
- </Card>
220
- ))}
221
- </>
222
- );
223
- }
224
- type CreditsSelectorProps = {
225
- selectedCredits: unknown[];
226
- allCredits: unknown[];
227
- setSelectedCredits: React.Dispatch<React.SetStateAction<unknown[]>>;
228
- testid?: string;
229
- };
230
- function CreditsSelector(props: CreditsSelectorProps) {
231
- const { selectedCredits, allCredits, setSelectedCredits, testid } = props;
232
- const [isOpen, setIsOpen] = useState<boolean>(true);
233
-
234
- const handleCreditSelect = (credit: unknown) => {
235
- if (setSelectedCredits) {
236
- setSelectedCredits((prev) =>
237
- prev.includes(credit)
238
- ? prev.filter((c) => c !== credit)
239
- : [...prev, credit],
240
- );
241
- }
242
- };
243
-
244
- return (
245
- <Accordion
246
- isOpen={isOpen}
247
- title="Available Credits"
248
- onClick={() => setIsOpen((prev) => !prev)}
249
- testid={testid}
250
- >
251
- <HorizontalDivider />
252
- <Stack sizing="layout-group" width="full">
253
- <Stack
254
- sizing="layout-group"
255
- width="full"
256
- overflowY="auto"
257
- maxHeight={300}
258
- >
259
- {(
260
- allCredits as unknown as {
261
- InvoiceNumber: string;
262
- AROpenGUID: string;
263
- InvoiceBalanceDue: number;
264
- }[]
265
- ).map((credits) => (
266
- <Stack
267
- horizontal
268
- justify="between"
269
- items="center"
270
- key={credits.AROpenGUID}
271
- sizing="layout-group"
272
- >
273
- <Stack
274
- sizing="layout-group"
275
- onClick={() => handleCreditSelect(credits)}
276
- paddingY
277
- flexGrow={1}
278
- testid={
279
- testid
280
- ? `${testid}-credit-${credits.InvoiceNumber}`
281
- : undefined
282
- }
283
- >
284
- <Checkbox
285
- testid={
286
- testid
287
- ? `${testid}-credit-${credits.InvoiceNumber}-checkbox`
288
- : undefined
289
- }
290
- label={credits.InvoiceNumber}
291
- checked={selectedCredits?.includes(credits)}
292
- onChange={() => handleCreditSelect(credits)}
293
- />
294
- </Stack>
295
-
296
- <Subheader
297
- testid={
298
- testid
299
- ? `${testid}-credit-${credits.InvoiceNumber}-InvoiceBalanceDue`
300
- : undefined
301
- }
302
- className=" pr-desktop-component-padding"
303
- >
304
- $
305
- {formatCurrencyDisplay(
306
- formatDecimalValue(Math.abs(credits.InvoiceBalanceDue), 2),
307
- )}
308
- </Subheader>
309
- </Stack>
310
- ))}
311
- </Stack>
312
- </Stack>
313
- </Accordion>
314
- );
315
- }