@wix/headless-bookings 0.0.39 → 0.0.41
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/cjs/dist/react/core/payment/Payment.d.ts +36 -104
- package/cjs/dist/react/core/payment/Payment.js +36 -102
- package/cjs/dist/react/index.d.ts +0 -1
- package/cjs/dist/react/index.js +0 -1
- package/cjs/dist/react/payment/Payment.d.ts +119 -82
- package/cjs/dist/react/payment/Payment.js +126 -81
- package/cjs/dist/services/payment/payment.def.d.ts +2 -1
- package/cjs/dist/services/payment/payment.js +8 -2
- package/cjs/dist/utils/guid.d.ts +7 -0
- package/cjs/dist/utils/guid.js +12 -0
- package/dist/react/core/payment/Payment.d.ts +36 -104
- package/dist/react/core/payment/Payment.js +36 -102
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -1
- package/dist/react/payment/Payment.d.ts +119 -82
- package/dist/react/payment/Payment.js +126 -81
- package/dist/services/payment/payment.def.d.ts +2 -1
- package/dist/services/payment/payment.js +8 -2
- package/dist/utils/guid.d.ts +7 -0
- package/dist/utils/guid.js +12 -0
- package/package.json +2 -2
- package/cjs/dist/react/payment/PaymentLineItem.d.ts +0 -144
- package/cjs/dist/react/payment/PaymentLineItem.js +0 -141
- package/dist/react/payment/PaymentLineItem.d.ts +0 -144
- package/dist/react/payment/PaymentLineItem.js +0 -141
|
@@ -34,7 +34,8 @@ export interface PaymentDetails {
|
|
|
34
34
|
*/
|
|
35
35
|
export interface SlotService {
|
|
36
36
|
service: Service;
|
|
37
|
-
|
|
37
|
+
/** Optional line item ID. If not provided, one will be generated. */
|
|
38
|
+
lineItemId?: string;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* Public config for PaymentService (SSR mode only):
|
|
@@ -9,6 +9,7 @@ import { calculateTotals, } from '@wix/auto_sdk_ecom_totals-calculator';
|
|
|
9
9
|
import { BookingServiceDefinition } from '../booking/booking.js';
|
|
10
10
|
import { RateType } from '@wix/auto_sdk_bookings_services';
|
|
11
11
|
import { PaymentServiceDefinition, } from './payment.def.js';
|
|
12
|
+
import { generateLineItemId } from '../../utils/guid.js';
|
|
12
13
|
export { PaymentServiceDefinition, } from './payment.def.js';
|
|
13
14
|
// ============================================================================
|
|
14
15
|
// Constants
|
|
@@ -54,11 +55,16 @@ function buildLineItem(service, numberOfParticipants, lineItemId) {
|
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
async function calculatePaymentDetails(slotServices, numberOfParticipants) {
|
|
57
|
-
|
|
58
|
+
// Ensure all slot services have a lineItemId
|
|
59
|
+
const data = slotServices.map((slot) => ({
|
|
60
|
+
...slot,
|
|
61
|
+
lineItemId: slot.lineItemId || generateLineItemId(),
|
|
62
|
+
}));
|
|
63
|
+
const lineItems = data.map((item) => buildLineItem(item.service, numberOfParticipants, item.lineItemId));
|
|
58
64
|
const response = await calculateTotals({
|
|
59
65
|
lineItems,
|
|
60
66
|
});
|
|
61
|
-
const additionalInfoList =
|
|
67
|
+
const additionalInfoList = data.map((item) => getAdditionalInfo(item.service, item.lineItemId));
|
|
62
68
|
return {
|
|
63
69
|
response,
|
|
64
70
|
additionalInfo: {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ID generation utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generates a unique line item ID in Ecom's GUID format
|
|
6
|
+
*/
|
|
7
|
+
export function generateLineItemId() {
|
|
8
|
+
const s4 = () => Math.floor((1 + Math.random()) * 0x10000)
|
|
9
|
+
.toString(16)
|
|
10
|
+
.substring(1);
|
|
11
|
+
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-bookings",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"groupId": "com.wixpress.headless-components"
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"falconPackageHash": "
|
|
75
|
+
"falconPackageHash": "5847d0ce3b07a2485f7d9b707eee272b9f100b3d13614c2d92018112"
|
|
76
76
|
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PaymentLineItem - Component for displaying individual line item information
|
|
3
|
-
* Used within Payment.LineItemRepeater to display price, discount, deposit, etc.
|
|
4
|
-
*/
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { AsChildChildren } from '@wix/headless-utils/react';
|
|
7
|
-
import { MoneyData } from '@wix/headless-components/react';
|
|
8
|
-
import type { CombinedLineItem } from '../core/payment/Payment.js';
|
|
9
|
-
/**
|
|
10
|
-
* Props for PaymentLineItem.Root component
|
|
11
|
-
*/
|
|
12
|
-
export interface RootProps {
|
|
13
|
-
lineItem: CombinedLineItem;
|
|
14
|
-
currency: string;
|
|
15
|
-
children?: React.ReactNode | AsChildChildren<{
|
|
16
|
-
lineItem: CombinedLineItem;
|
|
17
|
-
currency: string;
|
|
18
|
-
}>;
|
|
19
|
-
asChild?: boolean;
|
|
20
|
-
className?: string;
|
|
21
|
-
'data-testid'?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Root component for a single line item.
|
|
25
|
-
* Provides context for child components.
|
|
26
|
-
*
|
|
27
|
-
* @component
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* <PaymentLineItem.Root lineItem={item} currency="USD">
|
|
31
|
-
* <PaymentLineItem.Price />
|
|
32
|
-
* <PaymentLineItem.Discount />
|
|
33
|
-
* </PaymentLineItem.Root>
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLElement>>;
|
|
37
|
-
/**
|
|
38
|
-
* Props for PaymentLineItem.Price component
|
|
39
|
-
*/
|
|
40
|
-
export interface PriceProps {
|
|
41
|
-
asChild?: boolean;
|
|
42
|
-
children?: AsChildChildren<{
|
|
43
|
-
totalPrice: MoneyData | null;
|
|
44
|
-
subtotal: MoneyData | null;
|
|
45
|
-
tax: MoneyData | null;
|
|
46
|
-
discount: MoneyData | null;
|
|
47
|
-
deposit: MoneyData | null;
|
|
48
|
-
priceText: string | null;
|
|
49
|
-
}>;
|
|
50
|
-
className?: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Displays the line item price with support for different price types.
|
|
54
|
-
* Uses data-attributes for conditional visibility.
|
|
55
|
-
*
|
|
56
|
-
* For CUSTOM rate type services, displays priceText instead of monetary value.
|
|
57
|
-
*
|
|
58
|
-
* @component
|
|
59
|
-
* @example
|
|
60
|
-
* ```tsx
|
|
61
|
-
* // Default usage - renders total price or price text
|
|
62
|
-
* <PaymentLineItem.Price className="text-lg font-bold" />
|
|
63
|
-
*
|
|
64
|
-
* // Custom rendering with full price data
|
|
65
|
-
* <PaymentLineItem.Price asChild>
|
|
66
|
-
* {({ totalPrice, subtotal, tax, discount, priceText }) => (
|
|
67
|
-
* <div>
|
|
68
|
-
* {priceText ? (
|
|
69
|
-
* <span>{priceText}</span>
|
|
70
|
-
* ) : (
|
|
71
|
-
* <>
|
|
72
|
-
* <span><Money money={totalPrice} /></span>
|
|
73
|
-
* <span data-has-discount={!!discount?.amount}><Money money={discount} /></span>
|
|
74
|
-
* </>
|
|
75
|
-
* )}
|
|
76
|
-
* </div>
|
|
77
|
-
* )}
|
|
78
|
-
* </PaymentLineItem.Price>
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export declare const Price: React.ForwardRefExoticComponent<PriceProps & React.RefAttributes<HTMLElement>>;
|
|
82
|
-
/**
|
|
83
|
-
* Props for PaymentLineItem.Discount component
|
|
84
|
-
*/
|
|
85
|
-
export interface DiscountProps {
|
|
86
|
-
asChild?: boolean;
|
|
87
|
-
children?: AsChildChildren<{
|
|
88
|
-
discount: MoneyData | null;
|
|
89
|
-
}>;
|
|
90
|
-
className?: string;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Displays the line item discount.
|
|
94
|
-
* Uses data-has-discount attribute for conditional visibility.
|
|
95
|
-
*
|
|
96
|
-
* @component
|
|
97
|
-
* @example
|
|
98
|
-
* ```tsx
|
|
99
|
-
* <PaymentLineItem.Discount className="text-green-500" />
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare const Discount: React.ForwardRefExoticComponent<DiscountProps & React.RefAttributes<HTMLElement>>;
|
|
103
|
-
/**
|
|
104
|
-
* Props for PaymentLineItem.Deposit component
|
|
105
|
-
*/
|
|
106
|
-
export interface DepositProps {
|
|
107
|
-
asChild?: boolean;
|
|
108
|
-
children?: AsChildChildren<{
|
|
109
|
-
deposit: MoneyData | null;
|
|
110
|
-
}>;
|
|
111
|
-
className?: string;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Displays the line item deposit amount.
|
|
115
|
-
* Uses data-has-deposit attribute for conditional visibility.
|
|
116
|
-
*
|
|
117
|
-
* @component
|
|
118
|
-
* @example
|
|
119
|
-
* ```tsx
|
|
120
|
-
* <PaymentLineItem.Deposit className="font-semibold" />
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export declare const Deposit: React.ForwardRefExoticComponent<DepositProps & React.RefAttributes<HTMLElement>>;
|
|
124
|
-
/**
|
|
125
|
-
* Props for PaymentLineItem.PriceText component
|
|
126
|
-
*/
|
|
127
|
-
export interface PriceTextProps {
|
|
128
|
-
asChild?: boolean;
|
|
129
|
-
children?: AsChildChildren<{
|
|
130
|
-
priceText: string | null;
|
|
131
|
-
}>;
|
|
132
|
-
className?: string;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Displays the custom price text (for CUSTOM rate type services).
|
|
136
|
-
* Uses data-has-price-text attribute for conditional visibility.
|
|
137
|
-
*
|
|
138
|
-
* @component
|
|
139
|
-
* @example
|
|
140
|
-
* ```tsx
|
|
141
|
-
* <PaymentLineItem.PriceText className="text-foreground" />
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
export declare const PriceText: React.ForwardRefExoticComponent<PriceTextProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* PaymentLineItem - Component for displaying individual line item information
|
|
4
|
-
* Used within Payment.LineItemRepeater to display price, discount, deposit, etc.
|
|
5
|
-
*/
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import * as CorePayment from '../core/payment/Payment.js';
|
|
8
|
-
import { AsChildSlot } from '@wix/headless-utils/react';
|
|
9
|
-
import { Money } from '@wix/headless-components/react';
|
|
10
|
-
var TestIds;
|
|
11
|
-
(function (TestIds) {
|
|
12
|
-
TestIds["paymentLineItemRoot"] = "payment-line-item-root";
|
|
13
|
-
TestIds["paymentLineItemPrice"] = "payment-line-item-price";
|
|
14
|
-
TestIds["paymentLineItemDiscount"] = "payment-line-item-discount";
|
|
15
|
-
TestIds["paymentLineItemDeposit"] = "payment-line-item-deposit";
|
|
16
|
-
TestIds["paymentLineItemPriceText"] = "payment-line-item-price-text";
|
|
17
|
-
})(TestIds || (TestIds = {}));
|
|
18
|
-
const PaymentLineItemContext = React.createContext(null);
|
|
19
|
-
/**
|
|
20
|
-
* Hook to access PaymentLineItem context
|
|
21
|
-
*/
|
|
22
|
-
function usePaymentLineItemContext() {
|
|
23
|
-
const context = React.useContext(PaymentLineItemContext);
|
|
24
|
-
if (!context) {
|
|
25
|
-
throw new Error('usePaymentLineItemContext must be used within a PaymentLineItem.Root component');
|
|
26
|
-
}
|
|
27
|
-
return context;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Root component for a single line item.
|
|
31
|
-
* Provides context for child components.
|
|
32
|
-
*
|
|
33
|
-
* @component
|
|
34
|
-
* @example
|
|
35
|
-
* ```tsx
|
|
36
|
-
* <PaymentLineItem.Root lineItem={item} currency="USD">
|
|
37
|
-
* <PaymentLineItem.Price />
|
|
38
|
-
* <PaymentLineItem.Discount />
|
|
39
|
-
* </PaymentLineItem.Root>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export const Root = React.forwardRef((props, ref) => {
|
|
43
|
-
const { lineItem, currency, children, asChild, className, ...attrs } = props;
|
|
44
|
-
return (_jsx(PaymentLineItemContext.Provider, { value: { lineItem, currency }, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": attrs['data-testid'] || TestIds.paymentLineItemRoot, customElement: children, customElementProps: { lineItem, currency }, ...attrs, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
|
|
45
|
-
});
|
|
46
|
-
Root.displayName = 'PaymentLineItem.Root';
|
|
47
|
-
/**
|
|
48
|
-
* Displays the line item price with support for different price types.
|
|
49
|
-
* Uses data-attributes for conditional visibility.
|
|
50
|
-
*
|
|
51
|
-
* For CUSTOM rate type services, displays priceText instead of monetary value.
|
|
52
|
-
*
|
|
53
|
-
* @component
|
|
54
|
-
* @example
|
|
55
|
-
* ```tsx
|
|
56
|
-
* // Default usage - renders total price or price text
|
|
57
|
-
* <PaymentLineItem.Price className="text-lg font-bold" />
|
|
58
|
-
*
|
|
59
|
-
* // Custom rendering with full price data
|
|
60
|
-
* <PaymentLineItem.Price asChild>
|
|
61
|
-
* {({ totalPrice, subtotal, tax, discount, priceText }) => (
|
|
62
|
-
* <div>
|
|
63
|
-
* {priceText ? (
|
|
64
|
-
* <span>{priceText}</span>
|
|
65
|
-
* ) : (
|
|
66
|
-
* <>
|
|
67
|
-
* <span><Money money={totalPrice} /></span>
|
|
68
|
-
* <span data-has-discount={!!discount?.amount}><Money money={discount} /></span>
|
|
69
|
-
* </>
|
|
70
|
-
* )}
|
|
71
|
-
* </div>
|
|
72
|
-
* )}
|
|
73
|
-
* </PaymentLineItem.Price>
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export const Price = React.forwardRef((props, ref) => {
|
|
77
|
-
const { asChild, children, className } = props;
|
|
78
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
79
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: (priceData) => {
|
|
80
|
-
const { totalPrice, discount, deposit, priceText } = priceData;
|
|
81
|
-
// Default rendering based on price type
|
|
82
|
-
const renderDefaultPrice = () => {
|
|
83
|
-
// If custom price text (CUSTOM rate type), show text
|
|
84
|
-
if (priceText) {
|
|
85
|
-
return (_jsx("span", { className: className, "data-testid": TestIds.paymentLineItemPrice, children: priceText }));
|
|
86
|
-
}
|
|
87
|
-
// Otherwise show monetary price
|
|
88
|
-
return totalPrice ? (_jsx(Money, { money: totalPrice, className: className })) : null;
|
|
89
|
-
};
|
|
90
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemPrice, "data-has-discount": discount !== null && discount.amount > 0, "data-has-deposit": deposit !== null && deposit.amount > 0, "data-has-price-text": !!priceText, customElement: children, customElementProps: priceData, children: renderDefaultPrice() }));
|
|
91
|
-
} }));
|
|
92
|
-
});
|
|
93
|
-
Price.displayName = 'PaymentLineItem.Price';
|
|
94
|
-
/**
|
|
95
|
-
* Displays the line item discount.
|
|
96
|
-
* Uses data-has-discount attribute for conditional visibility.
|
|
97
|
-
*
|
|
98
|
-
* @component
|
|
99
|
-
* @example
|
|
100
|
-
* ```tsx
|
|
101
|
-
* <PaymentLineItem.Discount className="text-green-500" />
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
export const Discount = React.forwardRef((props, ref) => {
|
|
105
|
-
const { asChild, children, className } = props;
|
|
106
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
107
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: ({ discount }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemDiscount, "data-has-discount": discount !== null && discount.amount > 0, customElement: children, customElementProps: { discount }, children: discount ? _jsx(Money, { money: discount }) : null })) }));
|
|
108
|
-
});
|
|
109
|
-
Discount.displayName = 'PaymentLineItem.Discount';
|
|
110
|
-
/**
|
|
111
|
-
* Displays the line item deposit amount.
|
|
112
|
-
* Uses data-has-deposit attribute for conditional visibility.
|
|
113
|
-
*
|
|
114
|
-
* @component
|
|
115
|
-
* @example
|
|
116
|
-
* ```tsx
|
|
117
|
-
* <PaymentLineItem.Deposit className="font-semibold" />
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export const Deposit = React.forwardRef((props, ref) => {
|
|
121
|
-
const { asChild, children, className } = props;
|
|
122
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
123
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: ({ deposit }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemDeposit, "data-has-deposit": deposit !== null && deposit.amount > 0, customElement: children, customElementProps: { deposit }, children: deposit ? _jsx(Money, { money: deposit }) : null })) }));
|
|
124
|
-
});
|
|
125
|
-
Deposit.displayName = 'PaymentLineItem.Deposit';
|
|
126
|
-
/**
|
|
127
|
-
* Displays the custom price text (for CUSTOM rate type services).
|
|
128
|
-
* Uses data-has-price-text attribute for conditional visibility.
|
|
129
|
-
*
|
|
130
|
-
* @component
|
|
131
|
-
* @example
|
|
132
|
-
* ```tsx
|
|
133
|
-
* <PaymentLineItem.PriceText className="text-foreground" />
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
export const PriceText = React.forwardRef((props, ref) => {
|
|
137
|
-
const { asChild, children, className } = props;
|
|
138
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
139
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: ({ priceText }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemPriceText, "data-has-price-text": !!priceText, customElement: children, customElementProps: { priceText }, children: priceText ? _jsx("span", { children: priceText }) : null })) }));
|
|
140
|
-
});
|
|
141
|
-
PriceText.displayName = 'PaymentLineItem.PriceText';
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PaymentLineItem - Component for displaying individual line item information
|
|
3
|
-
* Used within Payment.LineItemRepeater to display price, discount, deposit, etc.
|
|
4
|
-
*/
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { AsChildChildren } from '@wix/headless-utils/react';
|
|
7
|
-
import { MoneyData } from '@wix/headless-components/react';
|
|
8
|
-
import type { CombinedLineItem } from '../core/payment/Payment.js';
|
|
9
|
-
/**
|
|
10
|
-
* Props for PaymentLineItem.Root component
|
|
11
|
-
*/
|
|
12
|
-
export interface RootProps {
|
|
13
|
-
lineItem: CombinedLineItem;
|
|
14
|
-
currency: string;
|
|
15
|
-
children?: React.ReactNode | AsChildChildren<{
|
|
16
|
-
lineItem: CombinedLineItem;
|
|
17
|
-
currency: string;
|
|
18
|
-
}>;
|
|
19
|
-
asChild?: boolean;
|
|
20
|
-
className?: string;
|
|
21
|
-
'data-testid'?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Root component for a single line item.
|
|
25
|
-
* Provides context for child components.
|
|
26
|
-
*
|
|
27
|
-
* @component
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* <PaymentLineItem.Root lineItem={item} currency="USD">
|
|
31
|
-
* <PaymentLineItem.Price />
|
|
32
|
-
* <PaymentLineItem.Discount />
|
|
33
|
-
* </PaymentLineItem.Root>
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLElement>>;
|
|
37
|
-
/**
|
|
38
|
-
* Props for PaymentLineItem.Price component
|
|
39
|
-
*/
|
|
40
|
-
export interface PriceProps {
|
|
41
|
-
asChild?: boolean;
|
|
42
|
-
children?: AsChildChildren<{
|
|
43
|
-
totalPrice: MoneyData | null;
|
|
44
|
-
subtotal: MoneyData | null;
|
|
45
|
-
tax: MoneyData | null;
|
|
46
|
-
discount: MoneyData | null;
|
|
47
|
-
deposit: MoneyData | null;
|
|
48
|
-
priceText: string | null;
|
|
49
|
-
}>;
|
|
50
|
-
className?: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Displays the line item price with support for different price types.
|
|
54
|
-
* Uses data-attributes for conditional visibility.
|
|
55
|
-
*
|
|
56
|
-
* For CUSTOM rate type services, displays priceText instead of monetary value.
|
|
57
|
-
*
|
|
58
|
-
* @component
|
|
59
|
-
* @example
|
|
60
|
-
* ```tsx
|
|
61
|
-
* // Default usage - renders total price or price text
|
|
62
|
-
* <PaymentLineItem.Price className="text-lg font-bold" />
|
|
63
|
-
*
|
|
64
|
-
* // Custom rendering with full price data
|
|
65
|
-
* <PaymentLineItem.Price asChild>
|
|
66
|
-
* {({ totalPrice, subtotal, tax, discount, priceText }) => (
|
|
67
|
-
* <div>
|
|
68
|
-
* {priceText ? (
|
|
69
|
-
* <span>{priceText}</span>
|
|
70
|
-
* ) : (
|
|
71
|
-
* <>
|
|
72
|
-
* <span><Money money={totalPrice} /></span>
|
|
73
|
-
* <span data-has-discount={!!discount?.amount}><Money money={discount} /></span>
|
|
74
|
-
* </>
|
|
75
|
-
* )}
|
|
76
|
-
* </div>
|
|
77
|
-
* )}
|
|
78
|
-
* </PaymentLineItem.Price>
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export declare const Price: React.ForwardRefExoticComponent<PriceProps & React.RefAttributes<HTMLElement>>;
|
|
82
|
-
/**
|
|
83
|
-
* Props for PaymentLineItem.Discount component
|
|
84
|
-
*/
|
|
85
|
-
export interface DiscountProps {
|
|
86
|
-
asChild?: boolean;
|
|
87
|
-
children?: AsChildChildren<{
|
|
88
|
-
discount: MoneyData | null;
|
|
89
|
-
}>;
|
|
90
|
-
className?: string;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Displays the line item discount.
|
|
94
|
-
* Uses data-has-discount attribute for conditional visibility.
|
|
95
|
-
*
|
|
96
|
-
* @component
|
|
97
|
-
* @example
|
|
98
|
-
* ```tsx
|
|
99
|
-
* <PaymentLineItem.Discount className="text-green-500" />
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare const Discount: React.ForwardRefExoticComponent<DiscountProps & React.RefAttributes<HTMLElement>>;
|
|
103
|
-
/**
|
|
104
|
-
* Props for PaymentLineItem.Deposit component
|
|
105
|
-
*/
|
|
106
|
-
export interface DepositProps {
|
|
107
|
-
asChild?: boolean;
|
|
108
|
-
children?: AsChildChildren<{
|
|
109
|
-
deposit: MoneyData | null;
|
|
110
|
-
}>;
|
|
111
|
-
className?: string;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Displays the line item deposit amount.
|
|
115
|
-
* Uses data-has-deposit attribute for conditional visibility.
|
|
116
|
-
*
|
|
117
|
-
* @component
|
|
118
|
-
* @example
|
|
119
|
-
* ```tsx
|
|
120
|
-
* <PaymentLineItem.Deposit className="font-semibold" />
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export declare const Deposit: React.ForwardRefExoticComponent<DepositProps & React.RefAttributes<HTMLElement>>;
|
|
124
|
-
/**
|
|
125
|
-
* Props for PaymentLineItem.PriceText component
|
|
126
|
-
*/
|
|
127
|
-
export interface PriceTextProps {
|
|
128
|
-
asChild?: boolean;
|
|
129
|
-
children?: AsChildChildren<{
|
|
130
|
-
priceText: string | null;
|
|
131
|
-
}>;
|
|
132
|
-
className?: string;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Displays the custom price text (for CUSTOM rate type services).
|
|
136
|
-
* Uses data-has-price-text attribute for conditional visibility.
|
|
137
|
-
*
|
|
138
|
-
* @component
|
|
139
|
-
* @example
|
|
140
|
-
* ```tsx
|
|
141
|
-
* <PaymentLineItem.PriceText className="text-foreground" />
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
export declare const PriceText: React.ForwardRefExoticComponent<PriceTextProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* PaymentLineItem - Component for displaying individual line item information
|
|
4
|
-
* Used within Payment.LineItemRepeater to display price, discount, deposit, etc.
|
|
5
|
-
*/
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import * as CorePayment from '../core/payment/Payment.js';
|
|
8
|
-
import { AsChildSlot } from '@wix/headless-utils/react';
|
|
9
|
-
import { Money } from '@wix/headless-components/react';
|
|
10
|
-
var TestIds;
|
|
11
|
-
(function (TestIds) {
|
|
12
|
-
TestIds["paymentLineItemRoot"] = "payment-line-item-root";
|
|
13
|
-
TestIds["paymentLineItemPrice"] = "payment-line-item-price";
|
|
14
|
-
TestIds["paymentLineItemDiscount"] = "payment-line-item-discount";
|
|
15
|
-
TestIds["paymentLineItemDeposit"] = "payment-line-item-deposit";
|
|
16
|
-
TestIds["paymentLineItemPriceText"] = "payment-line-item-price-text";
|
|
17
|
-
})(TestIds || (TestIds = {}));
|
|
18
|
-
const PaymentLineItemContext = React.createContext(null);
|
|
19
|
-
/**
|
|
20
|
-
* Hook to access PaymentLineItem context
|
|
21
|
-
*/
|
|
22
|
-
function usePaymentLineItemContext() {
|
|
23
|
-
const context = React.useContext(PaymentLineItemContext);
|
|
24
|
-
if (!context) {
|
|
25
|
-
throw new Error('usePaymentLineItemContext must be used within a PaymentLineItem.Root component');
|
|
26
|
-
}
|
|
27
|
-
return context;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Root component for a single line item.
|
|
31
|
-
* Provides context for child components.
|
|
32
|
-
*
|
|
33
|
-
* @component
|
|
34
|
-
* @example
|
|
35
|
-
* ```tsx
|
|
36
|
-
* <PaymentLineItem.Root lineItem={item} currency="USD">
|
|
37
|
-
* <PaymentLineItem.Price />
|
|
38
|
-
* <PaymentLineItem.Discount />
|
|
39
|
-
* </PaymentLineItem.Root>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export const Root = React.forwardRef((props, ref) => {
|
|
43
|
-
const { lineItem, currency, children, asChild, className, ...attrs } = props;
|
|
44
|
-
return (_jsx(PaymentLineItemContext.Provider, { value: { lineItem, currency }, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": attrs['data-testid'] || TestIds.paymentLineItemRoot, customElement: children, customElementProps: { lineItem, currency }, ...attrs, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
|
|
45
|
-
});
|
|
46
|
-
Root.displayName = 'PaymentLineItem.Root';
|
|
47
|
-
/**
|
|
48
|
-
* Displays the line item price with support for different price types.
|
|
49
|
-
* Uses data-attributes for conditional visibility.
|
|
50
|
-
*
|
|
51
|
-
* For CUSTOM rate type services, displays priceText instead of monetary value.
|
|
52
|
-
*
|
|
53
|
-
* @component
|
|
54
|
-
* @example
|
|
55
|
-
* ```tsx
|
|
56
|
-
* // Default usage - renders total price or price text
|
|
57
|
-
* <PaymentLineItem.Price className="text-lg font-bold" />
|
|
58
|
-
*
|
|
59
|
-
* // Custom rendering with full price data
|
|
60
|
-
* <PaymentLineItem.Price asChild>
|
|
61
|
-
* {({ totalPrice, subtotal, tax, discount, priceText }) => (
|
|
62
|
-
* <div>
|
|
63
|
-
* {priceText ? (
|
|
64
|
-
* <span>{priceText}</span>
|
|
65
|
-
* ) : (
|
|
66
|
-
* <>
|
|
67
|
-
* <span><Money money={totalPrice} /></span>
|
|
68
|
-
* <span data-has-discount={!!discount?.amount}><Money money={discount} /></span>
|
|
69
|
-
* </>
|
|
70
|
-
* )}
|
|
71
|
-
* </div>
|
|
72
|
-
* )}
|
|
73
|
-
* </PaymentLineItem.Price>
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export const Price = React.forwardRef((props, ref) => {
|
|
77
|
-
const { asChild, children, className } = props;
|
|
78
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
79
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: (priceData) => {
|
|
80
|
-
const { totalPrice, discount, deposit, priceText } = priceData;
|
|
81
|
-
// Default rendering based on price type
|
|
82
|
-
const renderDefaultPrice = () => {
|
|
83
|
-
// If custom price text (CUSTOM rate type), show text
|
|
84
|
-
if (priceText) {
|
|
85
|
-
return (_jsx("span", { className: className, "data-testid": TestIds.paymentLineItemPrice, children: priceText }));
|
|
86
|
-
}
|
|
87
|
-
// Otherwise show monetary price
|
|
88
|
-
return totalPrice ? (_jsx(Money, { money: totalPrice, className: className })) : null;
|
|
89
|
-
};
|
|
90
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemPrice, "data-has-discount": discount !== null && discount.amount > 0, "data-has-deposit": deposit !== null && deposit.amount > 0, "data-has-price-text": !!priceText, customElement: children, customElementProps: priceData, children: renderDefaultPrice() }));
|
|
91
|
-
} }));
|
|
92
|
-
});
|
|
93
|
-
Price.displayName = 'PaymentLineItem.Price';
|
|
94
|
-
/**
|
|
95
|
-
* Displays the line item discount.
|
|
96
|
-
* Uses data-has-discount attribute for conditional visibility.
|
|
97
|
-
*
|
|
98
|
-
* @component
|
|
99
|
-
* @example
|
|
100
|
-
* ```tsx
|
|
101
|
-
* <PaymentLineItem.Discount className="text-green-500" />
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
export const Discount = React.forwardRef((props, ref) => {
|
|
105
|
-
const { asChild, children, className } = props;
|
|
106
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
107
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: ({ discount }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemDiscount, "data-has-discount": discount !== null && discount.amount > 0, customElement: children, customElementProps: { discount }, children: discount ? _jsx(Money, { money: discount }) : null })) }));
|
|
108
|
-
});
|
|
109
|
-
Discount.displayName = 'PaymentLineItem.Discount';
|
|
110
|
-
/**
|
|
111
|
-
* Displays the line item deposit amount.
|
|
112
|
-
* Uses data-has-deposit attribute for conditional visibility.
|
|
113
|
-
*
|
|
114
|
-
* @component
|
|
115
|
-
* @example
|
|
116
|
-
* ```tsx
|
|
117
|
-
* <PaymentLineItem.Deposit className="font-semibold" />
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export const Deposit = React.forwardRef((props, ref) => {
|
|
121
|
-
const { asChild, children, className } = props;
|
|
122
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
123
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: ({ deposit }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemDeposit, "data-has-deposit": deposit !== null && deposit.amount > 0, customElement: children, customElementProps: { deposit }, children: deposit ? _jsx(Money, { money: deposit }) : null })) }));
|
|
124
|
-
});
|
|
125
|
-
Deposit.displayName = 'PaymentLineItem.Deposit';
|
|
126
|
-
/**
|
|
127
|
-
* Displays the custom price text (for CUSTOM rate type services).
|
|
128
|
-
* Uses data-has-price-text attribute for conditional visibility.
|
|
129
|
-
*
|
|
130
|
-
* @component
|
|
131
|
-
* @example
|
|
132
|
-
* ```tsx
|
|
133
|
-
* <PaymentLineItem.PriceText className="text-foreground" />
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
export const PriceText = React.forwardRef((props, ref) => {
|
|
137
|
-
const { asChild, children, className } = props;
|
|
138
|
-
const { lineItem, currency } = usePaymentLineItemContext();
|
|
139
|
-
return (_jsx(CorePayment.LineItem, { lineItem: lineItem, currency: currency, children: ({ priceText }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentLineItemPriceText, "data-has-price-text": !!priceText, customElement: children, customElementProps: { priceText }, children: priceText ? _jsx("span", { children: priceText }) : null })) }));
|
|
140
|
-
});
|
|
141
|
-
PriceText.displayName = 'PaymentLineItem.PriceText';
|