@riosst100/pwa-marketplace 1.0.2 → 1.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/package.json +1 -1
- package/src/componentOverrideMapping.js +5 -1
- package/src/components/BecomeSeller/becomeSeller.js +181 -78
- package/src/components/BecomeSeller/becomeSeller.module.css +0 -1
- package/src/components/BecomeSellerLink/becomeSellerLink.js +21 -4
- package/src/components/BecomeSellerPage/becomeSellerPage.js +6 -11
- package/src/components/SellerAccountPage/index.js +1 -0
- package/src/components/SellerAccountPage/sellerAccountPage.js +138 -0
- package/src/components/SellerAccountPage/sellerAccountPage.module.css +55 -0
- package/src/components/SellerVerification/index.js +1 -0
- package/src/components/SellerVerification/sellerVerification.js +198 -0
- package/src/components/SellerVerification/sellerVerification.module.css +47 -0
- package/src/components/SellerVerificationPage/index.js +1 -0
- package/src/components/SellerVerificationPage/sellerVerificationPage.js +43 -0
- package/src/components/SellerVerificationPage/sellerVerificationPage.module.css +21 -0
- package/src/components/WebsiteSwitcher/websiteSwitcher.js +2 -2
- package/src/intercept.js +11 -1
- package/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js +96 -0
- package/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js +65 -0
- package/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js +56 -0
- package/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js +226 -0
- package/src/overwrites/venia-ui/lib/components/Header/storeSwitcher.js +2 -2
- package/src/talons/BecomeSeller/becomeSeller.gql.js +34 -124
- package/src/talons/BecomeSeller/useBecomeSeller.js +50 -192
- package/src/talons/BecomeSellerLink/useBecomeSellerLink.js +6 -8
- package/src/talons/BecomeSellerPage/useBecomeSellerPage.js +12 -14
- package/src/talons/SellerAccountPage/useSellerAccountPage.js +174 -0
- package/src/talons/WebsiteByIp/useWebsiteByIp.js +2 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { useCallback, useRef, useState, useMemo } from 'react';
|
|
2
|
+
import { useApolloClient, useMutation } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
import { useGoogleReCaptcha } from '@magento/peregrine/lib/hooks/useGoogleReCaptcha/useGoogleReCaptcha';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
7
|
+
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
8
|
+
import { useAwaitQuery } from '@magento/peregrine/lib/hooks/useAwaitQuery';
|
|
9
|
+
import { retrieveCartId } from '@magento/peregrine/lib/store/actions/cart';
|
|
10
|
+
|
|
11
|
+
import DEFAULT_OPERATIONS from '@magento/peregrine/lib/talons/SignIn/signIn.gql';
|
|
12
|
+
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
13
|
+
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
14
|
+
|
|
15
|
+
const storage = new BrowserPersistence();
|
|
16
|
+
|
|
17
|
+
export const useSignIn = props => {
|
|
18
|
+
const {
|
|
19
|
+
handleTriggerClick,
|
|
20
|
+
getCartDetailsQuery,
|
|
21
|
+
setDefaultUsername,
|
|
22
|
+
showCreateAccount,
|
|
23
|
+
showForgotPassword
|
|
24
|
+
} = props;
|
|
25
|
+
|
|
26
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
27
|
+
const {
|
|
28
|
+
createCartMutation,
|
|
29
|
+
getCustomerQuery,
|
|
30
|
+
mergeCartsMutation,
|
|
31
|
+
signInMutation
|
|
32
|
+
} = operations;
|
|
33
|
+
|
|
34
|
+
const apolloClient = useApolloClient();
|
|
35
|
+
const [isSigningIn, setIsSigningIn] = useState(false);
|
|
36
|
+
|
|
37
|
+
const [
|
|
38
|
+
{ cartId },
|
|
39
|
+
{ createCart, removeCart, getCartDetails }
|
|
40
|
+
] = useCartContext();
|
|
41
|
+
|
|
42
|
+
const [
|
|
43
|
+
{ isGettingDetails, getDetailsError },
|
|
44
|
+
{ getUserDetails, setToken }
|
|
45
|
+
] = useUserContext();
|
|
46
|
+
|
|
47
|
+
const [, { dispatch }] = useEventingContext();
|
|
48
|
+
|
|
49
|
+
const [signIn, { error: signInError }] = useMutation(signInMutation, {
|
|
50
|
+
fetchPolicy: 'no-cache'
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
generateReCaptchaData,
|
|
55
|
+
recaptchaLoading,
|
|
56
|
+
recaptchaWidgetProps
|
|
57
|
+
} = useGoogleReCaptcha({
|
|
58
|
+
currentForm: 'CUSTOMER_LOGIN',
|
|
59
|
+
formAction: 'signIn'
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const [fetchCartId] = useMutation(createCartMutation);
|
|
63
|
+
const [mergeCarts] = useMutation(mergeCartsMutation);
|
|
64
|
+
const fetchUserDetails = useAwaitQuery(getCustomerQuery);
|
|
65
|
+
const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);
|
|
66
|
+
|
|
67
|
+
const formApiRef = useRef(null);
|
|
68
|
+
const setFormApi = useCallback(api => (formApiRef.current = api), []);
|
|
69
|
+
|
|
70
|
+
const handleSubmit = useCallback(
|
|
71
|
+
async ({ email, password }) => {
|
|
72
|
+
setIsSigningIn(true);
|
|
73
|
+
// handleTriggerClick();
|
|
74
|
+
try {
|
|
75
|
+
// Get source cart id (guest cart id).
|
|
76
|
+
const sourceCartId = cartId;
|
|
77
|
+
|
|
78
|
+
// Get recaptchaV3 data for login
|
|
79
|
+
const recaptchaData = await generateReCaptchaData();
|
|
80
|
+
|
|
81
|
+
// Sign in and set the token.
|
|
82
|
+
const signInResponse = await signIn({
|
|
83
|
+
variables: {
|
|
84
|
+
email,
|
|
85
|
+
password
|
|
86
|
+
},
|
|
87
|
+
...recaptchaData
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const token = signInResponse.data.generateCustomerToken.token;
|
|
91
|
+
await setToken(token);
|
|
92
|
+
|
|
93
|
+
// Clear all cart/customer data from cache and redux.
|
|
94
|
+
await apolloClient.clearCacheData(apolloClient, 'cart');
|
|
95
|
+
await apolloClient.clearCacheData(apolloClient, 'customer');
|
|
96
|
+
await removeCart();
|
|
97
|
+
|
|
98
|
+
// Create and get the customer's cart id.
|
|
99
|
+
await createCart({
|
|
100
|
+
fetchCartId
|
|
101
|
+
});
|
|
102
|
+
const destinationCartId = await retrieveCartId();
|
|
103
|
+
|
|
104
|
+
// Merge the guest cart into the customer cart.
|
|
105
|
+
await mergeCarts({
|
|
106
|
+
variables: {
|
|
107
|
+
destinationCartId,
|
|
108
|
+
sourceCartId
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Ensure old stores are updated with any new data.
|
|
113
|
+
|
|
114
|
+
await getUserDetails({ fetchUserDetails });
|
|
115
|
+
|
|
116
|
+
const { data } = await fetchUserDetails({
|
|
117
|
+
fetchPolicy: 'cache-only'
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
console.log(data.customer)
|
|
121
|
+
|
|
122
|
+
if (data.customer.is_seller) {
|
|
123
|
+
storage.setItem('is_seller', true);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
dispatch({
|
|
127
|
+
type: 'USER_SIGN_IN',
|
|
128
|
+
payload: {
|
|
129
|
+
...data.customer
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
getCartDetails({ fetchCartId, fetchCartDetails });
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
136
|
+
console.error(error);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
setIsSigningIn(false);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
[
|
|
143
|
+
cartId,
|
|
144
|
+
generateReCaptchaData,
|
|
145
|
+
signIn,
|
|
146
|
+
setToken,
|
|
147
|
+
apolloClient,
|
|
148
|
+
removeCart,
|
|
149
|
+
createCart,
|
|
150
|
+
fetchCartId,
|
|
151
|
+
mergeCarts,
|
|
152
|
+
getUserDetails,
|
|
153
|
+
fetchUserDetails,
|
|
154
|
+
getCartDetails,
|
|
155
|
+
fetchCartDetails,
|
|
156
|
+
dispatch,
|
|
157
|
+
handleTriggerClick
|
|
158
|
+
]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const handleForgotPassword = useCallback(() => {
|
|
162
|
+
const { current: formApi } = formApiRef;
|
|
163
|
+
|
|
164
|
+
if (formApi) {
|
|
165
|
+
setDefaultUsername(formApi.getValue('email'));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
showForgotPassword();
|
|
169
|
+
}, [setDefaultUsername, showForgotPassword]);
|
|
170
|
+
|
|
171
|
+
const forgotPasswordHandleEnterKeyPress = useCallback(() => {
|
|
172
|
+
event => {
|
|
173
|
+
if (event.key === 'Enter') {
|
|
174
|
+
handleForgotPassword();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}, [handleForgotPassword]);
|
|
178
|
+
|
|
179
|
+
const handleCreateAccount = useCallback(() => {
|
|
180
|
+
const { current: formApi } = formApiRef;
|
|
181
|
+
|
|
182
|
+
if (formApi) {
|
|
183
|
+
setDefaultUsername(formApi.getValue('email'));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
showCreateAccount();
|
|
187
|
+
}, [setDefaultUsername, showCreateAccount]);
|
|
188
|
+
|
|
189
|
+
const handleEnterKeyPress = useCallback(() => {
|
|
190
|
+
event => {
|
|
191
|
+
if (event.key === 'Enter') {
|
|
192
|
+
handleCreateAccount();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}, [handleCreateAccount]);
|
|
196
|
+
|
|
197
|
+
const signinHandleEnterKeyPress = useCallback(() => {
|
|
198
|
+
event => {
|
|
199
|
+
if (event.key === 'Enter') {
|
|
200
|
+
handleSubmit();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, [handleSubmit]);
|
|
204
|
+
|
|
205
|
+
const errors = useMemo(
|
|
206
|
+
() =>
|
|
207
|
+
new Map([
|
|
208
|
+
['getUserDetailsQuery', getDetailsError],
|
|
209
|
+
['signInMutation', signInError]
|
|
210
|
+
]),
|
|
211
|
+
[getDetailsError, signInError]
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
errors,
|
|
216
|
+
handleCreateAccount,
|
|
217
|
+
handleEnterKeyPress,
|
|
218
|
+
signinHandleEnterKeyPress,
|
|
219
|
+
handleForgotPassword,
|
|
220
|
+
forgotPasswordHandleEnterKeyPress,
|
|
221
|
+
handleSubmit,
|
|
222
|
+
isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
|
|
223
|
+
setFormApi,
|
|
224
|
+
recaptchaWidgetProps
|
|
225
|
+
};
|
|
226
|
+
};
|
|
@@ -74,7 +74,7 @@ const StoreSwitcher = props => {
|
|
|
74
74
|
|
|
75
75
|
let triggerLabel;
|
|
76
76
|
if (hasOnlyOneGroup) {
|
|
77
|
-
triggerLabel = `${currentStoreName}
|
|
77
|
+
triggerLabel = currentStoreName ? `${currentStoreName}` : '';
|
|
78
78
|
} else {
|
|
79
79
|
triggerLabel = `${currentGroupName} - ${currentStoreName}`;
|
|
80
80
|
}
|
|
@@ -84,7 +84,7 @@ const StoreSwitcher = props => {
|
|
|
84
84
|
<button
|
|
85
85
|
data-cy="StoreSwitcher-triggerButton"
|
|
86
86
|
className={classes.trigger}
|
|
87
|
-
aria-label={currentStoreName}
|
|
87
|
+
aria-label={currentStoreName || ''}
|
|
88
88
|
onClick={handleTriggerClick}
|
|
89
89
|
ref={storeMenuTriggerRef}
|
|
90
90
|
data-cy="StoreSwitcher-trigger"
|
|
@@ -1,136 +1,46 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
-
import { CheckoutPageFragment } from '@magento/peregrine/lib/talons/CheckoutPage/checkoutPageFragments.gql';
|
|
3
2
|
|
|
4
|
-
export const
|
|
3
|
+
export const BECOME_SELLER = gql`
|
|
5
4
|
mutation BecomeSeller(
|
|
6
|
-
$
|
|
7
|
-
$
|
|
8
|
-
$
|
|
9
|
-
$
|
|
10
|
-
$
|
|
5
|
+
$seller_type: String
|
|
6
|
+
$group_id: String!
|
|
7
|
+
$url_key: String!
|
|
8
|
+
$name: String!
|
|
9
|
+
$company: String
|
|
10
|
+
$company_registration_number: String
|
|
11
|
+
$country_id: String
|
|
12
|
+
$address_line_1: String!
|
|
13
|
+
$address_line_2: String
|
|
14
|
+
$city: String!
|
|
15
|
+
$region: String
|
|
16
|
+
$region_id: String
|
|
17
|
+
$postcode: String!
|
|
18
|
+
$contact_number: String!
|
|
11
19
|
) {
|
|
12
|
-
|
|
20
|
+
becomeSeller(
|
|
13
21
|
input: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
seller_type: $seller_type
|
|
23
|
+
group_id: $group_id
|
|
24
|
+
url_key: $url_key
|
|
25
|
+
name: $name
|
|
26
|
+
company: $company
|
|
27
|
+
company_registration_number: $company_registration_number,
|
|
28
|
+
country_id: $country_id
|
|
29
|
+
address_line_1: $address_line_1
|
|
30
|
+
address_line_2: $address_line_2
|
|
31
|
+
city: $city
|
|
32
|
+
region: $region
|
|
33
|
+
region_id: $region_id
|
|
34
|
+
postcode: $postcode
|
|
35
|
+
contact_number: $contact_number
|
|
19
36
|
}
|
|
20
37
|
) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
25
|
-
customer {
|
|
26
|
-
email
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
export const GET_CUSTOMER = gql`
|
|
33
|
-
query GetCustomerAfterCreate {
|
|
34
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
35
|
-
customer {
|
|
36
|
-
email
|
|
37
|
-
firstname
|
|
38
|
-
lastname
|
|
39
|
-
is_subscribed
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
export const SIGN_IN = gql`
|
|
45
|
-
mutation SignInAfterCreate($email: String!, $password: String!) {
|
|
46
|
-
generateCustomerToken(email: $email, password: $password) {
|
|
47
|
-
token
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
export const CREATE_CART = gql`
|
|
53
|
-
mutation CreateCartAfterAccountCreation {
|
|
54
|
-
cartId: createEmptyCart
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
export const GET_CART_DETAILS = gql`
|
|
59
|
-
query GetCartDetailsAfterAccountCreation($cartId: String!) {
|
|
60
|
-
cart(cart_id: $cartId) {
|
|
61
|
-
id
|
|
62
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
63
|
-
items {
|
|
64
|
-
uid
|
|
65
|
-
prices {
|
|
66
|
-
price {
|
|
67
|
-
value
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
71
|
-
product {
|
|
72
|
-
uid
|
|
73
|
-
name
|
|
74
|
-
sku
|
|
75
|
-
small_image {
|
|
76
|
-
url
|
|
77
|
-
label
|
|
78
|
-
}
|
|
79
|
-
price {
|
|
80
|
-
regularPrice {
|
|
81
|
-
amount {
|
|
82
|
-
value
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
quantity
|
|
88
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
89
|
-
... on ConfigurableCartItem {
|
|
90
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
91
|
-
configurable_options {
|
|
92
|
-
configurable_product_option_uid
|
|
93
|
-
option_label
|
|
94
|
-
configurable_product_option_value_uid
|
|
95
|
-
value_label
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
prices {
|
|
100
|
-
grand_total {
|
|
101
|
-
value
|
|
102
|
-
currency
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
export const MERGE_CARTS = gql`
|
|
110
|
-
mutation MergeCartsAfterAccountCreation(
|
|
111
|
-
$sourceCartId: String!
|
|
112
|
-
$destinationCartId: String!
|
|
113
|
-
) {
|
|
114
|
-
mergeCarts(
|
|
115
|
-
source_cart_id: $sourceCartId
|
|
116
|
-
destination_cart_id: $destinationCartId
|
|
117
|
-
) {
|
|
118
|
-
id
|
|
119
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
120
|
-
items {
|
|
121
|
-
uid
|
|
122
|
-
}
|
|
123
|
-
...CheckoutPageFragment
|
|
38
|
+
code
|
|
39
|
+
message
|
|
124
40
|
}
|
|
125
41
|
}
|
|
126
|
-
${CheckoutPageFragment}
|
|
127
42
|
`;
|
|
128
43
|
|
|
129
44
|
export default {
|
|
130
|
-
becomeSellerMutation:
|
|
131
|
-
|
|
132
|
-
getCartDetailsQuery: GET_CART_DETAILS,
|
|
133
|
-
getCustomerQuery: GET_CUSTOMER,
|
|
134
|
-
mergeCartsMutation: MERGE_CARTS,
|
|
135
|
-
signInMutation: SIGN_IN
|
|
136
|
-
};
|
|
45
|
+
becomeSellerMutation: BECOME_SELLER
|
|
46
|
+
};
|