@akinon/projectzero 2.0.152 → 2.0.153-rc.4

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 (53) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/app-template/.env.example +1 -0
  3. package/app-template/AGENTS.md +8 -0
  4. package/app-template/CHANGELOG.md +89 -0
  5. package/app-template/README.md +25 -1
  6. package/app-template/docs/plugins.md +6 -0
  7. package/app-template/next-env.d.ts +1 -1
  8. package/app-template/next.config.mjs +7 -1
  9. package/app-template/package.json +41 -41
  10. package/app-template/public/locales/en/common.json +5 -0
  11. package/app-template/public/locales/en/product.json +6 -0
  12. package/app-template/public/locales/tr/common.json +5 -0
  13. package/app-template/public/locales/tr/product.json +6 -0
  14. package/app-template/src/__tests__/data-source-landing-page.test.tsx +132 -0
  15. package/app-template/src/app/[pz]/[...prettyurl]/page.tsx +14 -0
  16. package/app-template/src/app/[pz]/account/orders/[id]/(detail)/page.tsx +21 -0
  17. package/app-template/src/app/[pz]/data-source-landing-page/[pk]/loading.tsx +5 -0
  18. package/app-template/src/app/[pz]/data-source-landing-page/[pk]/page.tsx +62 -0
  19. package/app-template/src/app/[pz]/product/[pk]/page.tsx +7 -1
  20. package/app-template/src/app/api/client-env/route.ts +5 -0
  21. package/app-template/src/app/global-error.tsx +22 -0
  22. package/app-template/src/hooks/favourite-product-ids-context.tsx +104 -0
  23. package/app-template/src/hooks/index.ts +2 -0
  24. package/app-template/src/hooks/use-fav-button.tsx +35 -13
  25. package/app-template/src/plugins.js +1 -0
  26. package/app-template/src/proxy.ts +2 -1
  27. package/app-template/src/types/widgets.ts +58 -0
  28. package/app-template/src/utils/__tests__/favourite-product-ids-fallback.test.ts +42 -0
  29. package/app-template/src/utils/__tests__/sanitize.test.ts +127 -0
  30. package/app-template/src/utils/favourite-product-ids-fallback.ts +51 -0
  31. package/app-template/src/utils/sanitize.ts +167 -0
  32. package/app-template/src/views/category/category-info.tsx +31 -17
  33. package/app-template/src/views/data-source-page/__tests__/header.test.tsx +173 -0
  34. package/app-template/src/views/data-source-page/__tests__/layout.test.tsx +83 -0
  35. package/app-template/src/views/data-source-page/__tests__/sections.test.tsx +143 -0
  36. package/app-template/src/views/data-source-page/banner.tsx +45 -0
  37. package/app-template/src/views/data-source-page/footer.tsx +27 -0
  38. package/app-template/src/views/data-source-page/header.tsx +140 -0
  39. package/app-template/src/views/data-source-page/layout.tsx +45 -0
  40. package/app-template/src/views/data-source-page/products.tsx +55 -0
  41. package/app-template/src/views/data-source-page/stories.tsx +70 -0
  42. package/app-template/src/views/header/search/index.tsx +13 -5
  43. package/app-template/src/views/product/__tests__/product-offers.test.tsx +217 -0
  44. package/app-template/src/views/product/index.ts +1 -0
  45. package/app-template/src/views/product/product-info.tsx +14 -0
  46. package/app-template/src/views/product/product-offers.tsx +125 -0
  47. package/app-template/src/views/product/rate-review.tsx +21 -0
  48. package/app-template/src/views/product/slider.tsx +85 -38
  49. package/app-template/src/views/product-item/index.tsx +6 -1
  50. package/app-template/tsconfig.json +3 -0
  51. package/commands/plugins.ts +8 -0
  52. package/dist/commands/plugins.js +8 -0
  53. package/package.json +1 -1
