@pradip1995/segment-bestsellers-carousel 0.2.0
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 +38 -0
- package/src/index.ts +2 -0
- package/src/manifest.ts +11 -0
- package/src/segment.tsx +49 -0
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pradip1995/segment-bestsellers-carousel",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/index.ts",
|
|
14
|
+
"./manifest": "./src/manifest.ts"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
18
|
+
"react": ">=19",
|
|
19
|
+
"react-dom": ">=19",
|
|
20
|
+
"next": ">=15"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@pradip1995/commerce-core": "^4.0.0",
|
|
24
|
+
"@pradip1995/segment-primitives": "0.2.0",
|
|
25
|
+
"@pradip1995/segment-product-card": "0.2.0",
|
|
26
|
+
"@pradip1995/segment-tokens": "0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
30
|
+
"@types/react": "^19",
|
|
31
|
+
"react": "19.0.3",
|
|
32
|
+
"typescript": "^5.7.2"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"lint": "tsc --noEmit"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
package/src/manifest.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SegmentManifest } from "@pradip1995/plugin-sdk"
|
|
2
|
+
|
|
3
|
+
const manifest: SegmentManifest = {
|
|
4
|
+
id: "bestsellers-carousel",
|
|
5
|
+
type: "segment",
|
|
6
|
+
version: "0.1.0",
|
|
7
|
+
compatibleFramework: ["^1.0.0"],
|
|
8
|
+
dataKey: "lovedByMoms",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default manifest
|
package/src/segment.tsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getProductsByTag } from "@pradip1995/commerce-core/data/products"
|
|
2
|
+
import ProductScroll from "@pradip1995/segment-product-card/product-scroll"
|
|
3
|
+
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
4
|
+
import type { HttpTypes } from "@medusajs/types"
|
|
5
|
+
|
|
6
|
+
export default async function BestsellersCarousel({
|
|
7
|
+
products: fallbackProducts,
|
|
8
|
+
region,
|
|
9
|
+
ratings,
|
|
10
|
+
title = "Best sellers",
|
|
11
|
+
viewAllLink = "View all",
|
|
12
|
+
}: {
|
|
13
|
+
products?: HttpTypes.StoreProduct[]
|
|
14
|
+
region?: HttpTypes.StoreRegion | null
|
|
15
|
+
ratings?: Array<{ product_id?: string; rating?: number }>
|
|
16
|
+
title?: string
|
|
17
|
+
viewAllLink?: string
|
|
18
|
+
}) {
|
|
19
|
+
const countryCode =
|
|
20
|
+
region?.countries?.[0]?.iso_2?.toLowerCase() ??
|
|
21
|
+
process.env.NEXT_PUBLIC_DEFAULT_REGION?.toLowerCase() ??
|
|
22
|
+
"in"
|
|
23
|
+
|
|
24
|
+
let products = fallbackProducts ?? []
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const tagged = await getProductsByTag({ tagValue: "bestseller", limit: 12, countryCode })
|
|
28
|
+
if (tagged.length > 0) products = tagged
|
|
29
|
+
} catch {
|
|
30
|
+
products = fallbackProducts ?? []
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const list = products.slice(0, 12)
|
|
34
|
+
if (list.length === 0) return null
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<section className="bestsellers w-full py-8 md:py-12 bg-surface-muted">
|
|
38
|
+
<div className="mx-auto px-2 sm:px-3 lg:px-4" style={{ maxWidth: "var(--container-max)" }}>
|
|
39
|
+
<div className="home-section-header">
|
|
40
|
+
<h2 className="home-section-header__title">{title}</h2>
|
|
41
|
+
<LocalizedLink href="/store?sortBy=bestsellers" className="home-section-header__link">
|
|
42
|
+
{viewAllLink}
|
|
43
|
+
</LocalizedLink>
|
|
44
|
+
</div>
|
|
45
|
+
<ProductScroll products={list} region={region} ratings={ratings} />
|
|
46
|
+
</div>
|
|
47
|
+
</section>
|
|
48
|
+
)
|
|
49
|
+
}
|