@akinon/projectzero 2.0.116-rc.0 → 2.0.117-beta.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/CHANGELOG.md +2 -6
- package/app-template/.env.example +0 -1
- package/app-template/AGENTS.md +0 -8
- package/app-template/CHANGELOG.md +65 -83
- package/app-template/README.md +1 -25
- package/app-template/next.config.mjs +1 -7
- package/app-template/package.json +41 -41
- package/app-template/src/hooks/index.ts +0 -2
- package/app-template/src/hooks/use-fav-button.tsx +13 -35
- package/app-template/src/plugins.js +0 -1
- package/app-template/src/proxy.ts +1 -2
- package/app-template/src/views/category/category-info.tsx +17 -25
- package/app-template/src/views/header/search/index.tsx +5 -13
- package/app-template/src/views/product/slider.tsx +38 -85
- package/app-template/src/views/product-item/index.tsx +1 -1
- package/commands/plugins.ts +0 -4
- package/dist/commands/plugins.js +0 -4
- package/package.json +1 -1
- package/app-template/src/app/api/client-env/route.ts +0 -5
- package/app-template/src/app/global-error.tsx +0 -22
- package/app-template/src/hooks/favourite-product-ids-context.tsx +0 -104
- package/app-template/src/utils/__tests__/favourite-product-ids-fallback.test.ts +0 -42
- package/app-template/src/utils/favourite-product-ids-fallback.ts +0 -51
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# @akinon/projectzero
|
|
2
2
|
|
|
3
|
-
## 2.0.
|
|
3
|
+
## 2.0.117-beta.0
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- 143be2b9d: ZERO-3457: Crop styles are customizable and logic improved for rendering similar products modal
|
|
8
|
-
- d99a6a7d5: ZERO-3457_1: Fixed the settings prop and made sure everything is customizable.
|
|
9
|
-
- e18836b20: ZERO-4160: Restore scope in Sentry addon configuration in akinon.json
|
|
5
|
+
## 2.0.116
|
|
10
6
|
|
|
11
7
|
## 2.0.115
|
|
12
8
|
|
|
@@ -7,7 +7,6 @@ NEXT_PUBLIC_URL=http://localhost:3000
|
|
|
7
7
|
SERVICE_BACKEND_URL=https://02fde10fee4440269e695aa10707dfaf.lb.akinoncloud.com
|
|
8
8
|
SITEMAP_S3_BUCKET_NAME=0fb534
|
|
9
9
|
NEXT_PUBLIC_VIRTUAL_TRY_ON_API_URL=https://d2a26507c7094f359aba349b96a96881.lb.akinoncloud.com
|
|
10
|
-
NEXT_PUBLIC_ENABLE_IMAGE_SEARCH=true
|
|
11
10
|
|
|
12
11
|
# PZ Dashboard dataLayer observability (unset = observer disabled)
|
|
13
12
|
# NEXT_PUBLIC_PZ_DASHBOARD_URL=http://localhost:3005
|
package/app-template/AGENTS.md
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
<!-- BEGIN:nextjs-agent-rules -->
|
|
2
|
-
|
|
3
|
-
# Next.js: ALWAYS read docs before coding
|
|
4
|
-
|
|
5
|
-
Before any Next.js work, find and read the relevant doc in `node_modules/next/dist/docs/`. Your training data is outdated — the docs are the source of truth.
|
|
6
|
-
|
|
7
|
-
<!-- END:nextjs-agent-rules -->
|
|
8
|
-
|
|
9
1
|
# Project Zero Next.js - Developer Instructions
|
|
10
2
|
|
|
11
3
|
## 📚 Available Instruction Files
|
|
@@ -1,88 +1,70 @@
|
|
|
1
1
|
# projectzeronext
|
|
2
2
|
|
|
3
|
-
## 2.0.
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
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
|
-
- Updated dependencies [
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
- @akinon/pz-
|
|
60
|
-
- @akinon/
|
|
61
|
-
- @akinon/pz-
|
|
62
|
-
- @akinon/pz-
|
|
63
|
-
- @akinon/pz-
|
|
64
|
-
- @akinon/pz-
|
|
65
|
-
- @akinon/pz-
|
|
66
|
-
- @akinon/pz-
|
|
67
|
-
- @akinon/pz-
|
|
68
|
-
- @akinon/pz-multi-basket@2.0.116-rc.0
|
|
69
|
-
- @akinon/pz-masterpass@2.0.116-rc.0
|
|
70
|
-
- @akinon/pz-gpay@2.0.116-rc.0
|
|
71
|
-
- @akinon/pz-b2b@2.0.116-rc.0
|
|
72
|
-
- @akinon/pz-bkm@2.0.116-rc.0
|
|
73
|
-
- @akinon/pz-otp@2.0.116-rc.0
|
|
74
|
-
- @akinon/pz-similar-products@2.0.116-rc.0
|
|
75
|
-
- @akinon/pz-virtual-try-on@2.0.116-rc.0
|
|
76
|
-
- @akinon/pz-theme@2.0.116-rc.0
|
|
77
|
-
- @akinon/pz-akifast@2.0.116-rc.0
|
|
78
|
-
- @akinon/pz-apple-pay@2.0.116-rc.0
|
|
79
|
-
- @akinon/pz-cybersource-uc@2.0.116-rc.0
|
|
80
|
-
- @akinon/pz-flow-payment@2.0.116-rc.0
|
|
81
|
-
- @akinon/pz-google-pay@2.0.116-rc.0
|
|
82
|
-
- @akinon/pz-haso@2.0.116-rc.0
|
|
83
|
-
- @akinon/pz-hepsipay@2.0.116-rc.0
|
|
84
|
-
- @akinon/pz-saved-card@2.0.116-rc.0
|
|
85
|
-
- @akinon/pz-tamara-extension@2.0.116-rc.0
|
|
3
|
+
## 2.0.117-beta.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [cbbbfd757]
|
|
8
|
+
- @akinon/next@2.0.117-beta.0
|
|
9
|
+
- @akinon/pz-theme@2.0.117-beta.0
|
|
10
|
+
- @akinon/pz-virtual-try-on@2.0.117-beta.0
|
|
11
|
+
- @akinon/pz-akifast@2.0.117-beta.0
|
|
12
|
+
- @akinon/pz-apple-pay@2.0.117-beta.0
|
|
13
|
+
- @akinon/pz-b2b@2.0.117-beta.0
|
|
14
|
+
- @akinon/pz-basket-gift-pack@2.0.117-beta.0
|
|
15
|
+
- @akinon/pz-bkm@2.0.117-beta.0
|
|
16
|
+
- @akinon/pz-checkout-gift-pack@2.0.117-beta.0
|
|
17
|
+
- @akinon/pz-click-collect@2.0.117-beta.0
|
|
18
|
+
- @akinon/pz-credit-payment@2.0.117-beta.0
|
|
19
|
+
- @akinon/pz-cybersource-uc@2.0.117-beta.0
|
|
20
|
+
- @akinon/pz-flow-payment@2.0.117-beta.0
|
|
21
|
+
- @akinon/pz-google-pay@2.0.117-beta.0
|
|
22
|
+
- @akinon/pz-gpay@2.0.117-beta.0
|
|
23
|
+
- @akinon/pz-haso@2.0.117-beta.0
|
|
24
|
+
- @akinon/pz-hepsipay@2.0.117-beta.0
|
|
25
|
+
- @akinon/pz-masterpass@2.0.117-beta.0
|
|
26
|
+
- @akinon/pz-masterpass-rest@2.0.117-beta.0
|
|
27
|
+
- @akinon/pz-multi-basket@2.0.117-beta.0
|
|
28
|
+
- @akinon/pz-one-click-checkout@2.0.117-beta.0
|
|
29
|
+
- @akinon/pz-otp@2.0.117-beta.0
|
|
30
|
+
- @akinon/pz-pay-on-delivery@2.0.117-beta.0
|
|
31
|
+
- @akinon/pz-saved-card@2.0.117-beta.0
|
|
32
|
+
- @akinon/pz-similar-products@2.0.117-beta.0
|
|
33
|
+
- @akinon/pz-tabby-extension@2.0.117-beta.0
|
|
34
|
+
- @akinon/pz-tamara-extension@2.0.117-beta.0
|
|
35
|
+
|
|
36
|
+
## 2.0.116
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [9062fa0]
|
|
41
|
+
- @akinon/pz-theme@2.0.116
|
|
42
|
+
- @akinon/next@2.0.116
|
|
43
|
+
- @akinon/pz-akifast@2.0.116
|
|
44
|
+
- @akinon/pz-apple-pay@2.0.116
|
|
45
|
+
- @akinon/pz-b2b@2.0.116
|
|
46
|
+
- @akinon/pz-basket-gift-pack@2.0.116
|
|
47
|
+
- @akinon/pz-bkm@2.0.116
|
|
48
|
+
- @akinon/pz-checkout-gift-pack@2.0.116
|
|
49
|
+
- @akinon/pz-click-collect@2.0.116
|
|
50
|
+
- @akinon/pz-credit-payment@2.0.116
|
|
51
|
+
- @akinon/pz-cybersource-uc@2.0.116
|
|
52
|
+
- @akinon/pz-flow-payment@2.0.116
|
|
53
|
+
- @akinon/pz-google-pay@2.0.116
|
|
54
|
+
- @akinon/pz-gpay@2.0.116
|
|
55
|
+
- @akinon/pz-haso@2.0.116
|
|
56
|
+
- @akinon/pz-hepsipay@2.0.116
|
|
57
|
+
- @akinon/pz-masterpass@2.0.116
|
|
58
|
+
- @akinon/pz-masterpass-rest@2.0.116
|
|
59
|
+
- @akinon/pz-multi-basket@2.0.116
|
|
60
|
+
- @akinon/pz-one-click-checkout@2.0.116
|
|
61
|
+
- @akinon/pz-otp@2.0.116
|
|
62
|
+
- @akinon/pz-pay-on-delivery@2.0.116
|
|
63
|
+
- @akinon/pz-saved-card@2.0.116
|
|
64
|
+
- @akinon/pz-similar-products@2.0.116
|
|
65
|
+
- @akinon/pz-tabby-extension@2.0.116
|
|
66
|
+
- @akinon/pz-tamara-extension@2.0.116
|
|
67
|
+
- @akinon/pz-virtual-try-on@2.0.116
|
|
86
68
|
|
|
87
69
|
## 2.0.115
|
|
88
70
|
|
package/app-template/README.md
CHANGED
|
@@ -12,30 +12,6 @@ Run `cp .env.example .env && yarn` command at project root and all dependencies
|
|
|
12
12
|
|
|
13
13
|
- `SITEMAP_S3_BUCKET_NAME`: S3 bucket name for XML sitemaps (e.g., "0fb534"). This is required for the sitemap route to function correctly.
|
|
14
14
|
|
|
15
|
-
### Optional Environment Variables
|
|
16
|
-
|
|
17
|
-
- `NEXT_PUBLIC_ENABLE_IMAGE_SEARCH`: Set to `true` to enable image search feature for all users. If not set or `false`, the feature will only be visible to users who have enabled it via localStorage.
|
|
18
|
-
|
|
19
|
-
## Image Search Feature
|
|
20
|
-
|
|
21
|
-
The image search functionality allows users to search for similar products by uploading images or cropping existing product images.
|
|
22
|
-
|
|
23
|
-
### Feature Visibility Control
|
|
24
|
-
|
|
25
|
-
The image search feature can be controlled in two ways:
|
|
26
|
-
|
|
27
|
-
1. **Environment Variable (Global)**: Set `NEXT_PUBLIC_ENABLE_IMAGE_SEARCH=true` to enable for all users
|
|
28
|
-
2. **localStorage (Individual Users)**: Users can enable it locally using browser developer tools
|
|
29
|
-
|
|
30
|
-
````
|
|
31
|
-
|
|
32
|
-
### Feature Locations
|
|
33
|
-
|
|
34
|
-
When enabled, the image search feature appears in:
|
|
35
|
-
|
|
36
|
-
- **Header Search**: Camera icon next to the search input
|
|
37
|
-
- **Product Detail Page**: "View Similar Styles" button on product images
|
|
38
|
-
|
|
39
15
|
### Build
|
|
40
16
|
|
|
41
17
|
To build the app, run the following command:
|
|
@@ -43,7 +19,7 @@ To build the app, run the following command:
|
|
|
43
19
|
```bash
|
|
44
20
|
cd projectzeronext # Project root
|
|
45
21
|
yarn build
|
|
46
|
-
|
|
22
|
+
```
|
|
47
23
|
|
|
48
24
|
### Develop
|
|
49
25
|
|
|
@@ -38,9 +38,6 @@ const nextConfig = {
|
|
|
38
38
|
]
|
|
39
39
|
}
|
|
40
40
|
];
|
|
41
|
-
},
|
|
42
|
-
logging: {
|
|
43
|
-
browserToTerminal: 'error'
|
|
44
41
|
}
|
|
45
42
|
};
|
|
46
43
|
|
|
@@ -53,12 +50,9 @@ const withSerwist = withSerwistInit({
|
|
|
53
50
|
const sentryConfig = {
|
|
54
51
|
silent: true,
|
|
55
52
|
dryRun: !process.env.SENTRY_DSN,
|
|
56
|
-
org: 'akinon'
|
|
53
|
+
org: 'akinon'
|
|
57
54
|
// project: 'enter_your_project_name_here',
|
|
58
55
|
// authToken: 'enter_your_auth_token_here'
|
|
59
|
-
sourcemaps: {
|
|
60
|
-
deleteSourcemapsAfterUpload: true
|
|
61
|
-
}
|
|
62
56
|
};
|
|
63
57
|
|
|
64
58
|
const enhancedConfig = withPzConfig(nextConfig);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "projectzeronext",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.117-beta.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -24,33 +24,33 @@
|
|
|
24
24
|
"test:middleware": "jest middleware-matcher.test.ts --bail"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@akinon/next": "2.0.
|
|
28
|
-
"@akinon/pz-akifast": "2.0.
|
|
29
|
-
"@akinon/pz-apple-pay": "2.0.
|
|
30
|
-
"@akinon/pz-b2b": "2.0.
|
|
31
|
-
"@akinon/pz-basket-gift-pack": "2.0.
|
|
32
|
-
"@akinon/pz-bkm": "2.0.
|
|
33
|
-
"@akinon/pz-checkout-gift-pack": "2.0.
|
|
34
|
-
"@akinon/pz-click-collect": "2.0.
|
|
35
|
-
"@akinon/pz-credit-payment": "2.0.
|
|
36
|
-
"@akinon/pz-cybersource-uc": "2.0.
|
|
37
|
-
"@akinon/pz-flow-payment": "2.0.
|
|
38
|
-
"@akinon/pz-google-pay": "2.0.
|
|
39
|
-
"@akinon/pz-gpay": "2.0.
|
|
40
|
-
"@akinon/pz-haso": "2.0.
|
|
41
|
-
"@akinon/pz-hepsipay": "2.0.
|
|
42
|
-
"@akinon/pz-masterpass": "2.0.
|
|
43
|
-
"@akinon/pz-masterpass-rest": "2.0.
|
|
44
|
-
"@akinon/pz-multi-basket": "2.0.
|
|
45
|
-
"@akinon/pz-one-click-checkout": "2.0.
|
|
46
|
-
"@akinon/pz-otp": "2.0.
|
|
47
|
-
"@akinon/pz-pay-on-delivery": "2.0.
|
|
48
|
-
"@akinon/pz-saved-card": "2.0.
|
|
49
|
-
"@akinon/pz-similar-products": "2.0.
|
|
50
|
-
"@akinon/pz-tabby-extension": "2.0.
|
|
51
|
-
"@akinon/pz-tamara-extension": "2.0.
|
|
52
|
-
"@akinon/pz-theme": "2.0.
|
|
53
|
-
"@akinon/pz-virtual-try-on": "2.0.
|
|
27
|
+
"@akinon/next": "2.0.117-beta.0",
|
|
28
|
+
"@akinon/pz-akifast": "2.0.117-beta.0",
|
|
29
|
+
"@akinon/pz-apple-pay": "2.0.117-beta.0",
|
|
30
|
+
"@akinon/pz-b2b": "2.0.117-beta.0",
|
|
31
|
+
"@akinon/pz-basket-gift-pack": "2.0.117-beta.0",
|
|
32
|
+
"@akinon/pz-bkm": "2.0.117-beta.0",
|
|
33
|
+
"@akinon/pz-checkout-gift-pack": "2.0.117-beta.0",
|
|
34
|
+
"@akinon/pz-click-collect": "2.0.117-beta.0",
|
|
35
|
+
"@akinon/pz-credit-payment": "2.0.117-beta.0",
|
|
36
|
+
"@akinon/pz-cybersource-uc": "2.0.117-beta.0",
|
|
37
|
+
"@akinon/pz-flow-payment": "2.0.117-beta.0",
|
|
38
|
+
"@akinon/pz-google-pay": "2.0.117-beta.0",
|
|
39
|
+
"@akinon/pz-gpay": "2.0.117-beta.0",
|
|
40
|
+
"@akinon/pz-haso": "2.0.117-beta.0",
|
|
41
|
+
"@akinon/pz-hepsipay": "2.0.117-beta.0",
|
|
42
|
+
"@akinon/pz-masterpass": "2.0.117-beta.0",
|
|
43
|
+
"@akinon/pz-masterpass-rest": "2.0.117-beta.0",
|
|
44
|
+
"@akinon/pz-multi-basket": "2.0.117-beta.0",
|
|
45
|
+
"@akinon/pz-one-click-checkout": "2.0.117-beta.0",
|
|
46
|
+
"@akinon/pz-otp": "2.0.117-beta.0",
|
|
47
|
+
"@akinon/pz-pay-on-delivery": "2.0.117-beta.0",
|
|
48
|
+
"@akinon/pz-saved-card": "2.0.117-beta.0",
|
|
49
|
+
"@akinon/pz-similar-products": "2.0.117-beta.0",
|
|
50
|
+
"@akinon/pz-tabby-extension": "2.0.117-beta.0",
|
|
51
|
+
"@akinon/pz-tamara-extension": "2.0.117-beta.0",
|
|
52
|
+
"@akinon/pz-theme": "2.0.117-beta.0",
|
|
53
|
+
"@akinon/pz-virtual-try-on": "2.0.117-beta.0",
|
|
54
54
|
"@hookform/resolvers": "2.9.0",
|
|
55
55
|
"@next/third-parties": "16.2.6",
|
|
56
56
|
"@react-google-maps/api": "2.17.1",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"next": "16.2.6",
|
|
60
60
|
"@serwist/next": "9.5.11",
|
|
61
61
|
"next-auth": "5.0.0-beta.30",
|
|
62
|
-
"pino": "8.
|
|
62
|
+
"pino": "8.11.0",
|
|
63
63
|
"serwist": "9.5.11",
|
|
64
64
|
"postcss": "8.4.49",
|
|
65
65
|
"react": "19.2.5",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"react-google-recaptcha": "2.1.0",
|
|
68
68
|
"react-hook-form": "7.71.2",
|
|
69
69
|
"react-intersection-observer": "9.4.0",
|
|
70
|
-
"react-multi-carousel": "2.8.
|
|
71
|
-
"react-string-replace": "1.1.
|
|
72
|
-
"start-server-and-test": "2.0.
|
|
73
|
-
"tailwind-merge": "1.
|
|
70
|
+
"react-multi-carousel": "2.8.4",
|
|
71
|
+
"react-string-replace": "1.1.0",
|
|
72
|
+
"start-server-and-test": "2.0.3",
|
|
73
|
+
"tailwind-merge": "1.8.0",
|
|
74
74
|
"yup": "0.32.11"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@akinon/eslint-plugin-projectzero": "2.0.
|
|
77
|
+
"@akinon/eslint-plugin-projectzero": "2.0.117-beta.0",
|
|
78
78
|
"@semantic-release/changelog": "6.0.2",
|
|
79
79
|
"@semantic-release/exec": "6.0.3",
|
|
80
80
|
"@semantic-release/git": "10.0.1",
|
|
@@ -89,25 +89,25 @@
|
|
|
89
89
|
"@types/react": "19.2.14",
|
|
90
90
|
"@types/react-dom": "19.2.3",
|
|
91
91
|
"client-only": "0.0.1",
|
|
92
|
-
"clsx": "1.
|
|
92
|
+
"clsx": "1.1.1",
|
|
93
93
|
"currency-symbol-map": "5.1.0",
|
|
94
94
|
"eslint": "9.39.4",
|
|
95
95
|
"eslint-config-next": "16.2.4",
|
|
96
96
|
"eslint-config-prettier": "10.1.1",
|
|
97
97
|
"husky": "8.0.0",
|
|
98
98
|
"jest": "29.7.0",
|
|
99
|
-
"jest-css-modules-transform": "4.
|
|
99
|
+
"jest-css-modules-transform": "4.3.0",
|
|
100
100
|
"jest-environment-jsdom": "29.7.0",
|
|
101
|
-
"lint-staged": "13.
|
|
102
|
-
"prettier": "2.
|
|
101
|
+
"lint-staged": "13.1.0",
|
|
102
|
+
"prettier": "2.6.2",
|
|
103
103
|
"react-number-format": "5.3.4",
|
|
104
|
-
"sass": "1.
|
|
104
|
+
"sass": "1.49.9",
|
|
105
105
|
"semantic-release": "19.0.5",
|
|
106
106
|
"server-only": "0.0.1",
|
|
107
|
-
"stylelint": "14.
|
|
107
|
+
"stylelint": "14.6.0",
|
|
108
108
|
"stylelint-config-sass-guidelines": "9.0.1",
|
|
109
109
|
"stylelint-config-standard": "25.0.0",
|
|
110
|
-
"stylelint-scss": "4.
|
|
110
|
+
"stylelint-scss": "4.2.0",
|
|
111
111
|
"stylelint-selector-bem-pattern": "2.1.1",
|
|
112
112
|
"tailwindcss": "4.2.0",
|
|
113
113
|
"ts-jest": "29.2.6",
|
|
@@ -8,11 +8,9 @@ import {
|
|
|
8
8
|
useGetFavoritesQuery,
|
|
9
9
|
useRemoveFavoriteMutation
|
|
10
10
|
} from '@akinon/next/data/client/wishlist';
|
|
11
|
-
import { Product } from '@akinon/next/types';
|
|
12
11
|
import { Icon } from '@theme/components';
|
|
13
12
|
import { pushAddToWishlist } from '@theme/utils/gtm';
|
|
14
13
|
import { useToast, useLocalization } from '@akinon/next/hooks';
|
|
15
|
-
import { useFavouriteProductIds } from './favourite-product-ids-context';
|
|
16
14
|
|
|
17
15
|
interface FavButtonProps {
|
|
18
16
|
label?: string;
|
|
@@ -23,25 +21,16 @@ interface FavButtonProps {
|
|
|
23
21
|
|
|
24
22
|
const FAV_TOAST_OPTIONS = { position: 'bottom-right' as const }
|
|
25
23
|
|
|
26
|
-
const useFavButton = (
|
|
27
|
-
productPk: number,
|
|
28
|
-
product?: Pick<Product, 'base_code' | 'name' | 'price' | 'currency_type'>
|
|
29
|
-
) => {
|
|
24
|
+
const useFavButton = (productPk: number) => {
|
|
30
25
|
const { status } = useSession();
|
|
31
26
|
const { t } = useLocalization();
|
|
32
27
|
const { success, error: showError } = useToast();
|
|
33
28
|
|
|
34
|
-
// Inside a FavouriteProductIdsProvider (PLP) the favourite state comes from
|
|
35
|
-
// the batched favourite-product-ids request, so the full favourites list is
|
|
36
|
-
// only fetched when that flow is unavailable (no provider, or 404 fallback).
|
|
37
|
-
const favouriteProductIds = useFavouriteProductIds();
|
|
38
|
-
const useBatchFlow = Boolean(favouriteProductIds?.isActive);
|
|
39
|
-
|
|
40
29
|
const { data: favorites } = useGetFavoritesQuery(
|
|
41
30
|
{
|
|
42
31
|
limit: 1000
|
|
43
32
|
},
|
|
44
|
-
{ skip: status !== 'authenticated'
|
|
33
|
+
{ skip: status !== 'authenticated' }
|
|
45
34
|
);
|
|
46
35
|
|
|
47
36
|
const favoriteItem = useMemo(
|
|
@@ -52,11 +41,7 @@ const useFavButton = (
|
|
|
52
41
|
[favorites, productPk]
|
|
53
42
|
);
|
|
54
43
|
|
|
55
|
-
const
|
|
56
|
-
? favouriteProductIds.getFavouriteId(productPk)
|
|
57
|
-
: favoriteItem?.pk;
|
|
58
|
-
|
|
59
|
-
const isActive = favouriteId !== undefined;
|
|
44
|
+
const isActive = Boolean(favoriteItem);
|
|
60
45
|
const [isPushed, setIsPushed] = useState<boolean>(false);
|
|
61
46
|
|
|
62
47
|
const [addFavorite] = useAddFavoriteMutation();
|
|
@@ -64,8 +49,8 @@ const useFavButton = (
|
|
|
64
49
|
|
|
65
50
|
const handleClick = useCallback(async () => {
|
|
66
51
|
try {
|
|
67
|
-
if (
|
|
68
|
-
await removeFavorite(
|
|
52
|
+
if (favoriteItem) {
|
|
53
|
+
await removeFavorite(favoriteItem.pk).unwrap();
|
|
69
54
|
success(t('product.removed_from_favorites'), FAV_TOAST_OPTIONS);
|
|
70
55
|
} else {
|
|
71
56
|
await addFavorite(productPk).unwrap();
|
|
@@ -75,26 +60,19 @@ const useFavButton = (
|
|
|
75
60
|
} catch (err) {
|
|
76
61
|
showError(t('product.favorites_error'), FAV_TOAST_OPTIONS);
|
|
77
62
|
}
|
|
78
|
-
}, [
|
|
63
|
+
}, [favoriteItem, productPk, addFavorite, removeFavorite, success, showError, t]);
|
|
79
64
|
|
|
80
65
|
useEffect(() => {
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
// The batched flow returns ids only, so the analytics payload falls back
|
|
84
|
-
// to the product the card already renders.
|
|
85
|
-
const gtmProduct = favoriteItem?.product ?? product;
|
|
86
|
-
|
|
87
|
-
if (gtmProduct) {
|
|
66
|
+
if (favoriteItem && isPushed) {
|
|
88
67
|
pushAddToWishlist({
|
|
89
|
-
base_code:
|
|
90
|
-
name:
|
|
91
|
-
price:
|
|
92
|
-
currency_type:
|
|
68
|
+
base_code: favoriteItem?.product?.base_code,
|
|
69
|
+
name: favoriteItem?.product?.name,
|
|
70
|
+
price: favoriteItem?.product?.price,
|
|
71
|
+
currency_type: favoriteItem?.product?.currency_type
|
|
93
72
|
});
|
|
73
|
+
setIsPushed(false);
|
|
94
74
|
}
|
|
95
|
-
|
|
96
|
-
setIsPushed(false);
|
|
97
|
-
}, [isActive, favoriteItem, product, isPushed]);
|
|
75
|
+
}, [favoriteItem, isPushed]);
|
|
98
76
|
|
|
99
77
|
const FavButton = useMemo(() => {
|
|
100
78
|
const View = (props: FavButtonProps) => (
|
|
@@ -15,8 +15,7 @@ export const config = {
|
|
|
15
15
|
'/((?!api|_next|[\\w-\\/*]+\\.\\w+).*)',
|
|
16
16
|
'/(.*sitemap\\.xml)',
|
|
17
17
|
'/(.+\\.)(html|htm|aspx|asp|php)',
|
|
18
|
-
'/(.*orders\\/checkout-with-token.*)'
|
|
19
|
-
'/(.*orders\\/post-checkout.*)'
|
|
18
|
+
'/(.*orders\\/checkout-with-token.*)'
|
|
20
19
|
]
|
|
21
20
|
};
|
|
22
21
|
|
|
@@ -11,7 +11,6 @@ import { GetCategoryResponse } from '@akinon/next/types';
|
|
|
11
11
|
import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
|
|
12
12
|
import { setFacets, setMenuOpen } from '@theme/redux/reducers/category';
|
|
13
13
|
import CategoryActiveFilters from '@theme/views/category/category-active-filters';
|
|
14
|
-
import { FavouriteProductIdsProvider } from '@theme/hooks/favourite-product-ids-context';
|
|
15
14
|
import { useLocalization } from '@akinon/next/hooks';
|
|
16
15
|
import { Link, LoaderSpinner } from '@akinon/next/components';
|
|
17
16
|
import { ROUTES } from '@theme/routes';
|
|
@@ -63,11 +62,6 @@ export default function ListPage(props: ListPageProps) {
|
|
|
63
62
|
|
|
64
63
|
const { t } = useLocalization();
|
|
65
64
|
|
|
66
|
-
const productPks = useMemo(
|
|
67
|
-
() => data?.products?.map((product) => product.pk) ?? [],
|
|
68
|
-
[data?.products]
|
|
69
|
-
);
|
|
70
|
-
|
|
71
65
|
useEffect(() => {
|
|
72
66
|
dispatch(setFacets(data.facets));
|
|
73
67
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -111,25 +105,23 @@ export default function ListPage(props: ListPageProps) {
|
|
|
111
105
|
|
|
112
106
|
{data.products?.length === 0 && page > 1 && <LoaderSpinner />}
|
|
113
107
|
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
</div>
|
|
132
|
-
</FavouriteProductIdsProvider>
|
|
108
|
+
<div
|
|
109
|
+
className={clsx('grid gap-x-4 gap-y-12 grid-cols-2', {
|
|
110
|
+
'md:grid-cols-3': layoutSize === 3,
|
|
111
|
+
'lg:grid-cols-2': layoutSize === 2,
|
|
112
|
+
'lg:grid-cols-3': layoutSize === 3
|
|
113
|
+
})}
|
|
114
|
+
>
|
|
115
|
+
{data?.products?.map((product, index) => (
|
|
116
|
+
<ProductItem
|
|
117
|
+
key={product.pk}
|
|
118
|
+
product={product}
|
|
119
|
+
width={itemDimensions.width}
|
|
120
|
+
height={itemDimensions.height}
|
|
121
|
+
index={index}
|
|
122
|
+
/>
|
|
123
|
+
))}
|
|
124
|
+
</div>
|
|
133
125
|
{data?.products?.length > 0 && (
|
|
134
126
|
<Pagination
|
|
135
127
|
total={data.pagination.total_count}
|
|
@@ -4,7 +4,8 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
4
4
|
import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
|
|
5
5
|
import { closeSearch } from '@akinon/next/redux/reducers/header';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import { Icon } from '@theme/components';
|
|
8
9
|
import Results from './results';
|
|
9
10
|
import { ROUTES } from '@theme/routes';
|
|
10
11
|
import { useLocalization, useRouter } from '@akinon/next/hooks';
|
|
@@ -41,14 +42,6 @@ export default function Search() {
|
|
|
41
42
|
};
|
|
42
43
|
}, [isSearchOpen, dispatch]);
|
|
43
44
|
|
|
44
|
-
const handleSearchTextChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
45
|
-
setSearchText(e.target.value);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const handleCloseSearch = () => {
|
|
49
|
-
dispatch(closeSearch());
|
|
50
|
-
};
|
|
51
|
-
|
|
52
45
|
return (
|
|
53
46
|
<>
|
|
54
47
|
<div
|
|
@@ -74,9 +67,9 @@ export default function Search() {
|
|
|
74
67
|
{t('common.search.results_for')}
|
|
75
68
|
</span>
|
|
76
69
|
<div className="flex items-center">
|
|
77
|
-
<
|
|
70
|
+
<input
|
|
78
71
|
value={searchText}
|
|
79
|
-
onChange={
|
|
72
|
+
onChange={(e) => setSearchText(e.target.value)}
|
|
80
73
|
onKeyDown={(e) => {
|
|
81
74
|
if (e.key === 'Enter' && searchText.trim() !== '') {
|
|
82
75
|
router.push(`${ROUTES.LIST}/?search_text=${searchText}`);
|
|
@@ -98,12 +91,11 @@ export default function Search() {
|
|
|
98
91
|
<Icon
|
|
99
92
|
name="close"
|
|
100
93
|
size={14}
|
|
101
|
-
onClick={
|
|
94
|
+
onClick={() => dispatch(closeSearch())}
|
|
102
95
|
className="cursor-pointer"
|
|
103
96
|
/>
|
|
104
97
|
</div>
|
|
105
98
|
</div>
|
|
106
|
-
|
|
107
99
|
<Results searchText={searchText} />
|
|
108
100
|
</div>
|
|
109
101
|
</div>
|
|
@@ -36,100 +36,53 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
|
|
|
36
36
|
carouselRef.current?.next();
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const handleThumbnailClick = (index
|
|
39
|
+
const handleThumbnailClick = (index) => {
|
|
40
40
|
setActiveIndex(index);
|
|
41
41
|
carouselRef.current?.goToSlide(index);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
|
-
|
|
46
|
-
<div className="lg:
|
|
47
|
-
<div className="
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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 }}
|
|
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}
|
|
117
55
|
>
|
|
118
|
-
{
|
|
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) => (
|
|
119
60
|
<Image
|
|
120
|
-
key={
|
|
61
|
+
key={index}
|
|
121
62
|
src={item.image}
|
|
122
|
-
alt={
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
fill
|
|
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)}
|
|
130
70
|
/>
|
|
131
71
|
))}
|
|
132
|
-
</
|
|
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>
|
|
133
86
|
</div>
|
|
134
87
|
</div>
|
|
135
88
|
|
|
@@ -187,6 +140,6 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
|
|
|
187
140
|
))}
|
|
188
141
|
</CarouselCore>
|
|
189
142
|
</div>
|
|
190
|
-
|
|
143
|
+
</div>
|
|
191
144
|
);
|
|
192
145
|
}
|
|
@@ -22,7 +22,7 @@ export const ProductItem = (props: Props) => {
|
|
|
22
22
|
// TODO: Static image will change (TR)
|
|
23
23
|
const { product, width, height, index } = props;
|
|
24
24
|
const [viewed, setViewed] = useState(false);
|
|
25
|
-
const { FavButton } = useFavButton(product.pk
|
|
25
|
+
const { FavButton } = useFavButton(product.pk);
|
|
26
26
|
const { ref, inView } = useInView();
|
|
27
27
|
|
|
28
28
|
const image_url = product.productimage_set[0]?.image;
|
package/commands/plugins.ts
CHANGED
package/dist/commands/plugins.js
CHANGED
|
@@ -183,10 +183,6 @@ 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
|
-
},
|
|
190
186
|
{
|
|
191
187
|
name: 'Hepsipay',
|
|
192
188
|
value: 'pz-hepsipay'
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useSentryUncaughtErrors } from '@akinon/next/hooks';
|
|
4
|
-
|
|
5
|
-
export default function GlobalError({
|
|
6
|
-
error,
|
|
7
|
-
reset
|
|
8
|
-
}: {
|
|
9
|
-
error: Error & { digest?: string };
|
|
10
|
-
reset: () => void;
|
|
11
|
-
}) {
|
|
12
|
-
useSentryUncaughtErrors(error);
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<html>
|
|
16
|
-
<body>
|
|
17
|
-
<h2>Something went wrong!</h2>
|
|
18
|
-
<button onClick={() => reset()}>Try again</button>
|
|
19
|
-
</body>
|
|
20
|
-
</html>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
ReactNode,
|
|
6
|
-
useContext,
|
|
7
|
-
useEffect,
|
|
8
|
-
useMemo,
|
|
9
|
-
useState
|
|
10
|
-
} from 'react';
|
|
11
|
-
import { useSession } from 'next-auth/react';
|
|
12
|
-
import { useGetFavouriteProductIdsQuery } from '@akinon/next/data/client/wishlist';
|
|
13
|
-
import {
|
|
14
|
-
isFavouriteProductIdsSuspended,
|
|
15
|
-
suspendFavouriteProductIds
|
|
16
|
-
} from '@theme/utils/favourite-product-ids-fallback';
|
|
17
|
-
|
|
18
|
-
interface FavouriteProductIdsContextValue {
|
|
19
|
-
// False while the batch flow is unavailable (endpoint 404'd or errored), so
|
|
20
|
-
// consumers can fall back to the legacy favourites-list request.
|
|
21
|
-
isActive: boolean;
|
|
22
|
-
getFavouriteId: (productPk: number) => number | undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const FavouriteProductIdsContext =
|
|
26
|
-
createContext<FavouriteProductIdsContextValue | null>(null);
|
|
27
|
-
|
|
28
|
-
export const useFavouriteProductIds = () =>
|
|
29
|
-
useContext(FavouriteProductIdsContext);
|
|
30
|
-
|
|
31
|
-
type Phase = 'init' | 'batch' | 'fallback';
|
|
32
|
-
|
|
33
|
-
interface FavouriteProductIdsProviderProps {
|
|
34
|
-
productIds: Array<number | string>;
|
|
35
|
-
children: ReactNode;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function FavouriteProductIdsProvider({
|
|
39
|
-
productIds,
|
|
40
|
-
children
|
|
41
|
-
}: FavouriteProductIdsProviderProps) {
|
|
42
|
-
const { status } = useSession();
|
|
43
|
-
|
|
44
|
-
// Storage can only be read on the client, so the first render stays neutral
|
|
45
|
-
// to keep SSR and hydration output identical.
|
|
46
|
-
const [phase, setPhase] = useState<Phase>('init');
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
setPhase(isFavouriteProductIdsSuspended() ? 'fallback' : 'batch');
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
const sortedProductIds = useMemo(() => {
|
|
53
|
-
const unique = Array.from(
|
|
54
|
-
new Set(productIds.map(Number).filter((id) => Number.isFinite(id)))
|
|
55
|
-
);
|
|
56
|
-
// Stable order keeps the RTK Query cache key deterministic for the page.
|
|
57
|
-
return unique.sort((a, b) => a - b);
|
|
58
|
-
}, [productIds]);
|
|
59
|
-
|
|
60
|
-
const { data, error } = useGetFavouriteProductIdsQuery(
|
|
61
|
-
{ productIds: sortedProductIds },
|
|
62
|
-
{
|
|
63
|
-
skip:
|
|
64
|
-
status !== 'authenticated' ||
|
|
65
|
-
phase !== 'batch' ||
|
|
66
|
-
sortedProductIds.length === 0
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (!error) return;
|
|
72
|
-
|
|
73
|
-
if ('status' in error && error.status === 404) {
|
|
74
|
-
suspendFavouriteProductIds();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setPhase('fallback');
|
|
78
|
-
}, [error]);
|
|
79
|
-
|
|
80
|
-
const favouriteIdByProductPk = useMemo(() => {
|
|
81
|
-
const map = new Map<number, number>();
|
|
82
|
-
|
|
83
|
-
data?.favourite_products?.forEach((item) => {
|
|
84
|
-
map.set(Number(item.product_id), item.favourite_id);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return map;
|
|
88
|
-
}, [data]);
|
|
89
|
-
|
|
90
|
-
const value = useMemo<FavouriteProductIdsContextValue>(
|
|
91
|
-
() => ({
|
|
92
|
-
isActive: phase !== 'fallback',
|
|
93
|
-
getFavouriteId: (productPk: number) =>
|
|
94
|
-
favouriteIdByProductPk.get(Number(productPk))
|
|
95
|
-
}),
|
|
96
|
-
[phase, favouriteIdByProductPk]
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<FavouriteProductIdsContext.Provider value={value}>
|
|
101
|
-
{children}
|
|
102
|
-
</FavouriteProductIdsContext.Provider>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS,
|
|
3
|
-
isFavouriteProductIdsSuspended,
|
|
4
|
-
suspendFavouriteProductIds
|
|
5
|
-
} from '../favourite-product-ids-fallback';
|
|
6
|
-
|
|
7
|
-
const STORAGE_KEY = 'pz-favourite-product-ids-unavailable-until';
|
|
8
|
-
|
|
9
|
-
describe('favourite-product-ids-fallback', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
window.localStorage.clear();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('is not suspended by default', () => {
|
|
15
|
-
expect(isFavouriteProductIdsSuspended()).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('suspends after a 404 marker is written', () => {
|
|
19
|
-
suspendFavouriteProductIds();
|
|
20
|
-
|
|
21
|
-
expect(isFavouriteProductIdsSuspended()).toBe(true);
|
|
22
|
-
|
|
23
|
-
const until = Number(window.localStorage.getItem(STORAGE_KEY));
|
|
24
|
-
expect(until).toBeGreaterThan(Date.now());
|
|
25
|
-
expect(until).toBeLessThanOrEqual(
|
|
26
|
-
Date.now() + FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('expires the suspension and clears the marker', () => {
|
|
31
|
-
window.localStorage.setItem(STORAGE_KEY, String(Date.now() - 1000));
|
|
32
|
-
|
|
33
|
-
expect(isFavouriteProductIdsSuspended()).toBe(false);
|
|
34
|
-
expect(window.localStorage.getItem(STORAGE_KEY)).toBeNull();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('treats a corrupt marker as not suspended', () => {
|
|
38
|
-
window.localStorage.setItem(STORAGE_KEY, 'not-a-number');
|
|
39
|
-
|
|
40
|
-
expect(isFavouriteProductIdsSuspended()).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const STORAGE_KEY = 'pz-favourite-product-ids-unavailable-until';
|
|
2
|
-
|
|
3
|
-
// Not every brand's backend ships the favourite-product-ids endpoint at the
|
|
4
|
-
// same time, so a 404 suspends the new flow for this long before probing again.
|
|
5
|
-
export const FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS = 6 * 60 * 60 * 1000;
|
|
6
|
-
|
|
7
|
-
const getStorage = (): Storage | null => {
|
|
8
|
-
try {
|
|
9
|
-
// The property access itself is what throws when storage is blocked, so it
|
|
10
|
-
// has to be inside the try rather than guarded by a typeof check.
|
|
11
|
-
return typeof window === 'undefined' ? null : window.localStorage ?? null;
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Fails open: when storage is unavailable the endpoint is probed again, which
|
|
18
|
-
// at worst costs one extra 404 per page view.
|
|
19
|
-
export const isFavouriteProductIdsSuspended = (): boolean => {
|
|
20
|
-
const storage = getStorage();
|
|
21
|
-
if (!storage) return false;
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
const raw = storage.getItem(STORAGE_KEY);
|
|
25
|
-
if (!raw) return false;
|
|
26
|
-
|
|
27
|
-
const until = Number(raw);
|
|
28
|
-
if (!Number.isFinite(until) || Date.now() >= until) {
|
|
29
|
-
storage.removeItem(STORAGE_KEY);
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const suspendFavouriteProductIds = (): void => {
|
|
40
|
-
const storage = getStorage();
|
|
41
|
-
if (!storage) return;
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
storage.setItem(
|
|
45
|
-
STORAGE_KEY,
|
|
46
|
-
String(Date.now() + FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS)
|
|
47
|
-
);
|
|
48
|
-
} catch {
|
|
49
|
-
// Fail open; see isFavouriteProductIdsSuspended.
|
|
50
|
-
}
|
|
51
|
-
};
|