@@ -0,0 +1,125 @@
1
+ 'use client';
2
+
3
+ import clsx from 'clsx';
4
+ import React, { useEffect, useRef, useState } from 'react';
5
+ import { Link, Price } from '@theme/components';
6
+ import { useLocalization } from '@akinon/next/hooks';
7
+ import { Product } from '@akinon/next/types';
8
+
9
+ const INITIAL_OFFER_COUNT = 2;
10
+
11
+ interface ProductOffersProps {
12
+ offers?: Product[];
13
+ productPk?: Product['pk'];
14
+ }
15
+
16
+ export const ProductOffers: React.FC<ProductOffersProps> = ({
17
+ offers,
18
+ productPk
19
+ }) => {
20
+ const { t } = useLocalization();
21
+ const [showAll, setShowAll] = useState(false);
22
+ const revealedOfferRef = useRef<HTMLDivElement>(null);
23
+
24
+ // See all unmounts itself on click, so hand the focus to the first offer it
25
+ // revealed instead of dropping it on the document.
26
+ useEffect(() => {
27
+ if (showAll) {
28
+ revealedOfferRef.current?.focus();
29
+ }
30
+ }, [showAll]);
31
+
32
+ // The product on screen can itself be one of the offers (a seller's own
33
+ // product), and it is not another seller of the product.
34
+ const otherOffers = offers?.filter((offer) => offer.pk !== productPk) ?? [];
35
+
36
+ if (!otherOffers.length) {
37
+ return null;
38
+ }
39
+
40
+ const displayedOffers = showAll
41
+ ? otherOffers
42
+ : otherOffers.slice(0, INITIAL_OFFER_COUNT);
43
+
44
+ return (
45
+ <div className="w-full mb-8" data-testid="product-offers">
46
+ <div className="w-full text-left text-sm pb-1 mb-2">
47
+ {t('product.offers.title')}
48
+ </div>
49
+
50
+ <div className="w-full border p-4">
51
+ <div>
52
+ {displayedOffers.map((offer, index) => {
53
+ const sellerName =
54
+ offer.data_source?.title || offer.data_source?.name;
55
+ const starGrade = parseFloat(offer.attributes?.erp_star_grade);
56
+ const isFirstRevealed = index === INITIAL_OFFER_COUNT;
57
+
58
+ return (
59
+ <div
60
+ key={offer.pk}
61
+ ref={isFirstRevealed ? revealedOfferRef : undefined}
62
+ tabIndex={isFirstRevealed ? -1 : undefined}
63
+ className="mb-2 pb-2 border-b last:mb-0 last:pb-0 last:border-none"
64
+ data-testid="product-offer"
65
+ >
66
+ <div className="flex items-center gap-1 mb-1">
67
+ {/* Commerce builds the offer url with the seller_id and the
68
+ variant, so it opens that seller's own product. */}
69
+ {sellerName && (
70
+ <Link
71
+ href={offer.absolute_url}
72
+ className="text-sm text-[#1f6bc1] font-medium hover:underline"
73
+ >
74
+ {sellerName}
75
+ </Link>
76
+ )}
77
+
78
+ {Number.isFinite(starGrade) && (
79
+ <div
80
+ className="text-[10px] px-1 bg-[#08b449] text-white flex items-center justify-center rounded"
81
+ data-testid="offer-star-grade"
82
+ >
83
+ {starGrade.toFixed(1)}
84
+ </div>
85
+ )}
86
+ </div>
87
+
88
+ {offer.name && (
89
+ <div className="text-sm mb-1 text-gray-800">{offer.name}</div>
90
+ )}
91
+
92
+ <div className="flex items-center gap-2">
93
+ {offer.price && (
94
+ <Price className="font-bold" value={offer.price} />
95
+ )}
96
+
97
+ <span
98
+ className={clsx(
99
+ 'ml-auto text-xs',
100
+ offer.in_stock ? 'text-success' : 'text-error'
101
+ )}
102
+ >
103
+ {offer.in_stock
104
+ ? t('product.offers.in_stock')
105
+ : t('product.offers.out_of_stock')}
106
+ </span>
107
+ </div>
108
+ </div>
109
+ );
110
+ })}
111
+ </div>
112
+
113
+ {!showAll && otherOffers.length > INITIAL_OFFER_COUNT && (
114
+ <button
115
+ type="button"
116
+ className="w-full mt-2 text-center text-sm cursor-pointer hover:underline"
117
+ onClick={() => setShowAll(true)}
118
+ >
119
+ {t('product.offers.see_all')}
120
+ </button>
121
+ )}
122
+ </div>
123
+ </div>
124
+ );
125
+ };
@@ -0,0 +1,21 @@
1
+ 'use client';
2
+
3
+ import PluginModule, { Component } from '@akinon/next/components/plugin-module';
4
+ import { ProductPageProps } from './layout';
5
+
6
+ export default function ProductRateReview({
7
+ data
8
+ }: Pick<ProductPageProps, 'data'>) {
9
+ return (
10
+ <PluginModule
11
+ component={Component.ProductRateReview}
12
+ props={{
13
+ product: {
14
+ sku: data.product.sku,
15
+ base_code: data.product.base_code
16
+ },
17
+ classNames: { root: 'w-full mt-8' }
18
+ }}
19
+ />
20
+ );
21
+ }
@@ -36,53 +36,100 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
36
36
  carouselRef.current?.next();
