@riosst100/pwa-marketplace 3.0.1 → 3.0.4
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/i18n/en_US.json +3 -3
- package/i18n/id_ID.json +2 -2
- package/package.json +1 -1
- package/src/componentOverrideMapping.js +2 -0
- package/src/components/SellerCoupon/index.js +1 -0
- package/src/components/SellerCoupon/sellerCoupon.js +41 -6
- package/src/components/SellerCoupon/sellerCoupon.module.css +22 -0
- package/src/components/SellerCoupon/sellerCouponCheckout.js +36 -19
- package/src/components/SellerCoupon/sellerCouponCheckout.shimmer.js +21 -0
- package/src/overwrites/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js +2 -2
- package/src/overwrites/peregrine/lib/talons/CartPage/useCartPage.js +121 -0
- package/src/overwrites/venia-ui/lib/components/CartPage/PriceAdjustments/CouponCode/couponCode.js +24 -27
- package/src/overwrites/venia-ui/lib/components/CartPage/PriceAdjustments/CouponCode/couponCode.module.css +2 -0
- package/src/overwrites/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js +14 -5
- package/src/overwrites/venia-ui/lib/components/CartPage/cartPage.js +0 -7
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/OrderSummary/orderSummary.js +4 -0
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/PriceAdjustments/priceAdjustments.js +65 -57
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/PriceAdjustments/priceAdjustments.module.css +29 -0
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/checkoutPage.js +2 -2
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/checkoutPage.module.css +2 -0
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/Reviews/index.js +1 -0
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/Reviews/reviewModal.js +316 -0
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/Reviews/starInput.js +33 -0
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/orderHistoryPage.js +29 -2
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/orderRow.js +70 -34
- package/src/overwrites/venia-ui/lib/components/ProductFullDetail/components/modalFormReview.js +8 -8
- package/src/overwrites/venia-ui/lib/components/ProductFullDetail/components/productReview.js +4 -27
- package/src/talons/ReviewModal/reviewModal.gql.js +45 -0
- package/src/talons/ReviewModal/useReviewModal.js +87 -0
package/i18n/en_US.json
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"checkoutPage.additionalText": "You will also receive an email with the details and we will let you know when your order has shipped.",
|
|
64
64
|
"checkoutPage.billingAddressSame": "Billing address same as shipping address",
|
|
65
65
|
"checkoutPage.checkout": "Checkout",
|
|
66
|
-
"checkoutPage.couponCode": "Apply Coupon
|
|
66
|
+
"checkoutPage.couponCode": "Apply Coupon",
|
|
67
67
|
"checkoutPage.createAccount": "Create Account",
|
|
68
68
|
"checkoutPage.editPaymentInformation": "Edit Payment Information",
|
|
69
69
|
"checkoutPage.editShippingInfo": "Edit Shipping Information",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"checkoutPage.loadingPaymentInformation": "Fetching Payment Information",
|
|
83
83
|
"checkoutPage.noPaymentAvailable": "Payment is currently unavailable.",
|
|
84
84
|
"checkoutPage.orderNumber": "Order Number: {orderNumber}",
|
|
85
|
-
"checkoutPage.orderSummary": "Summary",
|
|
85
|
+
"checkoutPage.orderSummary": "Order Summary",
|
|
86
86
|
"checkoutPage.paymentInformation": "Payment Information",
|
|
87
87
|
"checkoutPage.paymentInformationStep": "Payment Information",
|
|
88
88
|
"checkoutPage.paymentLoadingError": "There was an error loading payments.",
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"country.label": "Country",
|
|
140
140
|
"couponCode.apply": "Apply",
|
|
141
141
|
"couponCode.couponCode": "Coupon Code",
|
|
142
|
-
"couponCode.enterCode": "Enter code",
|
|
142
|
+
"couponCode.enterCode": "Enter coupon code",
|
|
143
143
|
"couponCode.errorContainer": "Something went wrong. Please refresh and try again.",
|
|
144
144
|
"couponCode.removeButton": "Remove",
|
|
145
145
|
"createAccount.cancelText": "Cancel",
|
package/i18n/id_ID.json
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"checkoutPage.additionalText": "You will also receive an email with the details and we will let you know when your order has shipped.",
|
|
65
65
|
"checkoutPage.billingAddressSame": "Billing address same as shipping address",
|
|
66
66
|
"checkoutPage.checkout": "Checkout",
|
|
67
|
-
"checkoutPage.couponCode": "Apply Coupon
|
|
67
|
+
"checkoutPage.couponCode": "Apply Coupon",
|
|
68
68
|
"checkoutPage.createAccount": "Create Account",
|
|
69
69
|
"checkoutPage.editPaymentInformation": "Edit Payment Information",
|
|
70
70
|
"checkoutPage.editShippingInfo": "Edit Shipping Information",
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
"country.label": "Country",
|
|
141
141
|
"couponCode.apply": "Apply",
|
|
142
142
|
"couponCode.couponCode": "Coupon Code",
|
|
143
|
-
"couponCode.enterCode": "Enter code",
|
|
143
|
+
"couponCode.enterCode": "Enter coupon code",
|
|
144
144
|
"couponCode.errorContainer": "Something went wrong. Please refresh and try again.",
|
|
145
145
|
"couponCode.removeButton": "Remove",
|
|
146
146
|
"createAccount.cancelText": "Cancel",
|
package/package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module.exports = componentOverrideMapping = {
|
|
2
|
+
['@magento/venia-ui/lib/components/CartPage/PriceAdjustments/CouponCode/couponCode.js']: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/CartPage/PriceAdjustments/CouponCode/couponCode.js',
|
|
2
3
|
['@magento/peregrine/lib/talons/Header/useCartTrigger.js']: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/Header/useCartTrigger.js',
|
|
4
|
+
['@magento/peregrine/lib/talons/CartPage/useCartPage.js']: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/CartPage/useCartPage.js',
|
|
3
5
|
[`@magento/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js',
|
|
4
6
|
[`@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js',
|
|
5
7
|
[`@magento/venia-ui/lib/components/Adapter/adapter.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/Adapter/adapter.js',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { useMemo, useState } from 'react';
|
|
1
|
+
import React, { useMemo, useState, useCallback } from 'react';
|
|
2
2
|
import classes from './sellerCoupon.module.css';
|
|
3
|
+
import SellerCouponCheckout from '@riosst100/pwa-marketplace/src/components/SellerCoupon/sellerCouponCheckout';
|
|
3
4
|
|
|
4
5
|
const dayDiff = (toDate) => {
|
|
5
6
|
if (!toDate) return null;
|
|
@@ -13,20 +14,24 @@ const dayDiff = (toDate) => {
|
|
|
13
14
|
|
|
14
15
|
const SellerCoupon = ({ couponData, couponError, couponLoading }) => {
|
|
15
16
|
if (couponLoading) {
|
|
16
|
-
return
|
|
17
|
+
return '';
|
|
18
|
+
// return <div className={classes.container}><p className={classes.metaText}>Loading coupons...</p></div>;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
if (couponError) {
|
|
20
|
-
return
|
|
22
|
+
return '';
|
|
23
|
+
// return <div className={classes.container}><p className={classes.metaText}>Failed to load coupons.</p></div>;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const items = couponData?.sellerCoupons?.items || [];
|
|
24
27
|
|
|
25
28
|
if (!items.length) {
|
|
26
|
-
return
|
|
29
|
+
return '';
|
|
30
|
+
// return <div className={classes.container}><p className={classes.metaText}>No coupons available.</p></div>;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
const [copied, setCopied] = useState(null);
|
|
34
|
+
const [couponModalOpen, setCouponModalOpen] = useState(false);
|
|
30
35
|
|
|
31
36
|
const handleClaim = async (code) => {
|
|
32
37
|
try {
|
|
@@ -40,10 +45,14 @@ const SellerCoupon = ({ couponData, couponError, couponLoading }) => {
|
|
|
40
45
|
setTimeout(() => setCopied(null), 2000);
|
|
41
46
|
};
|
|
42
47
|
|
|
48
|
+
const handleViewCoupons = useCallback(() => {
|
|
49
|
+
setCouponModalOpen(true);
|
|
50
|
+
}, [setCouponModalOpen]);
|
|
51
|
+
|
|
43
52
|
return (
|
|
44
53
|
<section className={classes.container} aria-label="Seller coupons">
|
|
45
54
|
<div className={classes.scroller}>
|
|
46
|
-
{items.map(item => {
|
|
55
|
+
{items.slice(0, 3).map(item => {
|
|
47
56
|
const key = item.couponcode_id || item.coupon_id || item.code;
|
|
48
57
|
const daysLeft = dayDiff(item.to_date);
|
|
49
58
|
const expiryLabel = daysLeft === null
|
|
@@ -66,7 +75,7 @@ const SellerCoupon = ({ couponData, couponError, couponLoading }) => {
|
|
|
66
75
|
<div className={classes.actions}>
|
|
67
76
|
<button
|
|
68
77
|
type="button"
|
|
69
|
-
className={classes.claimBtn}
|
|
78
|
+
className={copied === item.code ? classes.claimedBtn : classes.claimBtn}
|
|
70
79
|
onClick={() => handleClaim(item.code)}
|
|
71
80
|
aria-label={`Claim coupon ${item.code}`}
|
|
72
81
|
>
|
|
@@ -76,6 +85,32 @@ const SellerCoupon = ({ couponData, couponError, couponLoading }) => {
|
|
|
76
85
|
</div>
|
|
77
86
|
);
|
|
78
87
|
})}
|
|
88
|
+
{couponModalOpen && (
|
|
89
|
+
<SellerCouponCheckout
|
|
90
|
+
couponData={couponData}
|
|
91
|
+
couponLoading={couponLoading}
|
|
92
|
+
couponError={couponError}
|
|
93
|
+
autoOpen={true}
|
|
94
|
+
closeOnClaim={true}
|
|
95
|
+
couponModalOpen={couponModalOpen}
|
|
96
|
+
setCouponModalOpen={setCouponModalOpen}
|
|
97
|
+
onSelectCoupon={handleClaim}
|
|
98
|
+
onTriggerRender={() => null}
|
|
99
|
+
isCopyAction={true}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
<div className={classes.viewAllCard} role="group" aria-label="View All Coupons">
|
|
103
|
+
<div className={classes.actions}>
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
className={classes.viewAllBtn}
|
|
107
|
+
onClick={handleViewCoupons}
|
|
108
|
+
aria-label="View All Coupons"
|
|
109
|
+
>
|
|
110
|
+
View All Coupons
|
|
111
|
+
</button>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
79
114
|
</div>
|
|
80
115
|
</section>
|
|
81
116
|
);
|
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
padding:8px 4px 12px;
|
|
20
20
|
scroll-snap-type:x mandatory;
|
|
21
21
|
}
|
|
22
|
+
.viewAllCard {
|
|
23
|
+
position:relative;
|
|
24
|
+
display:flex;
|
|
25
|
+
align-items:stretch;
|
|
26
|
+
padding:0 12px 0 24px;
|
|
27
|
+
scroll-snap-align:start;
|
|
28
|
+
overflow:hidden;
|
|
29
|
+
}
|
|
22
30
|
.card{
|
|
23
31
|
position:relative;
|
|
24
32
|
background:#fff8f1;
|
|
@@ -90,6 +98,20 @@
|
|
|
90
98
|
justify-content:center;
|
|
91
99
|
padding:10px 0;
|
|
92
100
|
}
|
|
101
|
+
.viewAllBtn {
|
|
102
|
+
color:#f76b1c;
|
|
103
|
+
padding:8px 18px;
|
|
104
|
+
font-weight:600;
|
|
105
|
+
cursor:pointer;
|
|
106
|
+
text-decoration:underline;
|
|
107
|
+
}
|
|
108
|
+
.claimedBtn {
|
|
109
|
+
color: #a19791;
|
|
110
|
+
border:none;
|
|
111
|
+
border-radius:6px;
|
|
112
|
+
padding:8px 18px;
|
|
113
|
+
cursor:pointer;
|
|
114
|
+
}
|
|
93
115
|
.claimBtn{
|
|
94
116
|
background: #f76b1c;
|
|
95
117
|
color:#fff;
|
|
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import listClasses from './sellerCoupon.module.css';
|
|
4
4
|
import modalClasses from './sellerCouponCheckout.module.css';
|
|
5
|
+
import { SellerCouponCheckoutShimmer } from '@riosst100/pwa-marketplace/src/components/SellerCoupon';
|
|
5
6
|
|
|
6
7
|
// Reuse day diff logic
|
|
7
8
|
const dayDiff = (toDate) => {
|
|
@@ -28,23 +29,26 @@ const getPortalRoot = () => {
|
|
|
28
29
|
const SellerCouponCheckout = ({
|
|
29
30
|
couponData,
|
|
30
31
|
couponError,
|
|
32
|
+
setCouponModalOpen,
|
|
33
|
+
couponModalOpen,
|
|
31
34
|
couponLoading,
|
|
35
|
+
isCopyAction,
|
|
32
36
|
triggerLabel = 'View Seller Coupons',
|
|
33
37
|
onSelectCoupon,
|
|
34
38
|
onTriggerRender, // optional custom trigger renderer
|
|
35
39
|
autoOpen = false, // auto open modal when mounted
|
|
36
40
|
closeOnClaim = true // close after claiming
|
|
37
41
|
}) => {
|
|
38
|
-
const [open, setOpen] = useState(false);
|
|
42
|
+
// const [open, setOpen] = useState(false);
|
|
39
43
|
const [copied, setCopied] = useState(null);
|
|
40
44
|
|
|
41
45
|
const items = couponData?.sellerCoupons?.items || [];
|
|
42
46
|
|
|
43
|
-
const handleOpen = () =>
|
|
44
|
-
const handleClose = () =>
|
|
47
|
+
const handleOpen = () => setCouponModalOpen(true);
|
|
48
|
+
const handleClose = () => setCouponModalOpen(false);
|
|
45
49
|
|
|
46
50
|
useEffect(() => {
|
|
47
|
-
if (!
|
|
51
|
+
if (!couponModalOpen) return;
|
|
48
52
|
const onKey = (e) => {
|
|
49
53
|
if (e.key === 'Escape') {
|
|
50
54
|
handleClose();
|
|
@@ -52,7 +56,7 @@ const SellerCouponCheckout = ({
|
|
|
52
56
|
};
|
|
53
57
|
document.addEventListener('keydown', onKey);
|
|
54
58
|
return () => document.removeEventListener('keydown', onKey);
|
|
55
|
-
}, [
|
|
59
|
+
}, [couponModalOpen]);
|
|
56
60
|
|
|
57
61
|
const handleClaim = async (item) => {
|
|
58
62
|
try {
|
|
@@ -62,29 +66,34 @@ const SellerCouponCheckout = ({
|
|
|
62
66
|
} catch (_) {
|
|
63
67
|
/* ignore */
|
|
64
68
|
}
|
|
69
|
+
console.log('item.code',item.code)
|
|
65
70
|
setCopied(item.code);
|
|
66
71
|
setTimeout(() => setCopied(null), 2000);
|
|
67
|
-
if (
|
|
68
|
-
|
|
72
|
+
if (!isCopyAction) {
|
|
73
|
+
if (onSelectCoupon) onSelectCoupon(item);
|
|
74
|
+
if (closeOnClaim) handleClose();
|
|
75
|
+
}
|
|
69
76
|
};
|
|
70
77
|
|
|
71
78
|
// Auto open behavior
|
|
72
79
|
useEffect(() => {
|
|
73
|
-
if (autoOpen && !
|
|
74
|
-
|
|
80
|
+
if (autoOpen && !couponModalOpen) {
|
|
81
|
+
setCouponModalOpen(true);
|
|
75
82
|
}
|
|
76
|
-
}, [autoOpen,
|
|
83
|
+
}, [autoOpen, couponModalOpen]);
|
|
84
|
+
|
|
85
|
+
console.log('copied',copied)
|
|
77
86
|
|
|
78
|
-
const modal =
|
|
87
|
+
const modal = couponModalOpen ? (
|
|
79
88
|
<div className={modalClasses.overlay} role="dialog" aria-modal="true" aria-label="Seller coupons list">
|
|
80
89
|
<div className={modalClasses.backdrop} onClick={handleClose} />
|
|
81
90
|
<div className={modalClasses.dialog}>
|
|
82
91
|
<div className={modalClasses.header}>
|
|
83
|
-
<h2 className={modalClasses.title}>
|
|
92
|
+
<h2 className={modalClasses.title}>{isCopyAction ? 'Store Coupons' : 'Apply Coupon'}</h2>
|
|
84
93
|
<button type="button" className={modalClasses.closeBtn} onClick={handleClose} aria-label="Close coupon modal">×</button>
|
|
85
94
|
</div>
|
|
86
95
|
<div className={modalClasses.body}>
|
|
87
|
-
{couponLoading && <
|
|
96
|
+
{couponLoading && <SellerCouponCheckoutShimmer />}
|
|
88
97
|
{!couponLoading && couponError && <p className={listClasses.metaText}>Failed to load coupons.</p>}
|
|
89
98
|
{!couponLoading && !couponError && !items.length && <p className={listClasses.metaText}>No coupons available.</p>}
|
|
90
99
|
{!couponLoading && !couponError && items.length > 0 && (
|
|
@@ -108,14 +117,22 @@ const SellerCouponCheckout = ({
|
|
|
108
117
|
</div>
|
|
109
118
|
<div className={listClasses.divider} aria-hidden="true" />
|
|
110
119
|
<div className={listClasses.actions}>
|
|
111
|
-
<button
|
|
120
|
+
{isCopyAction ? <button
|
|
112
121
|
type="button"
|
|
113
|
-
className={listClasses.claimBtn}
|
|
122
|
+
className={copied === item.code ? listClasses.claimedBtn : listClasses.claimBtn}
|
|
114
123
|
onClick={() => handleClaim(item)}
|
|
115
124
|
aria-label={`Claim coupon ${item.code}`}
|
|
116
125
|
>
|
|
117
126
|
{copied === item.code ? 'Copied' : 'Claim'}
|
|
118
|
-
</button>
|
|
127
|
+
</button> :
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
className={copied === item.code ? listClasses.claimedBtn : listClasses.claimBtn}
|
|
131
|
+
onClick={() => handleClaim(item)}
|
|
132
|
+
aria-label={`Apply coupon ${item.code}`}
|
|
133
|
+
>
|
|
134
|
+
{copied === item.code ? 'Applied' : 'Apply'}
|
|
135
|
+
</button>}
|
|
119
136
|
</div>
|
|
120
137
|
</div>
|
|
121
138
|
);
|
|
@@ -128,20 +145,20 @@ const SellerCouponCheckout = ({
|
|
|
128
145
|
) : null;
|
|
129
146
|
|
|
130
147
|
const trigger = onTriggerRender
|
|
131
|
-
? onTriggerRender({
|
|
148
|
+
? onTriggerRender({ couponModalOpen, setCouponModalOpen, handleOpen })
|
|
132
149
|
: (
|
|
133
150
|
<button
|
|
134
151
|
type="button"
|
|
135
152
|
className={modalClasses.triggerBtn}
|
|
136
153
|
onClick={handleOpen}
|
|
137
154
|
aria-haspopup="dialog"
|
|
138
|
-
aria-expanded={
|
|
155
|
+
aria-expanded={couponModalOpen}
|
|
139
156
|
>
|
|
140
157
|
{triggerLabel}
|
|
141
158
|
</button>
|
|
142
159
|
);
|
|
143
160
|
|
|
144
|
-
return <>{onTriggerRender ? trigger : trigger}{
|
|
161
|
+
return <>{onTriggerRender ? trigger : trigger}{couponModalOpen ? ReactDOM.createPortal(modal, getPortalRoot()) : null}</>;
|
|
145
162
|
};
|
|
146
163
|
|
|
147
164
|
export default SellerCouponCheckout;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Shimmer from '@magento/venia-ui/lib/components/Shimmer';
|
|
3
|
+
|
|
4
|
+
const SellerCouponCheckout = props => {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<Shimmer width="100%" height="85.1px" />
|
|
8
|
+
<Shimmer width="100%" height="85.1px" />
|
|
9
|
+
<Shimmer width="100%" height="85.1px" />
|
|
10
|
+
<Shimmer width="100%" height="85.1px" />
|
|
11
|
+
<Shimmer width="100%" height="85.1px" />
|
|
12
|
+
<Shimmer width="100%" height="85.1px" />
|
|
13
|
+
<Shimmer width="100%" height="85.1px" />
|
|
14
|
+
<Shimmer width="100%" height="85.1px" />
|
|
15
|
+
<Shimmer width="100%" height="85.1px" />
|
|
16
|
+
<Shimmer width="100%" height="85.1px" />
|
|
17
|
+
</>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default SellerCouponCheckout;
|
|
@@ -104,8 +104,6 @@ export const usePriceSummary = (props = {}) => {
|
|
|
104
104
|
// }
|
|
105
105
|
// });
|
|
106
106
|
|
|
107
|
-
await setCheckoutState(true);
|
|
108
|
-
|
|
109
107
|
await createSellerCart({ initCheckoutSplitCart, sellerUrl });
|
|
110
108
|
|
|
111
109
|
await removeCart();
|
|
@@ -114,6 +112,8 @@ export const usePriceSummary = (props = {}) => {
|
|
|
114
112
|
await createCart({
|
|
115
113
|
fetchCartId
|
|
116
114
|
});
|
|
115
|
+
|
|
116
|
+
await setCheckoutState(true);
|
|
117
117
|
|
|
118
118
|
history.push('/checkout');
|
|
119
119
|
}, [history, setCheckoutState, createSellerCart, fetchCartId, createCart, apolloClient, removeCart, cartId, initCheckoutSplitCart, initCheckoutSplitCartData]);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useLazyQuery } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from '@magento/peregrine/lib/talons/CartPage/cartPage.gql';
|
|
7
|
+
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
8
|
+
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This talon contains logic for a cart page component.
|
|
12
|
+
* It performs effects and returns prop data for rendering the component.
|
|
13
|
+
*
|
|
14
|
+
* This talon performs the following effects:
|
|
15
|
+
*
|
|
16
|
+
* - Manages the updating state of the cart while cart details data is being fetched
|
|
17
|
+
*
|
|
18
|
+
* @function
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} props
|
|
21
|
+
* @param {CartPageQueries} props.queries GraphQL queries
|
|
22
|
+
*
|
|
23
|
+
* @returns {CartPageTalonProps}
|
|
24
|
+
*
|
|
25
|
+
* @example <caption>Importing into your project</caption>
|
|
26
|
+
* import { useCartPage } from '@magento/peregrine/lib/talons/CartPage/useCartPage';
|
|
27
|
+
*/
|
|
28
|
+
export const useCartPage = (props = {}) => {
|
|
29
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
30
|
+
const { getCartDetailsQuery } = operations;
|
|
31
|
+
|
|
32
|
+
const [{ cartId }] = useCartContext();
|
|
33
|
+
const [{ isSignedIn }] = useUserContext();
|
|
34
|
+
|
|
35
|
+
const [isProceedToCheckout, setIsProceedToCheckout] = useState(false);
|
|
36
|
+
|
|
37
|
+
const [isCartUpdating, setIsCartUpdating] = useState(false);
|
|
38
|
+
const [wishlistSuccessProps, setWishlistSuccessProps] = useState(null);
|
|
39
|
+
|
|
40
|
+
const [fetchCartDetails, { called, data, loading }] = useLazyQuery(
|
|
41
|
+
getCartDetailsQuery,
|
|
42
|
+
{
|
|
43
|
+
fetchPolicy: 'cache-and-network',
|
|
44
|
+
nextFetchPolicy: 'cache-first',
|
|
45
|
+
errorPolicy: 'all'
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const hasItems = !!data?.cart?.total_quantity;
|
|
50
|
+
const shouldShowLoadingIndicator = called && loading && !hasItems;
|
|
51
|
+
|
|
52
|
+
const cartItems = useMemo(() => {
|
|
53
|
+
return data?.cart?.items || [];
|
|
54
|
+
}, [data]);
|
|
55
|
+
|
|
56
|
+
const onAddToWishlistSuccess = useCallback(successToastProps => {
|
|
57
|
+
setWishlistSuccessProps(successToastProps);
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
const [, { dispatch }] = useEventingContext();
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!called && cartId) {
|
|
64
|
+
fetchCartDetails({ variables: { cartId } });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Let the cart page know it is updating while we're waiting on network data.
|
|
68
|
+
setIsCartUpdating(loading);
|
|
69
|
+
}, [fetchCartDetails, called, cartId, loading]);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (called && cartId && !loading) {
|
|
73
|
+
dispatch({
|
|
74
|
+
type: 'CART_PAGE_VIEW',
|
|
75
|
+
payload: {
|
|
76
|
+
cart_id: cartId,
|
|
77
|
+
products: cartItems
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}, [called, cartItems, cartId, loading, dispatch]);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
cartItems,
|
|
85
|
+
hasItems,
|
|
86
|
+
isCartUpdating,
|
|
87
|
+
isGuestCheckout: !isSignedIn,
|
|
88
|
+
fetchCartDetails,
|
|
89
|
+
onAddToWishlistSuccess,
|
|
90
|
+
setIsCartUpdating,
|
|
91
|
+
shouldShowLoadingIndicator,
|
|
92
|
+
wishlistSuccessProps,
|
|
93
|
+
isProceedToCheckout,
|
|
94
|
+
setIsProceedToCheckout
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** JSDoc type definitions */
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* GraphQL formatted string queries used in this talon.
|
|
102
|
+
*
|
|
103
|
+
* @typedef {Object} CartPageQueries
|
|
104
|
+
*
|
|
105
|
+
* @property {GraphQLAST} getCartDetailsQuery Query for getting the cart details.
|
|
106
|
+
*
|
|
107
|
+
* @see [cartPage.gql.js]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/cartPage.gql.js}
|
|
108
|
+
* for queries used in Venia
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Props data to use when rendering a cart page component.
|
|
113
|
+
*
|
|
114
|
+
* @typedef {Object} CartPageTalonProps
|
|
115
|
+
*
|
|
116
|
+
* @property {Array<Object>} cartItems An array of item objects in the cart.
|
|
117
|
+
* @property {boolean} hasItems True if the cart has items. False otherwise.
|
|
118
|
+
* @property {boolean} isCartUpdating True if the cart is updating. False otherwise.
|
|
119
|
+
* @property {function} setIsCartUpdating Callback function for setting the updating state of the cart page.
|
|
120
|
+
* @property {boolean} shouldShowLoadingIndicator True if the loading indicator should be rendered. False otherwise.
|
|
121
|
+
*/
|
package/src/overwrites/venia-ui/lib/components/CartPage/PriceAdjustments/CouponCode/couponCode.js
CHANGED
|
@@ -93,31 +93,31 @@ const CouponCode = props => {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if (data.cart.applied_coupons) {
|
|
96
|
-
const codes = data.cart.applied_coupons.map(({ code }) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
96
|
+
// const codes = data.cart.applied_coupons.map(({ code }) => {
|
|
97
|
+
// return (
|
|
98
|
+
// <Fragment key={code}>
|
|
99
|
+
// <span>{code}</span>
|
|
100
|
+
// <LinkButton
|
|
101
|
+
// className={classes.removeButton}
|
|
102
|
+
// disabled={removingCoupon}
|
|
103
|
+
// data-cy="CouponCode-removeCouponButton"
|
|
104
|
+
// onClick={() => {
|
|
105
|
+
// handleRemoveCoupon(code);
|
|
106
|
+
// }}
|
|
107
|
+
// onKeyDown={() => {
|
|
108
|
+
// handleRemoveCouponOnEnter(code);
|
|
109
|
+
// }}
|
|
110
|
+
// >
|
|
111
|
+
// <FormattedMessage
|
|
112
|
+
// id={'couponCode.removeButton'}
|
|
113
|
+
// defaultMessage={'Remove'}
|
|
114
|
+
// />
|
|
115
|
+
// </LinkButton>
|
|
116
|
+
// </Fragment>
|
|
117
|
+
// );
|
|
118
|
+
// });
|
|
119
119
|
|
|
120
|
-
return
|
|
120
|
+
return '';
|
|
121
121
|
} else {
|
|
122
122
|
const errorMessage = deriveErrorMessage([
|
|
123
123
|
errors.get('applyCouponMutation')
|
|
@@ -160,9 +160,6 @@ const CouponCode = props => {
|
|
|
160
160
|
priority={'normal'}
|
|
161
161
|
type={'submit'}
|
|
162
162
|
onKeyDown={handleApplyCouponOnEnter}
|
|
163
|
-
classes={{
|
|
164
|
-
content: 'gap-1.5 grid-flow-col inline-grid items-center justify-center justify-items-center capitalize font-medium'
|
|
165
|
-
}}
|
|
166
163
|
>
|
|
167
164
|
<FormattedMessage
|
|
168
165
|
id={'couponCode.apply'}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
.entryForm,
|
|
3
3
|
.entryFormError {
|
|
4
4
|
composes: gap-x-sm from global;
|
|
5
|
+
composes: pb-2 from global;
|
|
5
6
|
composes: grid from global;
|
|
6
7
|
composes: grid-cols-autoLast from global;
|
|
7
8
|
}
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
/* switch to rows. */
|
|
15
16
|
grid-template-columns: unset;
|
|
16
17
|
grid-template-rows: 1fr 1fr;
|
|
18
|
+
composes: pb-2 from global;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -10,6 +10,7 @@ import GiftCardSummary from './giftCardSummary';
|
|
|
10
10
|
import GiftOptionsSummary from './giftOptionsSummary';
|
|
11
11
|
import ShippingSummary from './shippingSummary';
|
|
12
12
|
import TaxSummary from './taxSummary';
|
|
13
|
+
import Shimmer from '@magento/venia-ui/lib/components/Shimmer';
|
|
13
14
|
import cn from 'classnames';
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -74,9 +75,10 @@ const PriceSummary = props => {
|
|
|
74
75
|
|
|
75
76
|
const isPriceUpdating = isUpdating || isLoading;
|
|
76
77
|
const priceClass = isPriceUpdating ? classes.priceUpdating : classes.price;
|
|
77
|
-
const totalPriceClass =
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const totalPriceClass = classes.totalPrice;
|
|
79
|
+
// const totalPriceClass = isPriceUpdating
|
|
80
|
+
// ? classes.priceUpdating
|
|
81
|
+
// : classes.totalPrice;
|
|
80
82
|
|
|
81
83
|
const totalPriceLabel = isCheckout
|
|
82
84
|
? formatMessage({
|
|
@@ -88,7 +90,7 @@ const PriceSummary = props => {
|
|
|
88
90
|
defaultMessage: 'Estimated Total'
|
|
89
91
|
});
|
|
90
92
|
|
|
91
|
-
const proceedToCheckoutButton = (
|
|
93
|
+
const proceedToCheckoutButton = !isCheckout && (
|
|
92
94
|
<div className={cn(classes.checkoutButton_container, 'block !mt-6 !min-h-auto')}>
|
|
93
95
|
<Button
|
|
94
96
|
disabled={isPriceUpdating}
|
|
@@ -127,8 +129,15 @@ const PriceSummary = props => {
|
|
|
127
129
|
);
|
|
128
130
|
|
|
129
131
|
return (
|
|
130
|
-
<div className={cn(classes.root, 'pb-6 px-3')} data-cy="PriceSummary-root">
|
|
132
|
+
<div className={cn(classes.root, isCheckout ? 'pb-0 px-3' : 'pb-6 px-3')} data-cy="PriceSummary-root">
|
|
131
133
|
{isCheckout && (
|
|
134
|
+
isPriceUpdating ? <>
|
|
135
|
+
<Shimmer width="100%" height="20px" />
|
|
136
|
+
<Shimmer width="100%" height="20px" />
|
|
137
|
+
<Shimmer width="100%" height="20px" />
|
|
138
|
+
<Shimmer width="100%" height="20px" />
|
|
139
|
+
<Shimmer width="100%" height="20px" />
|
|
140
|
+
</> :
|
|
132
141
|
<div>
|
|
133
142
|
<ul>
|
|
134
143
|
<li className={classes.lineItems}>
|
|
@@ -75,10 +75,6 @@ const CartPage = props => {
|
|
|
75
75
|
return fullPageLoadingIndicator;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
const priceSummary = hasItems ? (
|
|
79
|
-
<PriceSummary isUpdating={isCartUpdating} />
|
|
80
|
-
) : null;
|
|
81
|
-
|
|
82
78
|
const productListing = hasItems ? (
|
|
83
79
|
<ProductListing
|
|
84
80
|
onAddToWishlistSuccess={onAddToWishlistSuccess}
|
|
@@ -132,9 +128,6 @@ const CartPage = props => {
|
|
|
132
128
|
{priceAdjustments}
|
|
133
129
|
</div> */}
|
|
134
130
|
{/* <div className={classes.summary_container}>
|
|
135
|
-
<div className={classes.summary_contents}>
|
|
136
|
-
{priceSummary}
|
|
137
|
-
</div>
|
|
138
131
|
</div> */}
|
|
139
132
|
</div>
|
|
140
133
|
</div>
|