@blocklet/payment-react 1.19.17 → 1.19.19
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/README.md +313 -0
- package/es/checkout/form.js +2 -2
- package/es/components/auto-topup/index.d.ts +14 -0
- package/es/components/auto-topup/index.js +417 -0
- package/es/components/auto-topup/modal.d.ts +35 -0
- package/es/components/auto-topup/modal.js +734 -0
- package/es/components/auto-topup/product-card.d.ts +13 -0
- package/es/components/auto-topup/product-card.js +173 -0
- package/es/components/collapse.d.ts +13 -0
- package/es/components/collapse.js +76 -0
- package/es/components/input.d.ts +2 -1
- package/es/components/input.js +64 -13
- package/es/components/label.d.ts +2 -1
- package/es/components/label.js +2 -1
- package/es/index.d.ts +4 -1
- package/es/index.js +7 -1
- package/es/libs/util.js +2 -1
- package/es/locales/en.js +56 -0
- package/es/locales/zh.js +56 -0
- package/es/payment/form/index.js +6 -0
- package/es/payment/product-item.js +19 -12
- package/lib/checkout/form.js +2 -2
- package/lib/components/auto-topup/index.d.ts +14 -0
- package/lib/components/auto-topup/index.js +451 -0
- package/lib/components/auto-topup/modal.d.ts +35 -0
- package/lib/components/auto-topup/modal.js +803 -0
- package/lib/components/auto-topup/product-card.d.ts +13 -0
- package/lib/components/auto-topup/product-card.js +149 -0
- package/lib/components/collapse.d.ts +13 -0
- package/lib/components/collapse.js +74 -0
- package/lib/components/input.d.ts +2 -1
- package/lib/components/input.js +66 -24
- package/lib/components/label.d.ts +2 -1
- package/lib/components/label.js +3 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +24 -0
- package/lib/libs/util.js +2 -1
- package/lib/locales/en.js +56 -0
- package/lib/locales/zh.js +56 -0
- package/lib/payment/form/index.js +6 -0
- package/lib/payment/product-item.js +21 -12
- package/package.json +9 -9
- package/src/checkout/form.tsx +2 -2
- package/src/components/auto-topup/index.tsx +449 -0
- package/src/components/auto-topup/modal.tsx +773 -0
- package/src/components/auto-topup/product-card.tsx +156 -0
- package/src/components/collapse.tsx +82 -0
- package/src/components/input.tsx +71 -22
- package/src/components/label.tsx +8 -2
- package/src/index.ts +7 -0
- package/src/libs/util.ts +1 -0
- package/src/locales/en.tsx +59 -0
- package/src/locales/zh.tsx +57 -0
- package/src/payment/form/index.tsx +6 -0
- package/src/payment/product-item.tsx +20 -13
|
@@ -54,7 +54,7 @@ export default function ProductItem({
|
|
|
54
54
|
onQuantityChange = () => {},
|
|
55
55
|
}: Props) {
|
|
56
56
|
const { t, locale } = useLocaleContext();
|
|
57
|
-
const { settings } = usePaymentContext();
|
|
57
|
+
const { settings, setPayable } = usePaymentContext();
|
|
58
58
|
const pricing = formatLineItemPricing(item, currency, { trialEnd, trialInDays }, locale);
|
|
59
59
|
const saving = formatUpsellSaving(items, currency);
|
|
60
60
|
const metered = item.price?.recurring?.usage_type === 'metered' ? t('common.metered') : '';
|
|
@@ -68,38 +68,45 @@ export default function ProductItem({
|
|
|
68
68
|
const validDuration = item.price.metadata?.credit_config?.valid_duration_value;
|
|
69
69
|
const validDurationUnit = item.price.metadata?.credit_config?.valid_duration_unit || 'days';
|
|
70
70
|
|
|
71
|
-
const [localQuantity, setLocalQuantity] = useState(item.quantity);
|
|
71
|
+
const [localQuantity, setLocalQuantity] = useState<number | undefined>(item.quantity);
|
|
72
72
|
const canAdjustQuantity = adjustableQuantity.enabled && mode === 'normal';
|
|
73
73
|
const minQuantity = Math.max(adjustableQuantity.minimum || 1, 1);
|
|
74
74
|
const quantityAvailable = Math.min(item.price.quantity_limit_per_checkout, item.price.quantity_available);
|
|
75
75
|
const maxQuantity = quantityAvailable
|
|
76
76
|
? Math.min(adjustableQuantity.maximum || Infinity, quantityAvailable)
|
|
77
77
|
: adjustableQuantity.maximum || Infinity;
|
|
78
|
+
const localQuantityNum = localQuantity || 0;
|
|
78
79
|
|
|
79
80
|
const handleQuantityChange = (newQuantity: number) => {
|
|
81
|
+
if (!newQuantity) {
|
|
82
|
+
setLocalQuantity(undefined);
|
|
83
|
+
setPayable(false);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
setPayable(true);
|
|
80
87
|
if (newQuantity >= minQuantity && newQuantity <= maxQuantity) {
|
|
81
|
-
setLocalQuantity(newQuantity);
|
|
82
88
|
if (formatQuantityInventory(item.price, newQuantity, locale)) {
|
|
83
89
|
return;
|
|
84
90
|
}
|
|
91
|
+
setLocalQuantity(newQuantity);
|
|
85
92
|
onQuantityChange(item.price_id, newQuantity);
|
|
86
93
|
}
|
|
87
94
|
};
|
|
88
95
|
|
|
89
96
|
const handleQuantityIncrease = () => {
|
|
90
|
-
if (
|
|
91
|
-
handleQuantityChange(
|
|
97
|
+
if (localQuantityNum < maxQuantity) {
|
|
98
|
+
handleQuantityChange(localQuantityNum + 1);
|
|
92
99
|
}
|
|
93
100
|
};
|
|
94
101
|
|
|
95
102
|
const handleQuantityDecrease = () => {
|
|
96
|
-
if (
|
|
97
|
-
handleQuantityChange(
|
|
103
|
+
if (localQuantityNum > minQuantity) {
|
|
104
|
+
handleQuantityChange(localQuantityNum - 1);
|
|
98
105
|
}
|
|
99
106
|
};
|
|
100
107
|
|
|
101
108
|
const handleQuantityInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
102
|
-
const value = parseInt(event.target.value, 10);
|
|
109
|
+
const value = parseInt(event.target.value || '0', 10);
|
|
103
110
|
if (!Number.isNaN(value)) {
|
|
104
111
|
handleQuantityChange(value);
|
|
105
112
|
}
|
|
@@ -110,7 +117,7 @@ export default function ProductItem({
|
|
|
110
117
|
if (!isCreditProduct) return null;
|
|
111
118
|
|
|
112
119
|
const isRecurring = item.price.type === 'recurring';
|
|
113
|
-
const totalCredit = formatNumber(creditAmount * localQuantity);
|
|
120
|
+
const totalCredit = formatNumber(creditAmount * (localQuantity || 0));
|
|
114
121
|
|
|
115
122
|
let message = '';
|
|
116
123
|
if (isRecurring) {
|
|
@@ -145,7 +152,7 @@ export default function ProductItem({
|
|
|
145
152
|
return pricing.primary;
|
|
146
153
|
}, [trialInDays, trialEnd, pricing, item, locale]);
|
|
147
154
|
|
|
148
|
-
const quantityInventoryError = formatQuantityInventory(item.price,
|
|
155
|
+
const quantityInventoryError = formatQuantityInventory(item.price, localQuantityNum, locale);
|
|
149
156
|
|
|
150
157
|
return (
|
|
151
158
|
<Stack
|
|
@@ -235,7 +242,7 @@ export default function ProductItem({
|
|
|
235
242
|
<IconButton
|
|
236
243
|
size="small"
|
|
237
244
|
onClick={handleQuantityDecrease}
|
|
238
|
-
disabled={
|
|
245
|
+
disabled={localQuantityNum <= minQuantity}
|
|
239
246
|
sx={{ minWidth: 32, width: 32, height: 32 }}>
|
|
240
247
|
<Remove fontSize="small" />
|
|
241
248
|
</IconButton>
|
|
@@ -248,14 +255,14 @@ export default function ProductItem({
|
|
|
248
255
|
htmlInput: {
|
|
249
256
|
min: minQuantity,
|
|
250
257
|
max: maxQuantity,
|
|
251
|
-
style: { textAlign: 'center', padding: '4px' },
|
|
258
|
+
style: { textAlign: 'center', padding: '4px', minWidth: 80 },
|
|
252
259
|
},
|
|
253
260
|
}}
|
|
254
261
|
/>
|
|
255
262
|
<IconButton
|
|
256
263
|
size="small"
|
|
257
264
|
onClick={handleQuantityIncrease}
|
|
258
|
-
disabled={
|
|
265
|
+
disabled={localQuantityNum >= maxQuantity}
|
|
259
266
|
sx={{ minWidth: 32, width: 32, height: 32 }}>
|
|
260
267
|
<Add fontSize="small" />
|
|
261
268
|
</IconButton>
|