37
37
  };
38
38
 
39
- const handleThumbnailClick = (index) => {
39
+ const handleThumbnailClick = (index: number) => {
40
40
  setActiveIndex(index);
41
41
  carouselRef.current?.goToSlide(index);
42
42
  };
43
43
 
44
44
  return (
45
- <div className="lg:grid lg:grid-cols-6">
46
- <div className="lg:col-span-1">
47
- <div className="flex flex-col items-center justify-center md:mr-[6px]">
48
- <button
49
- onClick={goToPrev}
50
- className={twMerge(
51
- 'hidden justify-center p-2 mb-3 border border-gray-100 rounded-full cursor-pointer lg:block',
52
- [activeIndex === 0 && 'cursor-not-allowed opacity-45']
53
- )}
54
- disabled={activeIndex === 0}
45
+ <>
46
+ <div className="lg:grid lg:grid-cols-6">
47
+ <div className="lg:col-span-1">
48
+ <div className="flex flex-col items-center justify-center md:mr-[6px]">
49
+ <button
50
+ onClick={goToPrev}
51
+ className={twMerge(
52
+ 'hidden justify-center p-2 mb-3 border border-gray-100 rounded-full cursor-pointer lg:block',
53
+ [activeIndex === 0 && 'cursor-not-allowed opacity-45']
54
+ )}
55
+ disabled={activeIndex === 0}
56
+ >
57
+ <Icon name="chevron-up" size={15} className="fill-[#000000]" />
58
+ </button>
59
+ <div className="hidden flex-col items-center overflow-scroll w-[80px] max-h-[620px] lg:block">
60
+ {product?.productimage_set?.map((item, index) => (
61
+ <Image
62
+ key={index}
63
+ src={item.image}
64
+ alt={`Thumbnail ${index}`}
65
+ width={80}
66
+ height={128}
67
+ aspectRatio={80 / 128}
68
+ className={twMerge('cursor-pointer', [
69
+ activeIndex === index && 'border-2 border-primary'
70
+ ])}
71
+ onClick={() => handleThumbnailClick(index)}
72
+ />
73
+ ))}
74
+ </div>
75
+ <button
76
+ onClick={goToNext}
77
+ className={twMerge(
78
+ 'hidden justify-center p-2 mt-3 border border-gray-100 rounded-full cursor-pointer lg:block',
79
+ [
80
+ activeIndex === product.productimage_set.length - 1 &&
81
+ 'cursor-not-allowed opacity-45'
82
+ ]
83
+ )}
84
+ disabled={activeIndex === product.productimage_set.length - 1}
85
+ >
86
+ <Icon name="chevron-down" size={15} className="fill-[#000000]" />
87
+ </button>
88
+ </div>
89
+ </div>
90
+
91
+ <div className="relative lg:col-span-5">
92
+ <FavButton className="absolute right-8 top-6 z-[20] sm:hidden" />
93
+
94
+ <PluginModule
95
+ component={Component.ProductImageSearchFeature}
96
+ props={{
97
+ product,
98
+ activeIndex,
99
+ showResetButton: true
100
+ }}
101
+ />
102
+
103
+ <CarouselCore
104
+ responsive={{
105
+ all: {
106
+ breakpoint: { max: 5000, min: 0 },
107
+ items: 1
108
+ }
109
+ }}
110
+ arrows={false}
111
+ swipeable={true}
112
+ ref={carouselRef}
113
+ afterChange={(previousSlide, { currentSlide }) => {
114
+ setActiveIndex(currentSlide);
115
+ }}
116
+ containerAspectRatio={{ mobile: 520 / 798, desktop: 484 / 726 }}
55
117
  >
56
- <Icon name="chevron-up" size={15} className="fill-[#000000]" />
57
- </button>
58
- <div className="hidden flex-col items-center overflow-scroll w-[80px] max-h-[620px] lg:block">
59
- {product?.productimage_set?.map((item, index) => (
118
+ {product?.productimage_set?.map((item, i) => (
60
119
  <Image
61
- key={index}
120
+ key={i}
62
121
  src={item.image}
63
- alt={`Thumbnail ${index}`}
64
- width={80}
65
- height={128}
66
- className={twMerge('cursor-pointer', [
67
- activeIndex === index && 'border-2 border-primary'
68
- ])}
69
- onClick={() => handleThumbnailClick(index)}
122
+ alt={product?.name || 'Product image'}
123
+ draggable={false}
124
+ aspectRatio={484 / 726}
125
+ sizes="(min-width: 425px) 512px,
126
+ (min-width: 601px) 576px,
127
+ (min-width: 768px) 336px,
128
+ (min-width: 1024px) 484px, 368px"
129
+ fill
70
130
  />
71
131
  ))}
72
- </div>
73
- <button
74
- onClick={goToNext}
75
- className={twMerge(
76
- 'hidden justify-center p-2 mt-3 border border-gray-100 rounded-full cursor-pointer lg:block',
77
- [
78
- activeIndex === product.productimage_set.length - 1 &&
79
- 'cursor-not-allowed opacity-45'
80
- ]
81
- )}
82
- disabled={activeIndex === product.productimage_set.length - 1}
83
- >
84
- <Icon name="chevron-down" size={15} className="fill-[#000000]" />
85
- </button>
132
+ </CarouselCore>
86
133
  </div>
87
134
  </div>
88
135
 
@@ -140,6 +187,6 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
140
187
  ))}
141
188
  </CarouselCore>
142
189
  </div>
143
- </div>
190
+ </>
144
191
  );
145
192
  }
