-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
product-list-content.tsx
168 lines (159 loc) · 4.24 KB
/
product-list-content.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* External dependencies
*/
import {
createInterpolateElement,
Fragment,
useEffect,
useState,
} from '@wordpress/element';
import classnames from 'classnames';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import './product-list-content.scss';
import '~/customize-store/intro/intro.scss';
import '~/customize-store/style.scss';
import ProductCard from '../product-card/product-card';
import { Product, ProductType } from '../product-list/types';
import { appendURLParams } from '../../utils/functions';
import { ADMIN_URL, getAdminSetting } from '~/utils/admin-settings';
import { NoAIBanner } from '~/customize-store/intro/intro-banners';
import { addQueryArgs } from '@wordpress/url';
export default function ProductListContent( props: {
products: Product[];
group?: string;
productGroup?: string;
type: ProductType;
className?: string;
searchTerm?: string;
category?: string;
} ): JSX.Element {
const wccomHelperSettings = getAdminSetting( 'wccomHelper', {} );
const classes = classnames(
'woocommerce-marketplace__product-list-content',
props.className
);
const [ columns, setColumns ] = useState( 1 );
const updateColumns = () => {
const screenWidth = window.innerWidth;
if ( screenWidth >= 1920 ) {
setColumns( 4 );
} else if ( screenWidth >= 1024 ) {
setColumns( 3 );
} else if ( screenWidth >= 769 ) {
setColumns( 2 );
} else {
setColumns( 1 );
}
};
useEffect( () => {
updateColumns();
// Update columns on screen resize to adjust for responsive layout
window.addEventListener( 'resize', updateColumns );
return () => window.removeEventListener( 'resize', updateColumns );
}, [] );
const bannerPosition = columns * 2 - 1;
return (
<>
<div className={ classes }>
{ props.products.map( ( product, index ) => (
<Fragment key={ product.id }>
<ProductCard
key={ product.id }
type={ props.type }
product={ {
id: product.id,
slug: product.slug,
title: product.title,
image: product.image,
type: product.type,
icon: product.icon,
vendorName: product.vendorName,
vendorUrl: product.vendorUrl
? appendURLParams( product.vendorUrl, [
[
'utm_source',
'extensionsscreen',
],
[ 'utm_medium', 'product' ],
[ 'utm_campaign', 'wcaddons' ],
[ 'utm_content', 'devpartner' ],
] )
: '',
price: product.price,
url: appendURLParams(
product.url,
Object.entries( {
...wccomHelperSettings.inAppPurchaseURLParams,
...( props.productGroup !== undefined
? { utm_group: props.productGroup }
: {} ),
} )
),
averageRating: product.averageRating,
reviewsCount: product.reviewsCount,
description: product.description,
isInstallable: product.isInstallable,
} }
tracksData={ {
position: index + 1,
...( product.label && {
label: product.label,
} ),
...( props.group && { group: props.group } ),
...( props.searchTerm && {
searchTerm: props.searchTerm,
} ),
...( props.category && {
category: props.category,
} ),
} }
/>
{ index === bannerPosition && (
<NoAIBanner
redirectToCYSFlow={ () => {
const customizeStoreDesignUrl =
addQueryArgs(
`${ ADMIN_URL }admin.php`,
{
page: 'wc-admin',
path: '/customize-store/design',
}
);
window.location.href =
customizeStoreDesignUrl;
} }
/>
) }
</Fragment>
) ) }
</div>
<div
className={
'woocommerce-marketplace__browse-wp-theme-directory'
}
>
<b>{ __( 'Didn’t find a theme you like?', 'woocommerce' ) }</b>
{ createInterpolateElement(
__(
' Browse the <a>WordPress.org theme directory</a> to discover more.',
'woocommerce'
),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={
ADMIN_URL +
'theme-install.php?search=e-commerce'
}
/>
),
}
) }
</div>
</>
);
}