@@ -4,17 +4,17 @@ import { CollectionServiceDefinition } from "./collection-service";
4
4
import { productsV3 } from "@wix/stores" ;
5
5
6
6
/**
7
- * Props for ProductGrid headless component
7
+ * Props for Grid headless component
8
8
*/
9
- export interface ProductGridProps {
9
+ export interface GridProps {
10
10
/** Render prop function that receives product grid data */
11
- children : ( props : ProductGridRenderProps ) => React . ReactNode ;
11
+ children : ( props : GridRenderProps ) => React . ReactNode ;
12
12
}
13
13
14
14
/**
15
- * Render props for ProductGrid component
15
+ * Render props for Grid component
16
16
*/
17
- export interface ProductGridRenderProps {
17
+ export interface GridRenderProps {
18
18
/** Array of products */
19
19
products : productsV3 . V3Product [ ] ;
20
20
/** Whether products are loading */
@@ -32,7 +32,7 @@ export interface ProductGridRenderProps {
32
32
/**
33
33
* Headless component for product grid
34
34
*/
35
- export const ProductGrid = ( props : ProductGridProps ) => {
35
+ export const Grid = ( props : GridProps ) => {
36
36
const service = useService ( CollectionServiceDefinition ) as ServiceAPI <
37
37
typeof CollectionServiceDefinition
38
38
> ;
@@ -80,79 +80,79 @@ export const ProductGrid = (props: ProductGridProps) => {
80
80
} ;
81
81
82
82
/**
83
- * Props for ProductCard headless component
83
+ * Props for Item headless component
84
84
*/
85
- export interface ProductCardProps {
85
+ export interface ItemProps {
86
86
/** Product data */
87
87
product : productsV3 . V3Product ;
88
- /** Render prop function that receives product card data */
89
- children : ( props : ProductCardRenderProps ) => React . ReactNode ;
88
+ /** Render prop function that receives product item data */
89
+ children : ( props : ItemRenderProps ) => React . ReactNode ;
90
90
}
91
91
92
92
/**
93
- * Render props for ProductCard component
93
+ * Render props for Item component
94
94
*/
95
- export interface ProductCardRenderProps {
95
+ export interface ItemRenderProps {
96
96
/** Product ID */
97
- productId : string ;
98
- /** Product name */
99
- name : string ;
97
+ id : string ;
98
+ /** Product title */
99
+ title : string ;
100
100
/** Product slug for URL */
101
101
slug : string ;
102
102
/** Main product image URL */
103
- imageUrl : string | null ;
103
+ image : string | null ;
104
104
/** Product price */
105
105
price : string ;
106
106
/** Product description */
107
107
description : string ;
108
- /** Whether product is in stock */
109
- inStock : boolean ;
108
+ /** Whether product is available */
109
+ available : boolean ;
110
110
/** Product URL */
111
- productUrl : string ;
111
+ href : string ;
112
112
}
113
113
114
114
/**
115
- * Headless component for individual product card
115
+ * Headless component for individual product item
116
116
*/
117
- export const ProductCard = ( props : ProductCardProps ) => {
117
+ export const Item = ( props : ItemProps ) => {
118
118
const { product } = props ;
119
119
120
120
// Use actual v3 API structure based on real data
121
121
// Images are in media.main.image, not media.itemsInfo.items
122
- const imageUrl = product ?. media ?. main ?. image || null ;
122
+ const image = product ?. media ?. main ?. image || null ;
123
123
124
124
// Create formatted price since formattedAmount is not available
125
125
const rawAmount = product . actualPriceRange ?. minValue ?. amount ;
126
126
const price = rawAmount ? `$${ rawAmount } ` : "$0.00" ;
127
127
128
- const inStock = product . inventory ?. availabilityStatus === "IN_STOCK" ;
128
+ const available = product . inventory ?. availabilityStatus === "IN_STOCK" ;
129
129
const description =
130
130
typeof product . description === "string" ? product . description : "" ;
131
131
132
132
return props . children ( {
133
- productId : product . _id || "" ,
134
- name : product . name || "" ,
133
+ id : product . _id || "" ,
134
+ title : product . name || "" ,
135
135
slug : product . slug || "" ,
136
- imageUrl ,
136
+ image ,
137
137
price,
138
138
description,
139
- inStock ,
140
- productUrl : `/store/products/${ product . slug } ` ,
139
+ available ,
140
+ href : `/store/products/${ product . slug } ` ,
141
141
} ) ;
142
142
} ;
143
143
144
144
/**
145
- * Props for LoadMoreProducts headless component
145
+ * Props for LoadMore headless component
146
146
*/
147
- export interface LoadMoreProductsProps {
147
+ export interface LoadMoreProps {
148
148
/** Render prop function that receives load more data */
149
- children : ( props : LoadMoreProductsRenderProps ) => React . ReactNode ;
149
+ children : ( props : LoadMoreRenderProps ) => React . ReactNode ;
150
150
}
151
151
152
152
/**
153
- * Render props for LoadMoreProducts component
153
+ * Render props for LoadMore component
154
154
*/
155
- export interface LoadMoreProductsRenderProps {
155
+ export interface LoadMoreRenderProps {
156
156
/** Function to load more products */
157
157
loadMore : ( ) => Promise < void > ;
158
158
/** Function to refresh products */
@@ -169,14 +169,14 @@ export interface LoadMoreProductsRenderProps {
169
169
* Headless component for load more products functionality
170
170
* Note: V3 API uses simplified loading without traditional pagination
171
171
*/
172
- export const LoadMoreProducts = ( props : LoadMoreProductsProps ) => {
172
+ export const LoadMore = ( props : LoadMoreProps ) => {
173
173
const service = useService ( CollectionServiceDefinition ) as ServiceAPI <
174
174
typeof CollectionServiceDefinition
175
175
> ;
176
176
177
177
// Error handling for undefined service
178
178
if ( ! service ) {
179
- console . error ( "CollectionService is undefined in LoadMoreProducts " ) ;
179
+ console . error ( "CollectionService is undefined in LoadMore " ) ;
180
180
return props . children ( {
181
181
loadMore : async ( ) => { } ,
182
182
refresh : async ( ) => { } ,
@@ -199,7 +199,7 @@ export const LoadMoreProducts = (props: LoadMoreProductsProps) => {
199
199
totalProducts,
200
200
} ) ;
201
201
} catch ( err ) {
202
- console . error ( "Error in LoadMoreProducts :" , err ) ;
202
+ console . error ( "Error in LoadMore :" , err ) ;
203
203
return props . children ( {
204
204
loadMore : async ( ) => { } ,
205
205
refresh : async ( ) => { } ,
@@ -211,17 +211,17 @@ export const LoadMoreProducts = (props: LoadMoreProductsProps) => {
211
211
} ;
212
212
213
213
/**
214
- * Props for CollectionHeader headless component
214
+ * Props for Header headless component
215
215
*/
216
- export interface CollectionHeaderProps {
216
+ export interface HeaderProps {
217
217
/** Render prop function that receives collection header data */
218
- children : ( props : CollectionHeaderRenderProps ) => React . ReactNode ;
218
+ children : ( props : HeaderRenderProps ) => React . ReactNode ;
219
219
}
220
220
221
221
/**
222
- * Render props for CollectionHeader component
222
+ * Render props for Header component
223
223
*/
224
- export interface CollectionHeaderRenderProps {
224
+ export interface HeaderRenderProps {
225
225
/** Total number of products */
226
226
totalProducts : number ;
227
227
/** Whether collection is loading */
@@ -233,14 +233,14 @@ export interface CollectionHeaderRenderProps {
233
233
/**
234
234
* Headless component for collection header with product count
235
235
*/
236
- export const CollectionHeader = ( props : CollectionHeaderProps ) => {
236
+ export const Header = ( props : HeaderProps ) => {
237
237
const service = useService ( CollectionServiceDefinition ) as ServiceAPI <
238
238
typeof CollectionServiceDefinition
239
239
> ;
240
240
241
241
// Error handling for undefined service
242
242
if ( ! service ) {
243
- console . error ( "CollectionService is undefined in CollectionHeader " ) ;
243
+ console . error ( "CollectionService is undefined in Header " ) ;
244
244
return props . children ( {
245
245
totalProducts : 0 ,
246
246
isLoading : false ,
@@ -259,7 +259,7 @@ export const CollectionHeader = (props: CollectionHeaderProps) => {
259
259
hasProducts,
260
260
} ) ;
261
261
} catch ( err ) {
262
- console . error ( "Error in CollectionHeader :" , err ) ;
262
+ console . error ( "Error in Header :" , err ) ;
263
263
return props . children ( {
264
264
totalProducts : 0 ,
265
265
isLoading : false ,
@@ -269,17 +269,17 @@ export const CollectionHeader = (props: CollectionHeaderProps) => {
269
269
} ;
270
270
271
271
/**
272
- * Props for CollectionActions headless component
272
+ * Props for Actions headless component
273
273
*/
274
- export interface CollectionActionsProps {
274
+ export interface ActionsProps {
275
275
/** Render prop function that receives collection actions data */
276
- children : ( props : CollectionActionsRenderProps ) => React . ReactNode ;
276
+ children : ( props : ActionsRenderProps ) => React . ReactNode ;
277
277
}
278
278
279
279
/**
280
- * Render props for CollectionActions component
280
+ * Render props for Actions component
281
281
*/
282
- export interface CollectionActionsRenderProps {
282
+ export interface ActionsRenderProps {
283
283
/** Function to refresh the collection */
284
284
refresh : ( ) => Promise < void > ;
285
285
/** Function to load more products */
@@ -294,14 +294,14 @@ export interface CollectionActionsRenderProps {
294
294
* Headless component for collection actions (refresh, load more)
295
295
* Replaces traditional pagination for V3 API
296
296
*/
297
- export const CollectionActions = ( props : CollectionActionsProps ) => {
297
+ export const Actions = ( props : ActionsProps ) => {
298
298
const service = useService ( CollectionServiceDefinition ) as ServiceAPI <
299
299
typeof CollectionServiceDefinition
300
300
> ;
301
301
302
302
// Error handling for undefined service
303
303
if ( ! service ) {
304
- console . error ( "CollectionService is undefined in CollectionActions " ) ;
304
+ console . error ( "CollectionService is undefined in Actions " ) ;
305
305
return props . children ( {
306
306
refresh : async ( ) => { } ,
307
307
loadMore : async ( ) => { } ,
@@ -321,7 +321,7 @@ export const CollectionActions = (props: CollectionActionsProps) => {
321
321
error,
322
322
} ) ;
323
323
} catch ( err ) {
324
- console . error ( "Error in CollectionActions :" , err ) ;
324
+ console . error ( "Error in Actions :" , err ) ;
325
325
return props . children ( {
326
326
refresh : async ( ) => { } ,
327
327
loadMore : async ( ) => { } ,
@@ -331,11 +331,10 @@ export const CollectionActions = (props: CollectionActionsProps) => {
331
331
}
332
332
} ;
333
333
334
- // Namespace export for clean API
335
334
export const Collection = {
336
- ProductGrid ,
337
- ProductCard ,
338
- LoadMoreProducts ,
339
- CollectionHeader ,
340
- CollectionActions ,
335
+ Grid ,
336
+ Item ,
337
+ LoadMore ,
338
+ Header ,
339
+ Actions ,
341
340
} as const ;
0 commit comments