@riosst100/pwa-marketplace 1.0.0 → 1.0.2

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 (30) hide show
  1. package/package.json +1 -1
  2. package/src/Utilities/graphQL.js +1 -1
  3. package/src/componentOverrideMapping.js +9 -9
  4. package/src/components/BecomeSeller/becomeSeller.js +220 -0
  5. package/src/components/BecomeSeller/becomeSeller.module.css +47 -0
  6. package/src/components/BecomeSeller/index.js +1 -0
  7. package/src/components/BecomeSellerLink/becomeSellerLink.js +28 -0
  8. package/src/components/BecomeSellerLink/becomeSellerLink.module.css +13 -0
  9. package/src/components/BecomeSellerPage/becomeSellerPage.js +50 -0
  10. package/src/components/BecomeSellerPage/becomeSellerPage.module.css +21 -0
  11. package/src/components/BecomeSellerPage/index.js +1 -0
  12. package/src/components/Header/becomeSellerLink.js +28 -0
  13. package/src/components/Header/becomeSellerLink.module.css +13 -0
  14. package/src/components/Header/websiteSwitcher.js +1 -1
  15. package/src/components/WebsiteSwitcher/websiteSwitcher.js +109 -0
  16. package/src/components/WebsiteSwitcher/websiteSwitcher.module.css +111 -0
  17. package/src/components/WebsiteSwitcher/websiteSwitcher.shimmer.js +6 -0
  18. package/src/components/WebsiteSwitcher/websiteSwitcherItem.js +47 -0
  19. package/src/components/WebsiteSwitcher/websiteSwitcherItem.module.css +20 -0
  20. package/src/intercept.js +32 -19
  21. package/src/overwrites/venia-ui/lib/components/Adapter/adapter.js +1 -1
  22. package/src/overwrites/venia-ui/lib/components/Header/header.js +3 -1
  23. package/src/overwrites/venia-ui/lib/components/Header/storeSwitcher.js +2 -2
  24. package/src/talons/BecomeSeller/becomeSeller.gql.js +136 -0
  25. package/src/talons/BecomeSeller/useBecomeSeller.js +288 -0
  26. package/src/talons/BecomeSellerLink/useBecomeSellerLink.js +13 -0
  27. package/src/talons/BecomeSellerPage/useBecomeSellerPage.js +68 -0
  28. package/src/talons/Header/useBecomeSellerLink.js +13 -0
  29. package/src/talons/WebsiteSwitcher/useWebsiteSwitcher.js +218 -0
  30. package/src/talons/WebsiteSwitcher/websiteSwitcher.gql.js +45 -0
@@ -0,0 +1,111 @@
1
+ .root {
2
+ composes: grid from global;
3
+ composes: items-center from global;
4
+ composes: justify-items-start from global;
5
+ composes: max-w-site from global;
6
+ composes: mx-auto from global;
7
+ composes: my-0 from global;
8
+ composes: px-xs from global;
9
+ composes: py-2xs from global;
10
+ composes: relative from global;
11
+
12
+ composes: sm_justify-items-end from global;
13
+ }
14
+
15
+ .trigger {
16
+ composes: max-w-[15rem] from global;
17
+ composes: overflow-ellipsis from global;
18
+ composes: overflow-hidden from global;
19
+ composes: whitespace-nowrap from global;
20
+
21
+ composes: sm_max-w-full from global;
22
+ }
23
+
24
+ .menu {
25
+ composes: absolute from global;
26
+ composes: bg-white from global;
27
+ composes: border from global;
28
+ composes: border-solid from global;
29
+ composes: border-subtle from global;
30
+ composes: bottom-md from global;
31
+ composes: left-xs from global;
32
+ composes: max-w-[90vw] from global;
33
+ composes: opacity-0 from global;
34
+ composes: pb-2xs from global;
35
+ composes: pt-2xs from global;
36
+ composes: right-auto from global;
37
+ composes: rounded from global;
38
+ composes: shadow-menu from global;
39
+ composes: top-auto from global;
40
+ composes: w-max from global;
41
+ composes: z-menu from global;
42
+ transform: translate3d(0, -8px, 0);
43
+ transition-duration: 192ms;
44
+ transition-timing-function: var(--venia-global-anim-out);
45
+ transition-property: opacity, transform, visibility;
46
+
47
+ /* TODO @TW: review (B6) */
48
+ /* composes: invisible from global; */
49
+ visibility: hidden;
50
+
51
+ composes: sm_bottom-auto from global;
52
+ composes: sm_left-auto from global;
53
+ composes: sm_right-xs from global;
54
+ composes: sm_top-md from global;
55
+ }
56
+
57
+ .menu_open {
58
+ composes: menu;
59
+
60
+ composes: opacity-100 from global;
61
+ transform: translate3d(0, 4px, 0);
62
+ transition-duration: 224ms;
63
+ transition-timing-function: var(--venia-global-anim-in);
64
+
65
+ /* TODO @TW: review (B6) */
66
+ /* composes: visible from global; */
67
+ visibility: visible;
68
+ }
69
+
70
+ .menuItem {
71
+ composes: hover_bg-subtle from global;
72
+ }
73
+
74
+ .groups {
75
+ composes: max-h-[24rem] from global;
76
+ composes: overflow-auto from global;
77
+ }
78
+
79
+ .groupList {
80
+ composes: border-b from global;
81
+ composes: border-solid from global;
82
+ composes: border-subtle from global;
83
+ composes: pb-2xs from global;
84
+ composes: pt-2xs from global;
85
+
86
+ composes: last_border-none from global;
87
+ }
88
+
89
+ /*
90
+ * Mobile-specific styles.
91
+ */
92
+
93
+ @media (max-width: 639px) {
94
+ .root:only-child {
95
+ grid-column: 2;
96
+ }
97
+
98
+ /* TODO @TW: cannot compose */
99
+ .root:last-child .menu {
100
+ right: 1rem;
101
+ left: auto;
102
+ }
103
+
104
+ .menu {
105
+ transform: translate3d(0, 8px, 0);
106
+ }
107
+
108
+ .menu_open {
109
+ transform: translate3d(0, -4px, 0);
110
+ }
111
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import Shimmer from '@magento/venia-ui/lib/components/Shimmer';
3
+
4
+ export default () => {
5
+ return <Shimmer width={6} height={2.25} />;
6
+ };
@@ -0,0 +1,47 @@
1
+ import React, { useCallback } from 'react';
2
+ import { Check } from 'react-feather';
3
+ import { bool, func, shape, string } from 'prop-types';
4
+
5
+ import { useStyle } from '@magento/venia-ui/lib/classify';
6
+ import Icon from '@magento/venia-ui/lib/components/Icon/icon';
7
+ import defaultClasses from './websiteSwitcherItem.module.css';
8
+
9
+ const WebsiteSwitcherItem = props => {
10
+ const { active, onClick, option, option2, children } = props;
11
+ const classes = useStyle(defaultClasses, props.classes);
12
+
13
+ const handleClick = useCallback(() => {
14
+ onClick(option, option2);
15
+ }, [option, option2, onClick]);
16
+
17
+ const activeIcon = active ? (
18
+ <Icon data-cy="WebsiteSwitcherItem-activeIcon" size={20} src={Check} />
19
+ ) : null;
20
+
21
+ return (
22
+ <button
23
+ data-cy="WebsiteSwitcherItem-button"
24
+ className={classes.root}
25
+ disabled={active}
26
+ onClick={handleClick}
27
+ >
28
+ <span className={classes.content}>
29
+ <span className={classes.text}>{children}</span>
30
+ {activeIcon}
31
+ </span>
32
+ </button>
33
+ );
34
+ };
35
+
36
+ WebsiteSwitcherItem.propTypes = {
37
+ active: bool,
38
+ classes: shape({
39
+ content: string,
40
+ root: string,
41
+ text: string
42
+ }),
43
+ onClick: func,
44
+ option: string
45
+ };
46
+
47
+ export default WebsiteSwitcherItem;
@@ -0,0 +1,20 @@
1
+ .root {
2
+ composes: flex from global;
3
+ composes: items-center from global;
4
+ composes: w-full from global;
5
+ }
6
+
7
+ .content {
8
+ composes: gap-3 from global;
9
+ composes: grid from global;
10
+ composes: grid-cols-[1fr] from global;
11
+ composes: grid-flow-col from global;
12
+ composes: items-center from global;
13
+ composes: px-xs from global;
14
+ composes: py-2xs from global;
15
+ composes: w-full from global;
16
+ }
17
+
18
+ .text {
19
+ composes: text-left from global;
20
+ }
package/src/intercept.js CHANGED
@@ -3,30 +3,24 @@ const moduleOverridePlugin = require('./moduleOverrideWebpackPlugin');
3
3
  const { DefinePlugin } = require('webpack');
4
4
  const { getAvailableWebsitesConfigData } = require('./Utilities/graphQL');
5
5
 
6
- /**
7
- * Custom intercept file for the extension
8
- * By default you can only use target of @magento/pwa-buildpack.
9
- *
10
- * If do want extend @magento/peregrine or @magento/venia-ui
11
- * you should add them to peerDependencies to your package.json
12
- *
13
- * If you want to add overwrites for @magento/venia-ui components you can use
14
- * moduleOverrideWebpackPlugin and componentOverrideMapping
15
- */
16
- module.exports = async targets => {
6
+ module.exports = targets => {
7
+ // Perform the asynchronous operation outside the tap
8
+ let availableWebsites;
9
+
10
+ // Use an IIFE (Immediately Invoked Function Expression) to enable async/await
11
+ (async () => {
12
+ availableWebsites = await getAvailableWebsitesConfigData();
13
+ })();
14
+
17
15
  targets.of('@magento/pwa-buildpack').specialFeatures.tap(flags => {
18
- /**
19
- * Wee need to activated esModules and cssModules to allow build pack to load our extension
20
- * {@link https://magento.github.io/pwa-studio/pwa-buildpack/reference/configure-webpack/#special-flags}.
21
- */
22
- flags[targets.name] = { esModules: true, cssModules: true, graphqlQueries: true };
16
+ flags[targets.name] = { esModules: true, cssModules: true, graphqlQueries: true };
23
17
  });
24
18
 
25
19
  targets.of('@magento/pwa-buildpack').webpackCompiler.tap(compiler => {
26
- new moduleOverridePlugin(componentOverrideMapping).apply(compiler);
20
+ new moduleOverridePlugin(componentOverrideMapping).apply(compiler);
27
21
  });
28
22
 
29
- targets.of('@magento/pwa-buildpack').envVarDefinitions.tap((defs) => {
23
+ targets.of('@magento/pwa-buildpack').envVarDefinitions.tap(defs => {
30
24
  defs.sections.push({
31
25
  name: "Default Website Code",
32
26
  variables: [
@@ -39,12 +33,31 @@ module.exports = async targets => {
39
33
  });
40
34
  });
41
35
 
42
- const availableWebsites = await getAvailableWebsitesConfigData();
36
+ // Define the routes using the results of the asynchronous operation
37
+ const routes = [
38
+ {
39
+ name: "BecomeSellerRoute",
40
+ pattern: "/become-seller",
41
+ path: require.resolve("./components/BecomeSellerPage/index.js"),
42
+ },
43
+ // Add other routes as needed
44
+ ];
43
45
 
46
+ // Apply DefinePlugin using the results of the asynchronous operation
44
47
  targets.of('@magento/pwa-buildpack').webpackCompiler.tap(compiler => {
45
48
  new DefinePlugin({
46
49
  AVAILABLE_WEBSITES: JSON.stringify(availableWebsites.availableStoresByUserIp),
47
50
  WEBSITE_CODE: process.env.WEBSITE_CODE
48
51
  }).apply(compiler);
49
52
  });
53
+
54
+ targets.of('@magento/pwa-buildpack').specialFeatures.tap(flags => {
55
+ flags[targets.name] = { esModules: true, cssModules: true, graphqlQueries: true };
56
+ });
57
+
58
+ // Handle the routes directly within the routes tap
59
+ targets.of("@magento/venia-ui").routes.tap(routesArray => {
60
+ routesArray.push(...routes);
61
+ return routesArray;
62
+ });
50
63
  };
@@ -5,7 +5,7 @@ import { BrowserRouter } from 'react-router-dom';
5
5
  import { useAdapter } from '@magento/peregrine/lib/talons/Adapter/useAdapter';
6
6
  import App, { AppContextProvider } from '@magento/venia-ui/lib/components/App';
7
7
  import StoreCodeRoute from '@magento/venia-ui/lib/components/StoreCodeRoute';
8
- import { useWebsiteByIp } from '@riosst100/pwa-multi-website/src/talons/WebsiteByIp/useWebsiteByIp';
8
+ import { useWebsiteByIp } from '@riosst100/pwa-marketplace/src/talons/WebsiteByIp/useWebsiteByIp';
9
9
  import { BrowserPersistence } from '@magento/peregrine/lib/util';
10
10
 
11
11
  const storage = new BrowserPersistence();
@@ -14,8 +14,9 @@ import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
14
14
  import { useStyle } from '@magento/venia-ui/lib/classify';
15
15
  import defaultClasses from '@magento/venia-ui/lib/components/Header/header.module.css';
16
16
  import StoreSwitcher from '@magento/venia-ui/lib/components/Header/storeSwitcher';
17
- import WebsiteSwitcher from '@riosst100/pwa-multi-website/src/components/Header/websiteSwitcher';
17
+ import WebsiteSwitcher from '@riosst100/pwa-marketplace/src/components/WebsiteSwitcher/websiteSwitcher';
18
18
  import CurrencySwitcher from '@magento/venia-ui/lib/components/Header/currencySwitcher';
19
+ import BecomeSellerLink from '@riosst100/pwa-marketplace/src/components/BecomeSellerLink/becomeSellerLink';
19
20
  import MegaMenu from '@magento/venia-ui/lib/components/MegaMenu';
20
21
  import PageLoadingIndicator from '@magento/venia-ui/lib/components/PageLoadingIndicator';
21
22
  import { useIntl } from 'react-intl';
@@ -60,6 +61,7 @@ const Header = props => {
60
61
  <Fragment>
61
62
  <div className={classes.switchersContainer}>
62
63
  <div className={classes.switchers} data-cy="Header-switchers">
64
+ <BecomeSellerLink />
63
65
  <WebsiteSwitcher />
64
66
  <StoreSwitcher />
65
67
  <CurrencySwitcher />
@@ -84,13 +84,13 @@ 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"
91
91
  aria-expanded={storeMenuIsOpen}
92
92
  >
93
- {triggerLabel}
93
+ {triggerLabel || ''}
94
94
  </button>
95
95
  <div
96
96
  ref={storeMenuRef}
@@ -0,0 +1,136 @@
1
+ import { gql } from '@apollo/client';
2
+ import { CheckoutPageFragment } from '@magento/peregrine/lib/talons/CheckoutPage/checkoutPageFragments.gql';
3
+
4
+ export const CREATE_ACCOUNT = gql`
5
+ mutation BecomeSeller(
6
+ $email: String!
7
+ $firstname: String!
8
+ $lastname: String!
9
+ $password: String!
10
+ $is_subscribed: Boolean!
11
+ ) {
12
+ createCustomer(
13
+ input: {
14
+ email: $email
15
+ firstname: $firstname
16
+ lastname: $lastname
17
+ password: $password
18
+ is_subscribed: $is_subscribed
19
+ }
20
+ ) {
21
+ # The createCustomer mutation returns a non-nullable CustomerOutput type
22
+ # which requires that at least one of the sub fields be returned.
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
124
+ }
125
+ }
126
+ ${CheckoutPageFragment}
127
+ `;
128
+
129
+ export default {
130
+ becomeSellerMutation: CREATE_ACCOUNT,
131
+ createCartMutation: CREATE_CART,
132
+ getCartDetailsQuery: GET_CART_DETAILS,
133
+ getCustomerQuery: GET_CUSTOMER,
134
+ mergeCartsMutation: MERGE_CARTS,
135
+ signInMutation: SIGN_IN
136
+ };