@riosst100/pwa-marketplace 2.1.0 → 2.1.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.
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
- {
2
- "name": "@riosst100/pwa-marketplace",
3
- "author": "riosst100@gmail.com",
4
- "version": "2.1.0",
5
- "main": "src/index.js",
6
- "pwa-studio": {
7
- "targets": {
8
- "intercept": "src/intercept.js"
9
- }
10
- },
11
- "dependencies": {
12
- "axios": "^1.6.5",
13
- "iconsax-react": "^0.0.8",
14
- "react-phone-number-input": "^3.3.9"
15
- },
16
- "license": "MIT",
17
- "private": false
18
- }
1
+ {
2
+ "name": "@riosst100/pwa-marketplace",
3
+ "author": "riosst100@gmail.com",
4
+ "version": "2.1.2",
5
+ "main": "src/index.js",
6
+ "pwa-studio": {
7
+ "targets": {
8
+ "intercept": "src/intercept.js"
9
+ }
10
+ },
11
+ "dependencies": {
12
+ "axios": "^1.6.5",
13
+ "formik": "^2.4.6",
14
+ "iconsax-react": "^0.0.8",
15
+ "react-countdown": "^2.3.5",
16
+ "react-datepicker": "4.10.0",
17
+ "react-dropzone": "^14.2.3",
18
+ "react-phone-number-input": "^3.3.9",
19
+ "react-slick": "^0.30.2",
20
+ "yup": "^1.4.0"
21
+ },
22
+ "license": "MIT",
23
+ "private": false
24
+ }
@@ -0,0 +1,54 @@
1
+ import React, { useRef } from 'react';
2
+ import { element, func, shape, string } from 'prop-types';
3
+ import { Heart } from 'react-feather';
4
+ import { useAddToFavoriteListButton } from '@riosst100/pwa-marketplace/src/talons/FavoriteSeller/AddToListButton/useAddToFavoriteListButton';
5
+ import { useButton } from 'react-aria';
6
+
7
+ import { useStyle } from '@magento/venia-ui/lib/classify';
8
+ import Icon from '@magento/venia-ui/lib/components/Icon';
9
+ import defaultClasses from './addToListButton.module.css';
10
+ import { useCommonToasts } from '@magento/venia-ui/lib/components/Wishlist/AddToListButton/useCommonToasts';
11
+
12
+ const HeartIcon = <Heart color='#f76b1c' size={14} variant="Outline" className='stroke-[#f76b1c]' />;
13
+
14
+ const AddToFavoriteListButton = props => {
15
+ const talonProps = useAddToFavoriteListButton(props);
16
+ const buttonRef = useRef();
17
+
18
+ const {
19
+ buttonProps,
20
+ buttonText,
21
+ errorToastProps,
22
+ isSelected,
23
+ loginToastProps,
24
+ successToastProps
25
+ } = talonProps;
26
+
27
+ useCommonToasts({ errorToastProps, loginToastProps, successToastProps });
28
+ const { buttonProps: ariaButtonProps } = useButton(buttonProps, buttonRef);
29
+
30
+ const classes = useStyle(defaultClasses, props.classes);
31
+ const buttonClass = isSelected ? classes.root_selected : classes.root;
32
+
33
+ return (
34
+ <button ref={buttonRef} className={buttonClass} {...ariaButtonProps}>
35
+ {props.icon}
36
+ </button>
37
+ );
38
+ };
39
+
40
+ export default AddToFavoriteListButton;
41
+
42
+ AddToFavoriteListButton.defaultProps = {
43
+ icon: HeartIcon
44
+ };
45
+
46
+ AddToFavoriteListButton.propTypes = {
47
+ afterAdd: func,
48
+ beforeAdd: func,
49
+ classes: shape({
50
+ root: string,
51
+ root_selected: string
52
+ }),
53
+ icon: element
54
+ };
@@ -0,0 +1,17 @@
1
+ .root {
2
+ composes: gap-x-2xs from global;
3
+ composes: inline-flex from global;
4
+ composes: items-center from global;
5
+ min-height: 3rem;
6
+ composes: min-w-[3rem] from global;
7
+ }
8
+
9
+ .root_selected {
10
+ composes: root;
11
+
12
+ --selectedColor: rgb(var(--venia-global-color-red-400));
13
+ --fill: var(--selectedColor);
14
+ --stroke: var(--selectedColor);
15
+
16
+ composes: no-underline from global;
17
+ }
@@ -0,0 +1 @@
1
+ export { default } from './addToListButton';
@@ -0,0 +1,33 @@
1
+ import React, { useEffect } from 'react';
2
+ import { AlertCircle, Check, Info } from 'react-feather';
3
+ import { useToasts } from '@magento/peregrine';
4
+
5
+ import Icon from '@magento/venia-ui/lib/components/Icon';
6
+
7
+ const CheckIcon = <Icon size={20} src={Check} />;
8
+ const ErrorIcon = <Icon size={20} src={AlertCircle} />;
9
+ const InfoIcon = <Icon size={20} src={Info} />;
10
+
11
+ export const useCommonToasts = props => {
12
+ const { errorToastProps, loginToastProps, successToastProps } = props;
13
+
14
+ const [, { addToast }] = useToasts();
15
+
16
+ useEffect(() => {
17
+ if (loginToastProps) {
18
+ addToast({ ...loginToastProps, icon: InfoIcon });
19
+ }
20
+ }, [addToast, loginToastProps]);
21
+
22
+ useEffect(() => {
23
+ if (successToastProps) {
24
+ addToast({ ...successToastProps, icon: CheckIcon });
25
+ }
26
+ }, [addToast, successToastProps]);
27
+
28
+ useEffect(() => {
29
+ if (errorToastProps) {
30
+ addToast({ ...errorToastProps, icon: ErrorIcon });
31
+ }
32
+ }, [addToast, errorToastProps]);
33
+ };
@@ -1,4 +1,4 @@
1
- import React, { Fragment, useState } from 'react';
1
+ import React, { Fragment, Suspense, useState } from 'react';
2
2
  import { FormattedMessage } from 'react-intl';
3
3
  import { useSeller } from '@riosst100/pwa-marketplace/src/talons/Seller/useSeller';
4
4
  import ErrorView from '@magento/venia-ui/lib/components/ErrorView';
@@ -22,13 +22,14 @@ import Image from '@magento/venia-ui/lib/components/Image';
22
22
  import LiveChat from '@riosst100/pwa-marketplace/src/components/LiveChat';
23
23
  import Button from '@magento/venia-ui/lib/components/Button';
24
24
  import cn from 'classnames';
25
+ const FavoriteSellerButton = React.lazy(() => import('@riosst100/pwa-marketplace/src/components/FavoriteSeller/AddToListButton'));
25
26
 
26
27
  const SellerDetail = props => {
27
28
  const talonProps = useSeller({
28
29
  mapSeller
29
30
  });
30
31
 
31
- const { error, loading, seller } = talonProps;
32
+ const { error, loading, seller, favoriteSellerButtonProps } = talonProps;
32
33
 
33
34
  if (loading && !seller)
34
35
  return '';
@@ -71,6 +72,10 @@ const SellerDetail = props => {
71
72
  setOpenChat(!openChat);
72
73
  }
73
74
 
75
+ const addToFavourite = () => {
76
+
77
+ }
78
+
74
79
  return (
75
80
  <div className=' py-8'>
76
81
  <Slider seller={seller} rootClassname='mb-[30px]' />
@@ -113,36 +118,31 @@ const SellerDetail = props => {
113
118
  </div>
114
119
  </div>
115
120
  </button>
116
- {/* <button class="flex items-center justify-center gap-[5px] xs_p-[11px] lg_px-[20px] lg_py-[8px] relative bg-[#280135] rounded-[30px] border border-solid border-[#280135]">
117
- <div class="flex items-center justify-center gap-[10px] relative">
118
- <Message color='#FFFFFF' size={14} variant="Outline" className='stroke-[#FFFFFF]' />
119
- <div class="relative xs_hidden lg_flex w-fit font-medium text-[#fff] text-base tracking-[0] leading-[20px] whitespace-nowrap">
120
- Chat With Seller
121
- </div>
122
- </div>
123
- </button> */}
124
121
  <Button
125
122
  priority='high'
126
123
  classes={{
127
124
  content: "flex justify-center gap-x-2.5 items-center text-[14px] font-medium capitalize"
128
125
  }}
129
- className={cn(
130
- "bg-darkblue-900 px-6 py-2 rounded-full text-white border",
131
- "border-darkblue-900 hover_bg-blue-900 hover_border-blue-900 focus-visible_outline-none"
132
- )}
126
+ className='flex items-center justify-center gap-[5px] xs_p-[11px] lg_px-[20px] lg_py-[8px] relative bg-[#280135] rounded-[30px] border border-solid border-[#280135]'
133
127
  onClick={toggleChat}
134
128
  >
135
129
  <Message color='#FFFFFF' size={14} variant="Outline" className='stroke-[#FFFFFF]' />
136
- <span>
130
+ <div class="relative xs_hidden lg_flex w-fit font-medium text-[#fff] text-base tracking-[0] leading-[20px] whitespace-nowrap">
137
131
  <FormattedMessage
138
132
  id={'seller.chatWithSeller'}
139
133
  defaultMessage={'Chat With Seller'}
140
134
  />
141
- </span>
135
+ </div>
142
136
  </Button>
143
- <button class="flex items-center justify-center gap-[5px] p-[11px] relative bg-white rounded-[30px] overflow-hidden border border-solid border-[#f76b1c]">
144
- <Heart color='#f76b1c' size={14} variant="Outline" className='stroke-[#f76b1c]' />
145
- </button>
137
+ <Suspense fallback={null}>
138
+ <FavoriteSellerButton
139
+ classes={{
140
+ root: 'flex items-center justify-center gap-[5px] p-[11px] relative bg-white rounded-[30px] overflow-hidden border border-solid border-[#f76b1c]'
141
+ }}
142
+ {...favoriteSellerButtonProps}
143
+ buttonText={''}
144
+ />
145
+ </Suspense>
146
146
  <button class="flex items-center justify-center gap-[5px] p-[11px] relative bg-white rounded-[30px] overflow-hidden border border-solid border-[#f76b1c]">
147
147
  <Share color='#f76b1c' size={14} variant="Outline" className='stroke-[#f76b1c]' />
148
148
  </button>
package/src/intercept.js CHANGED
@@ -133,7 +133,7 @@ module.exports = targets => {
133
133
  exact: true,
134
134
  name: "FavoriteSeller",
135
135
  pattern: "/favorite-seller",
136
- path: require.resolve("./components/FavoriteSeller/index.js"),
136
+ path: require.resolve("./components/FavoriteSellerPage/index.js"),
137
137
  authed: true,
138
138
  },
139
139
  {
@@ -30,7 +30,7 @@ export const useAccountMenuItems = props => {
30
30
  // url: ''
31
31
  // },
32
32
  {
33
- name: 'Favorites Lists',
33
+ name: 'Wishlist',
34
34
  id: 'accountMenu.favoritesListsLink',
35
35
  url: '/wishlist'
36
36
  },
@@ -125,11 +125,6 @@ const Header = props => {
125
125
  <div className='flex w-full justify-end lg_hidden'>
126
126
  <SearchNormal size="25" color="#280135" variant="Outline" className='mr-4' />
127
127
  </div>
128
- <Suspense fallback={searchBarFallback}>
129
- <Route>
130
- <SearchBar isOpen={true} ref={searchRef} />
131
- </Route>
132
- </Suspense>
133
128
  </div>
134
129
  <div className={cn(classes.secondaryActions, 'lg_gap-x-5 pl-5 border-l-[1px] border-gray-100')}>
135
130
  {/* <SearchTrigger
@@ -691,12 +691,6 @@ const ProductFullDetail = props => {
691
691
  <div className='block lg_hidden'>
692
692
  <ProductDetailsCollapsible data={dataTabs} />
693
693
  </div>
694
- <Tabs
695
- data={dataTabs}
696
- tabContentWrapperClassName='!p-0'
697
- hasContent
698
- tabWrapperClassName='xl_gap-x-[60px] justify-center'
699
- />
700
694
  </section>
701
695
 
702
696
  <section className='pt-8 lg_pt-10'>
@@ -0,0 +1,30 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const ADD_TO_FAVORITE_SELLER_LIST = gql`
4
+ mutation AddSellerToFavoriteList(
5
+ $sellerId: ID!
6
+ ) {
7
+ addSellerToFavoritelist(
8
+ sellerId: $sellerId
9
+ ) {
10
+ favorite {
11
+ id
12
+ customer_id
13
+ creation_time
14
+ status
15
+ }
16
+ error
17
+ }
18
+ }
19
+ `;
20
+
21
+ export const GET_SELLER_IN_FAVORITE_LISTS = gql`
22
+ query GetProductsInWishlistsForGallery {
23
+ customerWishlistProducts @client
24
+ }
25
+ `;
26
+
27
+ export default {
28
+ addToFavoriteSellerMutation: ADD_TO_FAVORITE_SELLER_LIST,
29
+ getSellerInFavoriteListsQuery: GET_SELLER_IN_FAVORITE_LISTS
30
+ };
@@ -0,0 +1,154 @@
1
+ import { useCallback, useMemo, useState } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { useMutation, useQuery } from '@apollo/client';
4
+
5
+ import { useUserContext } from '@magento/peregrine/lib/context/user';
6
+ import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
7
+
8
+ import defaultOperations from './addToListButton.gql';
9
+
10
+ export const useAddToFavoriteListButton = props => {
11
+ const { afterAdd, beforeAdd, item } = props;
12
+
13
+ const operations = mergeOperations(defaultOperations, props.operations);
14
+
15
+ const [
16
+ addToFavoriteSeller,
17
+ {
18
+ data: addSellerData,
19
+ error: errorAddingProduct,
20
+ loading: isAddingToList
21
+ }
22
+ ] = useMutation(operations.addToFavoriteSellerMutation);
23
+
24
+ // const {
25
+ // client,
26
+ // data: { customerFavoriteSellers }
27
+ // } = useQuery(operations.getSellerInFavoriteListsQuery);
28
+
29
+ // const isSelected = useMemo(() => {
30
+ // return (
31
+ // customerFavoriteSellers.includes(item.seller_id) || isAddingToList
32
+ // );
33
+ // }, [customerFavoriteSellers, isAddingToList, item.seller_id]);
34
+ const isSelected = false;
35
+
36
+ const [showLoginToast, setShowLoginToast] = useState(0);
37
+
38
+ const { formatMessage } = useIntl();
39
+ const [{ isSignedIn }] = useUserContext();
40
+
41
+ const handleClick = useCallback(async () => {
42
+ console.log(item)
43
+ if (!isSignedIn) {
44
+ setShowLoginToast(current => ++current);
45
+ } else {
46
+ try {
47
+ if (beforeAdd) {
48
+ await beforeAdd();
49
+ }
50
+
51
+ await addToFavoriteSeller({
52
+ variables: { sellerId: item.seller_id }
53
+ });
54
+
55
+ // client.writeQuery({
56
+ // query: operations.getSellerInFavoriteListsQuery,
57
+ // data: {
58
+ // customerFavoriteSellers: [
59
+ // ...customerFavoriteSellers,
60
+ // item.seller_id
61
+ // ]
62
+ // }
63
+ // });
64
+
65
+ // if (afterAdd) {
66
+ // afterAdd();
67
+ // }
68
+ } catch (error) {
69
+ console.error(error);
70
+ }
71
+ }
72
+ }, [
73
+ addToFavoriteSeller,
74
+ afterAdd,
75
+ beforeAdd,
76
+ // client,
77
+ // customerFavoriteSellers,
78
+ isSignedIn,
79
+ item,
80
+ // operations.getSellerInFavoriteListsQuery
81
+ ]);
82
+
83
+ const loginToastProps = useMemo(() => {
84
+ if (showLoginToast) {
85
+ return {
86
+ type: 'info',
87
+ message: formatMessage({
88
+ id: 'favoriteSeller.galleryButton.loginMessage',
89
+ defaultMessage:
90
+ 'Please sign-in to your Account to save seller for later.'
91
+ }),
92
+ timeout: 5000
93
+ };
94
+ }
95
+
96
+ return null;
97
+ }, [formatMessage, showLoginToast]);
98
+
99
+ const successToastProps = useMemo(() => {
100
+ if (addSellerData) {
101
+ return {
102
+ type: 'success',
103
+ message: formatMessage({
104
+ id: 'favoriteSeller.galleryButton.successMessageGeneral',
105
+ defaultMessage:
106
+ 'Seller successfully added to your favorites list.'
107
+ }),
108
+ timeout: 5000
109
+ };
110
+ }
111
+
112
+ return null;
113
+ }, [addSellerData, formatMessage]);
114
+
115
+ const errorToastProps = useMemo(() => {
116
+ if (errorAddingProduct) {
117
+ return {
118
+ type: 'error',
119
+ message: formatMessage({
120
+ id: 'favoriteSeller.galleryButton.addError',
121
+ defaultMessage:
122
+ 'Something went wrong adding the product to your favorite seller list.'
123
+ }),
124
+ timeout: 5000
125
+ };
126
+ }
127
+
128
+ return null;
129
+ }, [errorAddingProduct, formatMessage]);
130
+
131
+ const buttonProps = useMemo(
132
+ () => ({
133
+ 'aria-label': formatMessage({
134
+ id: 'favoriteSellerButton.addText',
135
+ defaultMessage: 'Add to Favorites'
136
+ }),
137
+ isDisabled: false,
138
+ onPress: handleClick,
139
+ type: 'button'
140
+ }),
141
+ [formatMessage, handleClick]
142
+ );
143
+
144
+ return {
145
+ buttonProps,
146
+ buttonText: props.buttonText && props.buttonText(isSelected),
147
+ // customerFavoriteSellers,
148
+ errorToastProps,
149
+ handleClick,
150
+ isSelected,
151
+ loginToastProps,
152
+ successToastProps
153
+ };
154
+ };
@@ -2,6 +2,7 @@ import { useQuery } from '@apollo/client';
2
2
  import { useEffect, useMemo } from 'react';
3
3
  import { useLocation } from 'react-router-dom';
4
4
  import { useAppContext } from '@magento/peregrine/lib/context/app';
5
+ import { useIntl } from 'react-intl';
5
6
 
6
7
  import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
7
8
  import DEFAULT_OPERATIONS from './seller.gql';
@@ -9,6 +10,8 @@ import DEFAULT_OPERATIONS from './seller.gql';
9
10
  export const useSeller = props => {
10
11
  const { mapSeller } = props;
11
12
 
13
+ const { formatMessage } = useIntl();
14
+
12
15
  const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
13
16
  const { getStoreConfigData, getSellerDetailQuery } = operations;
14
17
  const { pathname } = useLocation();
@@ -63,9 +66,24 @@ export const useSeller = props => {
63
66
  setPageLoading(isBackgroundLoading);
64
67
  }, [isBackgroundLoading, setPageLoading]);
65
68
 
69
+ const favoriteSellerOptions = useMemo(() => {
70
+ const options = {
71
+ seller_id: seller.seller_id
72
+ };
73
+
74
+ return options;
75
+ }, [seller]);
76
+
77
+ const favoriteSellerButtonProps = {
78
+ buttonText: '',
79
+ item: favoriteSellerOptions,
80
+ storeConfig: storeConfigData ? storeConfigData.storeConfig : {}
81
+ };
82
+
66
83
  return {
67
84
  error,
68
85
  loading,
69
- seller
86
+ seller,
87
+ favoriteSellerButtonProps
70
88
  };
71
89
  };