@@ -10,6 +10,7 @@ import useFavButton from '../../hooks/use-fav-button';
10
10
  import { Product } from '@akinon/next/types';
11
11
  import { Image } from '@akinon/next/components/image';
12
12
  import { Price, Link } from '@theme/components';
13
+ import PluginModule, { Component } from '@akinon/next/components/plugin-module';
13
14
 
14
15
  interface Props {
15
16
  product: Product;
@@ -22,7 +23,7 @@ export const ProductItem = (props: Props) => {
22
23
  // TODO: Static image will change (TR)
23
24
  const { product, width, height, index } = props;
24
25
  const [viewed, setViewed] = useState(false);
25
- const { FavButton } = useFavButton(product.pk);
26
+ const { FavButton } = useFavButton(product.pk, product);
26
27
  const { ref, inView } = useInView();
27
28
 
28
29
  const image_url = product.productimage_set[0]?.image;
@@ -81,6 +82,10 @@ export const ProductItem = (props: Props) => {
81
82
  >
82
83
  {product_name}
83
84
  </Link>
85
+ <PluginModule
86
+ component={Component.RateReviewPlpBadge}
87
+ props={{ product }}
88
+ />
84
89
  <div className="font-semibold">
85
90
  {parseFloat(retail_price) > parseFloat(price) && (
86
91
  <Price
@@ -24,6 +24,9 @@
24
24
  ],
25
25
  "@flat-page/*": [
26
26
  "./app/[pz]/flat-page/*"
27
+ ],
28
+ "@data-source-landing-page/*": [
29
+ "./app/[pz]/data-source-landing-page/*"
27
30
  ]
28
31
  },
29
32
  "allowSyntheticDefaultImports": true,
@@ -164,6 +164,10 @@ export default async () => {
164
164
  name: 'Tamara Payment Extension',
165
165
  value: 'pz-tamara-extension'
166
166
  },
167
+ {
168
+ name: 'Similar Products',
169
+ value: 'pz-similar-products'
170
+ },
167
171
  {
168
172
  name: 'Hepsipay',
169
173
  value: 'pz-hepsipay'
@@ -176,6 +180,10 @@ export default async () => {
176
180
  name: 'Virtual Try-On',
177
181
  value: 'pz-virtual-try-on'
178
182
  },
183
+ {
184
+ name: 'Rate & Review',
185
+ value: 'pz-rate-review'
186
+ },
179
187
  {
180
188
  name: 'Masterpass Rest',
181
189
  value: 'pz-masterpass-rest'
@@ -183,6 +183,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
183
183
  name: 'Tamara Payment Extension',
184
184
  value: 'pz-tamara-extension'
185
185
  },
186
+ {
187
+ name: 'Similar Products',
188
+ value: 'pz-similar-products'
189
+ },
186
190
  {
187
191
  name: 'Hepsipay',
188
192
  value: 'pz-hepsipay'
@@ -195,6 +199,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
195
199
  name: 'Virtual Try-On',
196
200
  value: 'pz-virtual-try-on'
197
201
  },
202
+ {
203
+ name: 'Rate & Review',
204
+ value: 'pz-rate-review'
205
+ },
198
206
  {
199
207
  name: 'Masterpass Rest',
200
208
  value: 'pz-masterpass-rest'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "2.0.152",
3
+ "version": "2.0.153-rc.4",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {