@riosst100/pwa-marketplace 2.9.3 → 2.9.5
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 +1 -0
- package/i18n/id_ID.json +1 -0
- package/package.json +1 -1
- package/src/componentOverrideMapping.js +2 -1
- package/src/components/ConfirmEmailPage/confirmEmail.js +76 -0
- package/src/components/ConfirmEmailPage/confirmEmail.module.css +71 -0
- package/src/components/ConfirmEmailPage/index.js +1 -0
- package/src/components/FavoriteSellerPage/favoriteSeller.js +0 -1
- package/src/components/FavoriteSellerPage/item.js +0 -2
- package/src/components/OrderDetail/components/itemsOrdered.js +94 -82
- package/src/components/OrderDetail/orderDetail.js +102 -86
- package/src/components/SubCategory/subCategory.js +1 -1
- package/src/components/VerifyEmailPage/verifyEmail.js +33 -10
- package/src/intercept.js +8 -1
- package/src/overwrites/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js +2 -2
- package/src/overwrites/peregrine/lib/talons/CheckoutPage/useCheckoutPage.js +43 -2
- package/src/overwrites/peregrine/lib/talons/FilterSidebar/useFilterSidebar.js +4 -1
- package/src/overwrites/peregrine/lib/talons/OrderHistoryPage/orderHistoryPage.gql.js +116 -0
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/useCategoryContent.js +7 -0
- package/src/overwrites/venia-ui/lib/components/AccountInformationPage/DeleteAccount.js +5 -37
- package/src/overwrites/venia-ui/lib/components/Adapter/adapter.js +3 -1
- package/src/overwrites/venia-ui/lib/components/Breadcrumbs/breadcrumbs.js +53 -58
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/OrderConfirmationPage/orderConfirmationPage.js +68 -39
- package/src/overwrites/venia-ui/lib/components/CheckoutPage/checkoutPage.js +1 -1
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/orderHistoryPage.js +10 -2
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/orderRow.js +91 -78
- package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/orderRow.module.css +3 -3
- package/src/overwrites/venia-ui/lib/components/StoreCodeRoute/storeCodeRoute.js +1 -1
- package/src/talons/AccountInformationPage/deleteAccount.gql.js +23 -0
- package/src/talons/AccountInformationPage/useDeleteAccount.js +98 -0
- package/src/talons/ConfirmEmailPage/confirmEmailPage.gql.js +20 -0
- package/src/talons/ConfirmEmailPage/useConfirmEmailPage.js +78 -0
- package/src/talons/OrderHistoryPage/useOrderHistoryPage.js +115 -0
- package/src/talons/ShopBy/useShopBy.js +12 -2
- package/src/talons/VerifyEmailPage/useVerifyEmailPage.js +73 -0
- package/src/talons/VerifyEmailPage/verifyEmailPage.gql.js +36 -0
- package/src/talons/WebsiteSwitcher/useWebsiteSwitcher.js +13 -2
|
@@ -12,7 +12,7 @@ import OrderProgressBar from './orderProgressBar';
|
|
|
12
12
|
import OrderDetails from './OrderDetails';
|
|
13
13
|
import defaultClasses from './orderRow.module.css';
|
|
14
14
|
import cn from 'classnames';
|
|
15
|
-
import { Verify } from 'iconsax-react';
|
|
15
|
+
import { Verify, Shop } from 'iconsax-react';
|
|
16
16
|
import PlaceholderImage from '@magento/venia-ui/lib/components/Image/placeholderImage';
|
|
17
17
|
import { Link } from 'react-router-dom';
|
|
18
18
|
|
|
@@ -28,6 +28,7 @@ const OrderRow = props => {
|
|
|
28
28
|
status,
|
|
29
29
|
total
|
|
30
30
|
} = order;
|
|
31
|
+
|
|
31
32
|
const { grand_total: grandTotal } = total;
|
|
32
33
|
const { currency, value: orderTotal } = grandTotal;
|
|
33
34
|
|
|
@@ -72,6 +73,11 @@ const OrderRow = props => {
|
|
|
72
73
|
|
|
73
74
|
const classes = useStyle(defaultClasses, props.classes);
|
|
74
75
|
|
|
76
|
+
// Determine seller/store name from first item if available
|
|
77
|
+
const sellerName = items && items.length > 0 && items[0] && items[0].seller_name
|
|
78
|
+
? items[0].seller_name
|
|
79
|
+
: '-';
|
|
80
|
+
|
|
75
81
|
const contentClass = isOpen ? classes.content : classes.content_collapsed;
|
|
76
82
|
|
|
77
83
|
const contentToggleIconSrc = isOpen ? ChevronUp : ChevronDown;
|
|
@@ -94,7 +100,7 @@ const OrderRow = props => {
|
|
|
94
100
|
);
|
|
95
101
|
|
|
96
102
|
const badgeStatusStyle = () => {
|
|
97
|
-
return '
|
|
103
|
+
return 'text-blue-700 text-[14px] font-medium py-[5px] border-none';
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
const thumbnailProps = {
|
|
@@ -103,13 +109,37 @@ const OrderRow = props => {
|
|
|
103
109
|
width: 50
|
|
104
110
|
};
|
|
105
111
|
|
|
112
|
+
// Helper to resolve a product image by SKU with graceful fallback
|
|
113
|
+
const getThumbnailForSku = (sku, fallbackLabel) => {
|
|
114
|
+
let url = null;
|
|
115
|
+
let label = fallbackLabel;
|
|
116
|
+
if (imagesData && typeof imagesData === 'object') {
|
|
117
|
+
const byKey = sku && imagesData[sku];
|
|
118
|
+
const byValue = !byKey && sku
|
|
119
|
+
? Object.values(imagesData).find(entry => entry?.sku === sku)
|
|
120
|
+
: null;
|
|
121
|
+
const chosen = byKey || byValue;
|
|
122
|
+
if (chosen?.thumbnail?.url) {
|
|
123
|
+
url = chosen.thumbnail.url;
|
|
124
|
+
label = chosen.thumbnail.label || label;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { url, label };
|
|
128
|
+
};
|
|
129
|
+
|
|
106
130
|
return (
|
|
107
131
|
<li className={classes.root}>
|
|
108
|
-
<div className='flex flex-col md_flex-row justify-between mb-2.5'>
|
|
109
|
-
<div className='flex flex-col'>
|
|
110
|
-
<div className="flex gap-x-[15px] flex-
|
|
111
|
-
<
|
|
112
|
-
|
|
132
|
+
<div className='flex flex-col md_flex-row md_items-start justify-between mb-2.5'>
|
|
133
|
+
<div className='flex flex-col ml-[14px] mt-[5px]'>
|
|
134
|
+
<div className="flex gap-x-[15px] flex-col">
|
|
135
|
+
<div className='flex gap-x-[5px] items-center'>
|
|
136
|
+
<Shop size={17} className='text-blue-700' variant="Bold" />
|
|
137
|
+
<span className='text-[14px] font-medium text-blue-700'>
|
|
138
|
+
{sellerName}
|
|
139
|
+
</span>
|
|
140
|
+
<span>|</span>
|
|
141
|
+
<span className="text-blue-700 text-[14px]">#{orderNumber}</span>
|
|
142
|
+
</div>
|
|
113
143
|
</div>
|
|
114
144
|
</div>
|
|
115
145
|
<div className='flex flex-col'>
|
|
@@ -121,90 +151,72 @@ const OrderRow = props => {
|
|
|
121
151
|
</div>
|
|
122
152
|
</div>
|
|
123
153
|
<div className='flex flex-col md_flex-row justify-between mb-2.5'>
|
|
124
|
-
<div className='flex flex-col'>
|
|
125
|
-
<div className='flex gap-x-[5px] mb-2.5'>
|
|
126
|
-
<Verify size={17} className='text-blue-700' variant="Bold" />
|
|
127
|
-
<span className='text-xs font-medium text-[rgba(25, 34, 42, 0.7)]'>
|
|
128
|
-
Gundam Info
|
|
129
|
-
</span>
|
|
130
|
-
</div>
|
|
154
|
+
<div className='flex flex-col ml-[14px]'>
|
|
131
155
|
<div className='flex flex-row'>
|
|
132
|
-
<div>
|
|
133
|
-
|
|
156
|
+
<div className={cn('mr-4 flex flex-col gap-8')}>
|
|
157
|
+
{items && items.length > 0 && items.map((it, idx) => {
|
|
158
|
+
const { url, label } = getThumbnailForSku(it.product_sku, it.product_name);
|
|
159
|
+
return (
|
|
160
|
+
<div key={it.id || idx} className={classes.productImage}>
|
|
161
|
+
{url ? (
|
|
162
|
+
<img
|
|
163
|
+
src={url}
|
|
164
|
+
alt={label}
|
|
165
|
+
width={60}
|
|
166
|
+
className={classes.thumbnail}
|
|
167
|
+
/>
|
|
168
|
+
) : (
|
|
169
|
+
<PlaceholderImage alt={it.product_name} classes={{ root: classes.thumbnail }} width={60} />
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
})}
|
|
134
174
|
</div>
|
|
135
|
-
<div className='flex flex-col max-w-[
|
|
136
|
-
|
|
137
|
-
<
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
</
|
|
149
|
-
|
|
175
|
+
<div className='flex flex-col max-w-[375px] gap-8'>
|
|
176
|
+
{items && items.length > 0 && items.map((it, idx) => (
|
|
177
|
+
<div key={it.id || idx} className='flex flex-col gap-1 pb-2 last_pb-0'>
|
|
178
|
+
<div className={cn(classes.productName, 'text-[14] font-medium')}>
|
|
179
|
+
<span>{it.product_name}</span>
|
|
180
|
+
</div>
|
|
181
|
+
<div className="text-[14] text-gray-300">
|
|
182
|
+
<span>Qty : {`${it.quantity_ordered}`}</span>
|
|
183
|
+
<br />
|
|
184
|
+
<span>
|
|
185
|
+
Price : <Price currencyCode={it?.product_sale_price?.currency} value={it?.product_sale_price?.value} />
|
|
186
|
+
</span>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
))}
|
|
150
190
|
</div>
|
|
151
191
|
</div>
|
|
152
192
|
</div>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
193
|
+
{/* Right column: bottom-aligned Order Total + CTA */}
|
|
194
|
+
<div className='flex flex-col items-end gap-2 md_pl-10 md_self-end mr-4 mb-1'>
|
|
195
|
+
<div className="md_text-right">
|
|
196
|
+
<span className="text-[14] text-gray-200 block mb-1">
|
|
156
197
|
<FormattedMessage
|
|
157
198
|
id={'orderRow.orderTotalText'}
|
|
158
199
|
defaultMessage={'Order Total'}
|
|
159
200
|
/>
|
|
160
201
|
</span>
|
|
161
|
-
<div className="text-lg font-medium
|
|
202
|
+
<div className="text-lg font-medium">{orderTotalPrice}</div>
|
|
162
203
|
</div>
|
|
204
|
+
<Link
|
|
205
|
+
to={{
|
|
206
|
+
pathname: `/order-history/view/${orderNumber}`,
|
|
207
|
+
state: { order }
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
<span className="bg-blue-700 hover:bg-white hover:text-blue-700 hover:border hover:border-blue-700 rounded-full px-[30px] py-[5px] text-[13px] font-medium text-white transition-all duration-300 ease-in-out">
|
|
211
|
+
<FormattedMessage
|
|
212
|
+
id={'orderRow.ViewTransactionDetail'}
|
|
213
|
+
defaultMessage={'View Order Detail'}
|
|
214
|
+
/>
|
|
215
|
+
</span>
|
|
216
|
+
</Link>
|
|
163
217
|
</div>
|
|
164
218
|
</div>
|
|
165
|
-
|
|
166
|
-
{/* <button
|
|
167
|
-
className={cn(classes.contentToggleContainer, '!p-0 !border-0')}
|
|
168
|
-
onClick={handleContentToggle}
|
|
169
|
-
type="button"
|
|
170
|
-
aria-expanded={isOpen}
|
|
171
|
-
>
|
|
172
|
-
<span className="text-[13px] font-medium text-blue-700 underline">
|
|
173
|
-
<FormattedMessage
|
|
174
|
-
id={'orderRow.ViewTransactionDetail'}
|
|
175
|
-
defaultMessage={'View Transaction Detail'}
|
|
176
|
-
/>
|
|
177
|
-
</span>
|
|
178
|
-
</button> */}
|
|
179
|
-
<Link to="/order-history/view/123213">
|
|
180
|
-
<span className="text-[13px] font-medium text-blue-700 underline">
|
|
181
|
-
<FormattedMessage
|
|
182
|
-
id={'orderRow.ViewTransactionDetail'}
|
|
183
|
-
defaultMessage={'View Transaction Detail'}
|
|
184
|
-
/>
|
|
185
|
-
</span>
|
|
186
|
-
</Link>
|
|
187
|
-
</div>
|
|
188
|
-
|
|
189
|
-
{/* <div className={classes.orderDateContainer}>
|
|
190
|
-
<span className={classes.orderDateLabel}>
|
|
191
|
-
<FormattedMessage
|
|
192
|
-
id={'orderRow.orderDateText'}
|
|
193
|
-
defaultMessage={'Order Date'}
|
|
194
|
-
/>
|
|
195
|
-
</span>
|
|
196
|
-
<span className={classes.orderDate}>{formattedDate}</span>
|
|
197
|
-
</div> */}
|
|
198
|
-
{/* <div className={classes.orderItemsContainer}>
|
|
199
|
-
{collapsedImageGalleryElement}
|
|
200
|
-
</div> */}
|
|
201
|
-
{/* <div className={classes.orderStatusContainer}>
|
|
202
|
-
<span className={classes.orderStatusBadge}>
|
|
203
|
-
{derivedStatus}
|
|
204
|
-
</span>
|
|
205
|
-
<OrderProgressBar status={derivedStatus} />
|
|
206
|
-
</div> */}
|
|
207
|
-
<div className={cn(contentClass, '!py-4 mt-4')}>{orderDetails}</div>
|
|
219
|
+
|
|
208
220
|
</li>
|
|
209
221
|
);
|
|
210
222
|
};
|
|
@@ -259,6 +271,7 @@ OrderRow.propTypes = {
|
|
|
259
271
|
value: string
|
|
260
272
|
})
|
|
261
273
|
),
|
|
274
|
+
seller_name: string,
|
|
262
275
|
quantity_ordered: number
|
|
263
276
|
})
|
|
264
277
|
),
|
|
@@ -101,14 +101,14 @@
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
.orderStatusBadge {
|
|
104
|
-
composes: border from global;
|
|
104
|
+
/* composes: border from global;
|
|
105
105
|
composes: border-solid from global;
|
|
106
|
-
composes: border-subtle from global;
|
|
106
|
+
composes: border-subtle from global; */
|
|
107
107
|
composes: font-bold from global;
|
|
108
108
|
composes: justify-self-start from global;
|
|
109
109
|
composes: px-xs from global;
|
|
110
110
|
composes: py-1 from global;
|
|
111
|
-
composes: rounded-md from global;
|
|
111
|
+
/* composes: rounded-md from global; */
|
|
112
112
|
composes: text-2xs from global;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -41,7 +41,7 @@ const StoreCodeRoute = () => {
|
|
|
41
41
|
// the storage value and refresh so that we start using the new code.
|
|
42
42
|
useEffect(() => {
|
|
43
43
|
if (!websiteCodeInUrl) {
|
|
44
|
-
history.replace(location.pathname)
|
|
44
|
+
history.replace(location.pathname + location.search)
|
|
45
45
|
} else if (websiteCodeInUrl && websiteCodeInUrl !== currentWebsiteCode) {
|
|
46
46
|
let storeCodeInUrl = websiteStores[websiteCodeInUrl];
|
|
47
47
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const DELETE_ACCOUNT = gql`
|
|
4
|
+
mutation DeleteAccount {
|
|
5
|
+
deleteCustomerAccount {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const SIGN_OUT = gql`
|
|
13
|
+
mutation SignOutFromMenu {
|
|
14
|
+
revokeCustomerToken {
|
|
15
|
+
result
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
deleteAccountMutation: DELETE_ACCOUNT,
|
|
22
|
+
signOutMutation: SIGN_OUT
|
|
23
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
4
|
+
import { useMutation, useQuery } from '@apollo/client';
|
|
5
|
+
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
6
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
7
|
+
import DEFAULT_OPERATIONS from './deleteAccount.gql';
|
|
8
|
+
import { useHistory } from 'react-router-dom';
|
|
9
|
+
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
10
|
+
import { useToasts } from '@magento/peregrine';
|
|
11
|
+
|
|
12
|
+
export const useDeleteAccount = (props = {}) => {
|
|
13
|
+
const [loading, setLoading] = useState(false);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const [success, setSuccess] = useState(false);
|
|
16
|
+
|
|
17
|
+
const { formatMessage } = useIntl();
|
|
18
|
+
|
|
19
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
20
|
+
const { signOutMutation } = operations;
|
|
21
|
+
|
|
22
|
+
const history = useHistory();
|
|
23
|
+
|
|
24
|
+
const [isSigningOut, setIsSigningOut] = useState(false);
|
|
25
|
+
const [{ currentUser, isSignedIn }, { signOut }] = useUserContext();
|
|
26
|
+
const [revokeToken] = useMutation(signOutMutation);
|
|
27
|
+
|
|
28
|
+
const [, { dispatch }] = useEventingContext();
|
|
29
|
+
const [, { addToast }] = useToasts();
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
deleteAccountMutation
|
|
33
|
+
} = operations;
|
|
34
|
+
|
|
35
|
+
const [deleteAccount, { data: deleteAccountData, error: deleteAccountError, loading: deleteAccountLoading}] = useMutation(
|
|
36
|
+
deleteAccountMutation,
|
|
37
|
+
{
|
|
38
|
+
fetchPolicy: 'no-cache'
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const handleDeleteAccount = useCallback(() => {
|
|
43
|
+
deleteAccount({});
|
|
44
|
+
}, [
|
|
45
|
+
setLoading,
|
|
46
|
+
deleteAccount,
|
|
47
|
+
deleteAccountError,
|
|
48
|
+
deleteAccountData
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const handleSignOut = useCallback(async () => {
|
|
52
|
+
setIsSigningOut(true);
|
|
53
|
+
|
|
54
|
+
dispatch({
|
|
55
|
+
type: 'USER_SIGN_OUT',
|
|
56
|
+
payload: currentUser
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Delete cart/user data from the redux stor`e.
|
|
60
|
+
await signOut({ revokeToken });
|
|
61
|
+
|
|
62
|
+
}, [history, revokeToken, signOut, dispatch, currentUser]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (deleteAccountLoading) {
|
|
66
|
+
setLoading(true);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (deleteAccountData && !deleteAccountLoading) {
|
|
70
|
+
if (deleteAccountData.deleteCustomerAccount.success) {
|
|
71
|
+
addToast({
|
|
72
|
+
type: 'info',
|
|
73
|
+
message: formatMessage({
|
|
74
|
+
id: 'deleteAccount.deleteAccountSuccess',
|
|
75
|
+
defaultMessage: 'Your account is deleted successfully.'
|
|
76
|
+
}),
|
|
77
|
+
timeout: 10000
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
handleSignOut();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setLoading(false);
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
deleteAccountData,
|
|
87
|
+
deleteAccountLoading,
|
|
88
|
+
handleSignOut,
|
|
89
|
+
addToast
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
loading,
|
|
94
|
+
error,
|
|
95
|
+
success,
|
|
96
|
+
handleDeleteAccount
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const CONFIRM_EMAIL = gql`
|
|
4
|
+
mutation ConfirmEmail(
|
|
5
|
+
$id: Int!
|
|
6
|
+
$key: String!
|
|
7
|
+
) {
|
|
8
|
+
confirmCustomerEmail(
|
|
9
|
+
id: $id
|
|
10
|
+
key: $key
|
|
11
|
+
) {
|
|
12
|
+
success
|
|
13
|
+
message
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
confirmCustomerEmailMutation: CONFIRM_EMAIL
|
|
20
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
|
|
2
|
+
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
4
|
+
import { useMutation } from '@apollo/client';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from './confirmEmailPage.gql';
|
|
7
|
+
import { useHistory } from 'react-router-dom';
|
|
8
|
+
import { useToasts } from '@magento/peregrine';
|
|
9
|
+
|
|
10
|
+
export const useConfirmEmailPage = (props = {}) => {
|
|
11
|
+
const { formatMessage } = useIntl();
|
|
12
|
+
|
|
13
|
+
const { id, key } = props;
|
|
14
|
+
|
|
15
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
16
|
+
|
|
17
|
+
const history = useHistory();
|
|
18
|
+
|
|
19
|
+
const [, { addToast }] = useToasts();
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
confirmCustomerEmailMutation
|
|
23
|
+
} = operations;
|
|
24
|
+
|
|
25
|
+
const [confirmEmail, { called: called, data: data, error: error, loading: loading}] = useMutation(
|
|
26
|
+
confirmCustomerEmailMutation,
|
|
27
|
+
{
|
|
28
|
+
fetchPolicy: 'no-cache'
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const handleConfirmEmail = useCallback(() => {
|
|
33
|
+
confirmEmail({
|
|
34
|
+
variables: {
|
|
35
|
+
id,
|
|
36
|
+
key
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}, [
|
|
40
|
+
confirmEmail,
|
|
41
|
+
id,
|
|
42
|
+
key
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
const shouldShowLoadingIndicator = called && loading;
|
|
46
|
+
const isSuccess = !loading && data && data.confirmCustomerEmail.success ? true : false;
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (data && !loading) {
|
|
51
|
+
if (data.confirmCustomerEmail.success) {
|
|
52
|
+
addToast({
|
|
53
|
+
type: 'success',
|
|
54
|
+
message: formatMessage({
|
|
55
|
+
id: 'emailConfirmation.confirmEmailSuccess',
|
|
56
|
+
defaultMessage: data.confirmCustomerEmail.message
|
|
57
|
+
}),
|
|
58
|
+
timeout: 10000
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// history.go(0)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, [
|
|
65
|
+
data,
|
|
66
|
+
loading,
|
|
67
|
+
addToast
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
loading,
|
|
72
|
+
error,
|
|
73
|
+
data,
|
|
74
|
+
handleConfirmEmail,
|
|
75
|
+
shouldShowLoadingIndicator,
|
|
76
|
+
isSuccess
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useQuery } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
import { useAppContext } from '@magento/peregrine/lib/context/app';
|
|
5
|
+
import { deriveErrorMessage } from '@magento/peregrine/lib/util/deriveErrorMessage';
|
|
6
|
+
import { usePagination } from '@magento/peregrine/lib/hooks/usePagination';
|
|
7
|
+
|
|
8
|
+
import operations from '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/OrderHistoryPage/orderHistoryPage.gql';
|
|
9
|
+
|
|
10
|
+
const PAGE_SIZE = 5;
|
|
11
|
+
|
|
12
|
+
// Custom Order History talon with page-based pagination
|
|
13
|
+
export const useOrderHistoryPage = (props = {}) => {
|
|
14
|
+
const { getCustomerOrdersQuery } = operations;
|
|
15
|
+
|
|
16
|
+
const [
|
|
17
|
+
,
|
|
18
|
+
{
|
|
19
|
+
actions: { setPageLoading }
|
|
20
|
+
}
|
|
21
|
+
] = useAppContext();
|
|
22
|
+
|
|
23
|
+
const [pageSize] = useState(PAGE_SIZE);
|
|
24
|
+
const [searchText, setSearchText] = useState('');
|
|
25
|
+
|
|
26
|
+
// Pagination state
|
|
27
|
+
const [paginationValues, paginationApi] = usePagination();
|
|
28
|
+
const { currentPage = 1, totalPages } = paginationValues;
|
|
29
|
+
const { setCurrentPage, setTotalPages } = paginationApi;
|
|
30
|
+
|
|
31
|
+
const { data, error, loading } = useQuery(getCustomerOrdersQuery, {
|
|
32
|
+
fetchPolicy: 'cache-and-network',
|
|
33
|
+
variables: {
|
|
34
|
+
filter: {
|
|
35
|
+
number: {
|
|
36
|
+
match: searchText
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
pageSize,
|
|
40
|
+
currentPage
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const ordersData = data && data.customer ? data.customer.orders : undefined;
|
|
45
|
+
const orders = ordersData && ordersData.items ? ordersData.items : [];
|
|
46
|
+
const totalCount = ordersData && typeof ordersData.total_count !== 'undefined' && ordersData.total_count !== null
|
|
47
|
+
? ordersData.total_count
|
|
48
|
+
: 0;
|
|
49
|
+
const totalPagesFromData = ordersData && ordersData.page_info && typeof ordersData.page_info.total_pages !== 'undefined'
|
|
50
|
+
? ordersData.page_info.total_pages
|
|
51
|
+
: null;
|
|
52
|
+
|
|
53
|
+
// Keep pagination total pages in sync with query result
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
setTotalPages(totalPagesFromData);
|
|
56
|
+
return () => setTotalPages(null);
|
|
57
|
+
}, [setTotalPages, totalPagesFromData]);
|
|
58
|
+
|
|
59
|
+
const isLoadingWithoutData = !data && loading;
|
|
60
|
+
const isBackgroundLoading = !!data && loading;
|
|
61
|
+
|
|
62
|
+
const pageInfo = useMemo(() => {
|
|
63
|
+
if (data) {
|
|
64
|
+
const currentShown = Math.min(currentPage * pageSize, totalCount);
|
|
65
|
+
return {
|
|
66
|
+
current: currentShown,
|
|
67
|
+
total: totalCount
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}, [data, currentPage, pageSize, totalCount]);
|
|
72
|
+
|
|
73
|
+
const derivedErrorMessage = useMemo(
|
|
74
|
+
() => deriveErrorMessage([error]),
|
|
75
|
+
[error]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const handleReset = useCallback(() => {
|
|
79
|
+
setSearchText('');
|
|
80
|
+
setCurrentPage(1);
|
|
81
|
+
}, [setCurrentPage]);
|
|
82
|
+
|
|
83
|
+
const handleSubmit = useCallback(
|
|
84
|
+
({ search }) => {
|
|
85
|
+
setSearchText(search);
|
|
86
|
+
setCurrentPage(1);
|
|
87
|
+
},
|
|
88
|
+
[setCurrentPage]
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Update the page indicator if the GraphQL query is in flight.
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
setPageLoading(isBackgroundLoading);
|
|
94
|
+
}, [isBackgroundLoading, setPageLoading]);
|
|
95
|
+
|
|
96
|
+
const pageControl = useMemo(
|
|
97
|
+
() => ({ currentPage, setPage: setCurrentPage, totalPages }),
|
|
98
|
+
[currentPage, setCurrentPage, totalPages]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
errorMessage: derivedErrorMessage,
|
|
103
|
+
handleReset,
|
|
104
|
+
handleSubmit,
|
|
105
|
+
isBackgroundLoading,
|
|
106
|
+
isLoadingWithoutData,
|
|
107
|
+
loadMoreOrders: null,
|
|
108
|
+
orders,
|
|
109
|
+
pageInfo,
|
|
110
|
+
searchText,
|
|
111
|
+
pageControl
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export default useOrderHistoryPage;
|
|
@@ -154,7 +154,12 @@ export const useShopBy = props => {
|
|
|
154
154
|
return null;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
let
|
|
157
|
+
let filter = rawData.find(item => item.attribute_code === shopby);
|
|
158
|
+
if (!filter) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let options = filter.options;
|
|
158
163
|
|
|
159
164
|
const mappingData = options.reduce((acc, item) => {
|
|
160
165
|
let firstLetter = item.label.charAt(0).toUpperCase();
|
|
@@ -184,7 +189,12 @@ export const useShopBy = props => {
|
|
|
184
189
|
return null;
|
|
185
190
|
}
|
|
186
191
|
|
|
187
|
-
let
|
|
192
|
+
let filter = rawData.find(item => item.attribute_code === shopby);
|
|
193
|
+
if (!filter) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let options = filter.options;
|
|
188
198
|
|
|
189
199
|
// const filteredSets = [];
|
|
190
200
|
|