@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.
Files changed (28) hide show
  1. package/package.json +1 -1
  2. package/src/componentOverrideMapping.js +5 -1
  3. package/src/components/BecomeSeller/becomeSeller.js +181 -78
  4. package/src/components/BecomeSeller/becomeSeller.module.css +0 -1
  5. package/src/components/BecomeSellerLink/becomeSellerLink.js +21 -4
  6. package/src/components/BecomeSellerPage/becomeSellerPage.js +6 -11
  7. package/src/components/SellerAccountPage/index.js +1 -0
  8. package/src/components/SellerAccountPage/sellerAccountPage.js +138 -0
  9. package/src/components/SellerAccountPage/sellerAccountPage.module.css +55 -0
  10. package/src/components/SellerVerification/index.js +1 -0
  11. package/src/components/SellerVerification/sellerVerification.js +198 -0
  12. package/src/components/SellerVerification/sellerVerification.module.css +47 -0
  13. package/src/components/SellerVerificationPage/index.js +1 -0
  14. package/src/components/SellerVerificationPage/sellerVerificationPage.js +43 -0
  15. package/src/components/SellerVerificationPage/sellerVerificationPage.module.css +21 -0
  16. package/src/components/WebsiteSwitcher/websiteSwitcher.js +2 -2
  17. package/src/intercept.js +11 -1
  18. package/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js +96 -0
  19. package/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js +65 -0
  20. package/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js +56 -0
  21. package/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js +226 -0
  22. package/src/overwrites/venia-ui/lib/components/Header/storeSwitcher.js +2 -2
  23. package/src/talons/BecomeSeller/becomeSeller.gql.js +34 -124
  24. package/src/talons/BecomeSeller/useBecomeSeller.js +50 -192
  25. package/src/talons/BecomeSellerLink/useBecomeSellerLink.js +6 -8
  26. package/src/talons/BecomeSellerPage/useBecomeSellerPage.js +12 -14
  27. package/src/talons/SellerAccountPage/useSellerAccountPage.js +174 -0
  28. package/src/talons/WebsiteByIp/useWebsiteByIp.js +2 -0
@@ -0,0 +1,198 @@
1
+ import React from 'react';
2
+ import { FormattedMessage, useIntl } from 'react-intl';
3
+ import { Form } from 'informed';
4
+ import { func, shape, string, bool } from 'prop-types';
5
+ import { useBecomeSeller } from '@riosst100/pwa-marketplace/src/talons/BecomeSeller/useBecomeSeller';
6
+
7
+ import { useStyle } from '@magento/venia-ui/lib/classify';
8
+ import combine from '@magento/venia-ui/lib/util/combineValidators';
9
+ import {
10
+ hasLengthAtLeast,
11
+ isRequired,
12
+ validatePassword
13
+ } from '@magento/venia-ui/lib/util/formValidators';
14
+ import Button from '@magento/venia-ui/lib/components/Button';
15
+ import Checkbox from '@magento/venia-ui/lib/components/Checkbox';
16
+ import Field from '@magento/venia-ui/lib/components/Field';
17
+ import Select from '@magento/venia-ui/lib/components/Select';
18
+ import TextInput from '@magento/venia-ui/lib/components/TextInput';
19
+ import defaultClasses from './sellerVerification.module.css';
20
+ import FormError from '@magento/venia-ui/lib/components/FormError';
21
+ import Password from '@magento/venia-ui/lib/components/Password';
22
+ import GoogleRecaptcha from '@magento/venia-ui/lib/components/GoogleReCaptcha';
23
+
24
+ const BecomeSeller = props => {
25
+ const talonProps = useBecomeSeller({
26
+ initialValues: props.initialValues,
27
+ onSubmit: props.onSubmit,
28
+ onCancel: props.onCancel
29
+ });
30
+
31
+ const {
32
+ errors,
33
+ handleSubmit,
34
+ handleEnterKeyPress,
35
+ isDisabled,
36
+ initialValues,
37
+ recaptchaWidgetProps
38
+ } = talonProps;
39
+ const { formatMessage } = useIntl();
40
+ const classes = useStyle(defaultClasses, props.classes);
41
+
42
+ const submitButton = (
43
+ <Button
44
+ className={classes.submitButton}
45
+ disabled={isDisabled}
46
+ type="submit"
47
+ priority="high"
48
+ onKeyDown={handleEnterKeyPress}
49
+ data-cy="BecomeSeller-submitButton"
50
+ >
51
+ <FormattedMessage
52
+ id={'sellerVerification.sellerVerificationText'}
53
+ defaultMessage={'Become a Seller'}
54
+ />
55
+ </Button>
56
+ );
57
+
58
+ const sellerTypeOptions = [
59
+ {
60
+ value: "individual",
61
+ label: "Individual"
62
+ },
63
+ {
64
+ value: "company",
65
+ label: "Company"
66
+ }
67
+ ];
68
+
69
+ return (
70
+ <Form
71
+ data-cy="BecomeSeller-form"
72
+ className={classes.root}
73
+ initialValues={initialValues}
74
+ onSubmit={handleSubmit}
75
+ >
76
+ <h2 data-cy="BecomeSeller-title" className={classes.title}>
77
+ <FormattedMessage
78
+ id={'sellerVerification.sellerVerificationText'}
79
+ defaultMessage={'Become a Seller'}
80
+ />
81
+ </h2>
82
+ <FormError errors={Array.from(errors.values())} />
83
+ <Field
84
+ id="sellerType"
85
+ label={formatMessage({
86
+ id: 'sellerVerification.sellerTypeText',
87
+ defaultMessage: 'Seller Type'
88
+ })}
89
+ >
90
+ <Select
91
+ field="seller.seller_type"
92
+ id={classes.root}
93
+ items={sellerTypeOptions}
94
+ />
95
+ </Field>
96
+ <Field
97
+ id="sellerProfileName"
98
+ label={formatMessage({
99
+ id: 'sellerVerification.sellerProfileNameText',
100
+ defaultMessage: 'Seller Profile Name'
101
+ })}
102
+ >
103
+ <TextInput
104
+ id="sellerProfileName"
105
+ field="seller.seller_profile_name"
106
+ validate={isRequired}
107
+ validateOnBlur
108
+ mask={value => value && value.trim()}
109
+ maskOnBlur={true}
110
+ data-cy="seller-profilename"
111
+ aria-label={formatMessage({
112
+ id: 'global.sellerProfileNameRequired',
113
+ defaultMessage: 'Seller Profile Name is required.'
114
+ })}
115
+ />
116
+ </Field>
117
+ <Field
118
+ id="companyName"
119
+ label={formatMessage({
120
+ id: 'sellerVerification.companyNameText',
121
+ defaultMessage: 'Company Name'
122
+ })}
123
+ >
124
+ <TextInput
125
+ id="companyName"
126
+ field="seller.company_name"
127
+ validate={isRequired}
128
+ validateOnBlur
129
+ mask={value => value && value.trim()}
130
+ maskOnBlur={true}
131
+ data-cy="seller-companyname"
132
+ aria-label={formatMessage({
133
+ id: 'global.companyNameRequired',
134
+ defaultMessage: 'Company Name Required'
135
+ })}
136
+ />
137
+ </Field>
138
+ <Field
139
+ id="storeURL"
140
+ label={formatMessage({
141
+ id: 'sellerVerification.storeURLText',
142
+ defaultMessage: 'Store URL'
143
+ })}
144
+ >
145
+ <TextInput
146
+ id="storeUrl"
147
+ field="seller.store_url"
148
+ validate={isRequired}
149
+ validateOnBlur
150
+ mask={value => value && value.trim()}
151
+ maskOnBlur={true}
152
+ data-cy="seller-storeurl"
153
+ aria-label={formatMessage({
154
+ id: 'global.storeUrlRequired',
155
+ defaultMessage: 'Store URL is required.'
156
+ })}
157
+ />
158
+ </Field>
159
+ <div className={classes.subscribe}>
160
+ <Checkbox
161
+ field="become_seller_agreement"
162
+ id="sellerVerificationAgreement"
163
+ label={formatMessage({
164
+ id: 'sellerVerification.sellerVerificationAgreementText',
165
+ defaultMessage: 'I agree the Terms and Condition (Terms and Conditions)'
166
+ })}
167
+ />
168
+ </div>
169
+ <GoogleRecaptcha {...recaptchaWidgetProps} />
170
+ <div className={classes.actions}>
171
+ {submitButton}
172
+ </div>
173
+ </Form>
174
+ );
175
+ };
176
+
177
+ BecomeSeller.propTypes = {
178
+ classes: shape({
179
+ actions: string,
180
+ lead: string,
181
+ root: string,
182
+ subscribe: string
183
+ }),
184
+ initialValues: shape({
185
+ sellerProfileName: string,
186
+ companyName: string
187
+ }),
188
+ isCancelButtonHidden: bool,
189
+ onSubmit: func,
190
+ onCancel: func
191
+ };
192
+
193
+ BecomeSeller.defaultProps = {
194
+ onCancel: () => {},
195
+ isCancelButtonHidden: true
196
+ };
197
+
198
+ export default BecomeSeller;
@@ -0,0 +1,47 @@
1
+ .root {
2
+ composes: gap-xs from global;
3
+ composes: grid from global;
4
+ composes: justify-items-stretch from global;
5
+ composes: px-sm from global;
6
+ composes: py-xs from global;
7
+ }
8
+
9
+ .message {
10
+ composes: bg-subtle from global;
11
+ composes: leading-tight from global;
12
+ composes: p-xs from global;
13
+ composes: rounded from global;
14
+ composes: text-sm from global;
15
+ }
16
+
17
+ /* TODO @TW: cannot compose */
18
+ .message:empty {
19
+ display: none;
20
+ }
21
+
22
+ .actions {
23
+ composes: gap-xs from global;
24
+ composes: grid from global;
25
+ composes: grid-flow-row from global;
26
+ composes: justify-center from global;
27
+ composes: mt-xs from global;
28
+ composes: text-center from global;
29
+
30
+ composes: lg_grid-flow-col from global;
31
+ }
32
+
33
+ .cancelButton {
34
+ composes: root_lowPriority from '@magento/venia-ui/lib/components/Button/button.module.css';
35
+ }
36
+
37
+ .submitButton {
38
+ composes: root_highPriority from '@magento/venia-ui/lib/components/Button/button.module.css';
39
+
40
+ composes: col-start-auto from global;
41
+
42
+ composes: lg_col-start-2 from global;
43
+ }
44
+
45
+ .subscribe {
46
+ composes: -ml-1.5 from global;
47
+ }
@@ -0,0 +1 @@
1
+ export {default} from './sellerVerificationPage';
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { shape, string } from 'prop-types';
3
+ import { FormattedMessage, useIntl } from 'react-intl';
4
+
5
+ import { useBecomeSellerPage } from '@riosst100/pwa-marketplace/src/talons/BecomeSellerPage/useBecomeSellerPage';
6
+ import { useStyle } from '@magento/venia-ui/lib/classify';
7
+ import BecomeSeller from '@riosst100/pwa-marketplace/src/components/BecomeSeller';
8
+ import { StoreTitle } from '@magento/venia-ui/lib/components/Head';
9
+ import defaultClasses from './sellerVerificationPage.module.css';
10
+
11
+ const BecomeSellerPage = props => {
12
+ const classes = useStyle(defaultClasses, props.classes);
13
+ const { sellerVerificationProps } = useBecomeSellerPage(props);
14
+ const { formatMessage } = useIntl();
15
+
16
+ return (
17
+ <div className={classes.root}>
18
+ <StoreTitle>
19
+ {formatMessage({
20
+ id: 'sellerVerificationPage.title',
21
+ defaultMessage: 'Become a Seller'
22
+ })}
23
+ </StoreTitle>
24
+ <div className={classes.contentContainer}>
25
+ <BecomeSeller {...sellerVerificationProps} />
26
+ </div>
27
+ </div>
28
+ );
29
+ }
30
+
31
+ export default BecomeSellerPage;
32
+
33
+ BecomeSellerPage.defaultProps = {
34
+ signedInRedirectUrl: '/seller-verification',
35
+ signInPageUrl: '/become-seller'
36
+ };
37
+
38
+ BecomeSellerPage.propTypes = {
39
+ classes: shape({
40
+ root: string
41
+ }),
42
+ signedInRedirectUrl: string
43
+ };
@@ -0,0 +1,21 @@
1
+ .root {
2
+ composes: gap-y-md from global;
3
+ composes: grid from global;
4
+ composes: justify-center from global;
5
+ composes: px-0 from global;
6
+ composes: py-md from global;
7
+ composes: text-center from global;
8
+ grid-template-columns: minmax(auto, 512px);
9
+ }
10
+
11
+ .header {
12
+ composes: font-serif from global;
13
+ }
14
+
15
+ .contentContainer {
16
+ composes: lg_border-2 from global;
17
+ composes: lg_border-solid from global;
18
+ composes: lg_border-subtle from global;
19
+ composes: lg_pb-md from global;
20
+ composes: lg_rounded-md from global;
21
+ }
@@ -68,14 +68,14 @@ const WebsiteSwitcher = props => {
68
68
  );
69
69
  });
70
70
 
71
- let triggerLabel = `${currentWebsiteName}`;
71
+ let triggerLabel = currentWebsiteName ? `${currentWebsiteName}` : '';
72
72
 
73
73
  return (
74
74
  <div className={classes.root} data-cy="WebsiteSwitcher-root">
75
75
  <button
76
76
  data-cy="WebsiteSwitcher-triggerButton"
77
77
  className={classes.trigger}
78
- aria-label={currentWebsiteName}
78
+ aria-label={currentWebsiteName || ''}
79
79
  onClick={handleTriggerClick}
80
80
  ref={storeMenuTriggerRef}
81
81
  data-cy="WebsiteSwitcher-trigger"
package/src/intercept.js CHANGED
@@ -36,11 +36,21 @@ module.exports = targets => {
36
36
  // Define the routes using the results of the asynchronous operation
37
37
  const routes = [
38
38
  {
39
+ exact: true,
39
40
  name: "BecomeSellerRoute",
40
41
  pattern: "/become-seller",
41
42
  path: require.resolve("./components/BecomeSellerPage/index.js"),
43
+ authed: true,
44
+ redirectTo: "/sign-in"
45
+ },
46
+ {
47
+ exact: true,
48
+ name: "SellerAccountRoute",
49
+ pattern: "/seller-account",
50
+ path: require.resolve("./components/SellerAccountPage/index.js"),
51
+ authed: true,
52
+ redirectTo: "/become-seller"
42
53
  },
43
- // Add other routes as needed
44
54
  ];
45
55
 
46
56
  // Apply DefinePlugin using the results of the asynchronous operation
@@ -0,0 +1,96 @@
1
+ import BrowserPersistence from '@magento/peregrine/lib/util/simplePersistence';
2
+ import { removeCart } from '@magento/peregrine/lib/store/actions/cart';
3
+ import { clearCheckoutDataFromStorage } from '@magento/peregrine/lib/store/actions/checkout';
4
+
5
+ import actions from '@magento/peregrine/lib/store/actions/user/actions';
6
+
7
+ const storage = new BrowserPersistence();
8
+
9
+ export const signOut = (payload = {}) =>
10
+ async function thunk(dispatch, getState, { apolloClient }) {
11
+ const { revokeToken } = payload;
12
+
13
+ if (revokeToken) {
14
+ // Send mutation to revoke token.
15
+ try {
16
+ await revokeToken();
17
+ } catch (error) {
18
+ console.error('Error Revoking Token', error);
19
+ }
20
+ }
21
+
22
+ // Remove token from local storage and Redux.
23
+ await dispatch(clearToken());
24
+ await dispatch(actions.reset());
25
+ await clearCheckoutDataFromStorage();
26
+ await apolloClient.clearCacheData(apolloClient, 'cart');
27
+ await apolloClient.clearCacheData(apolloClient, 'customer');
28
+
29
+ // Now that we're signed out, forget the old (customer) cart.
30
+ // We don't need to create a new cart here because we're going to refresh
31
+ // the page immediately after.
32
+ await dispatch(removeCart());
33
+ };
34
+
35
+ export const getUserDetails = ({ fetchUserDetails }) =>
36
+ async function thunk(...args) {
37
+ const [dispatch, getState] = args;
38
+ const { user } = getState();
39
+
40
+ if (user.isSignedIn) {
41
+ dispatch(actions.getDetails.request());
42
+
43
+ try {
44
+ const { data } = await fetchUserDetails();
45
+
46
+ if (data.customer) {
47
+ const isSeller = data.customer.is_seller;
48
+ if (isSeller) {
49
+ storage.setItem('is_seller', true);
50
+ }
51
+ }
52
+
53
+ dispatch(actions.getDetails.receive(data.customer));
54
+ } catch (error) {
55
+ dispatch(actions.getDetails.receive(error));
56
+ }
57
+ }
58
+ };
59
+
60
+ export const resetPassword = ({ email }) =>
61
+ async function thunk(...args) {
62
+ const [dispatch] = args;
63
+
64
+ dispatch(actions.resetPassword.request());
65
+
66
+ // TODO: actually make the call to the API.
67
+ // For now, just return a resolved promise.
68
+ await Promise.resolve(email);
69
+
70
+ dispatch(actions.resetPassword.receive());
71
+ };
72
+
73
+ export const setToken = token =>
74
+ async function thunk(...args) {
75
+ const [dispatch] = args;
76
+
77
+ // Store token in local storage.
78
+ // TODO: Get correct token expire time from API
79
+ storage.setItem('signin_token', token, 3600);
80
+
81
+ // Persist in store
82
+ dispatch(actions.setToken(token));
83
+ };
84
+
85
+ export const clearToken = () =>
86
+ async function thunk(...args) {
87
+ const [dispatch] = args;
88
+
89
+ // Clear token from local storage
90
+ storage.removeItem('signin_token');
91
+
92
+ storage.removeItem('is_seller');
93
+
94
+ // Remove from store
95
+ dispatch(actions.clearToken());
96
+ };
@@ -0,0 +1,65 @@
1
+ import { useCallback } from 'react';
2
+
3
+ /**
4
+ * @param {Object} props
5
+ * @param {Function} props.onSignOut - A function to call when sign out occurs.
6
+ *
7
+ * @returns {Object} result
8
+ * @returns {Function} result.handleSignOut - The function to handle sign out actions.
9
+ */
10
+ export const useAccountMenuItems = props => {
11
+ const { onSignOut } = props;
12
+
13
+ const handleSignOut = useCallback(() => {
14
+ onSignOut();
15
+ }, [onSignOut]);
16
+
17
+ const MENU_ITEMS = [
18
+ {
19
+ name: 'Seller Account Information',
20
+ id: 'accountMenu.sellerAccountInfoLink',
21
+ url: '/seller-account'
22
+ },
23
+ {
24
+ name: 'Order History',
25
+ id: 'accountMenu.orderHistoryLink',
26
+ url: '/order-history'
27
+ },
28
+ // Hide links until features are completed
29
+ // {
30
+ // name: 'Store Credit & Gift Cards',
31
+ // id: 'accountMenu.storeCreditLink',
32
+ // url: ''
33
+ // },
34
+ {
35
+ name: 'Favorites Lists',
36
+ id: 'accountMenu.favoritesListsLink',
37
+ url: '/wishlist'
38
+ },
39
+ {
40
+ name: 'Address Book',
41
+ id: 'accountMenu.addressBookLink',
42
+ url: '/address-book'
43
+ },
44
+ {
45
+ name: 'Saved Payments',
46
+ id: 'accountMenu.savedPaymentsLink',
47
+ url: '/saved-payments'
48
+ },
49
+ {
50
+ name: 'Communications',
51
+ id: 'accountMenu.communicationsLinak',
52
+ url: '/communications'
53
+ },
54
+ {
55
+ name: 'Account Information',
56
+ id: 'accountMenu.accountInfoLink',
57
+ url: '/account-information'
58
+ }
59
+ ];
60
+
61
+ return {
62
+ handleSignOut,
63
+ menuItems: MENU_ITEMS
64
+ };
65
+ };
@@ -0,0 +1,56 @@
1
+ import { gql } from '@apollo/client';
2
+ import { CheckoutPageFragment } from '@magento/peregrine/lib/talons/CheckoutPage/checkoutPageFragments.gql';
3
+
4
+ export const GET_CUSTOMER = gql`
5
+ query GetCustomerAfterSignIn {
6
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
7
+ customer {
8
+ email
9
+ firstname
10
+ lastname
11
+ is_subscribed
12
+ is_seller
13
+ }
14
+ }
15
+ `;
16
+
17
+ export const SIGN_IN = gql`
18
+ mutation SignIn($email: String!, $password: String!) {
19
+ generateCustomerToken(email: $email, password: $password) {
20
+ token
21
+ }
22
+ }
23
+ `;
24
+
25
+ export const CREATE_CART = gql`
26
+ mutation CreateCartAfterSignIn {
27
+ cartId: createEmptyCart
28
+ }
29
+ `;
30
+
31
+ export const MERGE_CARTS = gql`
32
+ mutation MergeCartsAfterSignIn(
33
+ $sourceCartId: String!
34
+ $destinationCartId: String!
35
+ ) {
36
+ mergeCarts(
37
+ source_cart_id: $sourceCartId
38
+ destination_cart_id: $destinationCartId
39
+ ) {
40
+ id
41
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
42
+ items {
43
+ uid
44
+ }
45
+ ...CheckoutPageFragment
46
+ }
47
+ }
48
+ ${CheckoutPageFragment}
49
+ `;
50
+
51
+ export default {
52
+ createCartMutation: CREATE_CART,
53
+ getCustomerQuery: GET_CUSTOMER,
54
+ mergeCartsMutation: MERGE_CARTS,
55
+ signInMutation: SIGN_IN
56
+ };