@faststore/core 3.86.2 → 3.87.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/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +25 -25
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/config.json +3 -3
- package/.next/cache/webpack/client-production/0.pack +0 -0
- package/.next/cache/webpack/client-production/index.pack +0 -0
- package/.next/cache/webpack/server-production/0.pack +0 -0
- package/.next/cache/webpack/server-production/index.pack +0 -0
- package/.next/prerender-manifest.js +1 -1
- package/.next/prerender-manifest.json +1 -1
- package/.next/react-loadable-manifest.json +20 -20
- package/.next/routes-manifest.json +1 -1
- package/.next/server/chunks/3006.js +1 -1
- package/.next/server/chunks/3945.js +1 -1
- package/.next/server/chunks/416.js +1 -1
- package/.next/server/chunks/83.js +1 -1
- package/.next/server/chunks/9563.js +2 -2
- package/.next/server/chunks/9630.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/.next/server/pages/api/graphql.js +2 -2
- package/.next/server/pages/en-US/404.html +1 -1
- package/.next/server/pages/en-US/500.html +1 -1
- package/.next/server/pages/en-US/checkout.html +1 -1
- package/.next/server/pages/en-US/login.html +1 -1
- package/.next/server/pages/en-US/s.html +1 -1
- package/.next/server/pages/en-US.html +1 -1
- package/.next/server/pages-manifest.json +1 -1
- package/.next/static/{OiIHrMTX_CXHqo1-8ncvt → OCdDzXbixjGq2qfKmUzTD}/_buildManifest.js +1 -1
- package/.next/static/chunks/3155.0a1b674bbd087938.js +1 -0
- package/.next/static/chunks/4836.5450b506133e326f.js +1 -0
- package/.next/static/chunks/83.8172f0b21b7683d6.js +1 -0
- package/.next/static/chunks/{9666-9be3f1e484eeb148.js → 9666-1bd33f872ad66b42.js} +1 -1
- package/.next/static/chunks/pages/{_app-02ac96e27a9cbbb4.js → _app-ea99eefec89aef24.js} +1 -1
- package/.next/static/chunks/pages/pvt/account/{orders-10475517a29223cb.js → orders-07d7ced3a4b845b0.js} +1 -1
- package/.next/static/chunks/{webpack-7e1828f4509e6ef7.js → webpack-98c08c89b832fbd2.js} +1 -1
- package/.next/static/css/{6d92375b6ee8276a.css → 37ee6a2c6adab309.css} +1 -1
- package/.next/trace +136 -136
- package/.turbo/turbo-build.log +15 -15
- package/.turbo/turbo-test.log +5 -5
- package/@generated/graphql.ts +3 -3
- package/@generated/schema.graphql +1 -1
- package/CHANGELOG.md +10 -0
- package/cms/faststore/content-types.json +22 -0
- package/package.json +4 -4
- package/src/components/search/Filter/FilterDesktop.tsx +8 -10
- package/src/components/search/Filter/FilterSlider.tsx +9 -10
- package/src/sdk/deliveryPromise/index.ts +3 -0
- package/src/sdk/deliveryPromise/useDeliveryPromise.ts +124 -92
- package/src/utils/globalSettings.ts +5 -0
- package/.next/static/chunks/3155.8ff6efc44151971f.js +0 -1
- package/.next/static/chunks/4836.ef87204971e182f4.js +0 -1
- package/.next/static/chunks/83.730576d7ded8dfe2.js +0 -1
- /package/.next/static/{OiIHrMTX_CXHqo1-8ncvt → OCdDzXbixjGq2qfKmUzTD}/_ssgManifest.js +0 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @faststore/core@3.86.
|
|
2
|
+
> @faststore/core@3.86.4 prebuild /home/runner/work/faststore/faststore/packages/core
|
|
3
3
|
> na run partytown && na run generate
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @faststore/core@3.86.
|
|
6
|
+
> @faststore/core@3.86.4 partytown /home/runner/work/faststore/faststore/packages/core
|
|
7
7
|
> partytown copylib ./public/~partytown
|
|
8
8
|
|
|
9
9
|
Partytown lib copied to: /home/runner/work/faststore/faststore/packages/core/public/~partytown
|
|
10
10
|
|
|
11
|
-
> @faststore/core@3.86.
|
|
11
|
+
> @faststore/core@3.86.4 generate /home/runner/work/faststore/faststore/packages/core
|
|
12
12
|
> na run generate:schema && na run generate:codegen && na run format:generated
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
> @faststore/core@3.86.
|
|
15
|
+
> @faststore/core@3.86.4 generate:schema /home/runner/work/faststore/faststore/packages/core
|
|
16
16
|
> tsx src/server/generator/generateGraphQLSchemaFile.ts
|
|
17
17
|
|
|
18
18
|
Schema GraphQL file generated successfully
|
|
19
19
|
|
|
20
|
-
> @faststore/core@3.86.
|
|
20
|
+
> @faststore/core@3.86.4 generate:codegen /home/runner/work/faststore/faststore/packages/core
|
|
21
21
|
> graphql-codegen
|
|
22
22
|
|
|
23
23
|
[STARTED] Parse Configuration
|
|
@@ -37,11 +37,11 @@ Running lifecycle hook "afterStart" scripts...
|
|
|
37
37
|
[CLI] Loading Documents
|
|
38
38
|
[CLI] Generating output
|
|
39
39
|
|
|
40
|
-
> @faststore/core@3.86.
|
|
40
|
+
> @faststore/core@3.86.4 format:generated /home/runner/work/faststore/faststore/packages/core
|
|
41
41
|
> prettier --write "@generated/**/*.{ts,js,tsx,jsx,json}" --loglevel error
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
> @faststore/core@3.86.
|
|
44
|
+
> @faststore/core@3.86.4 build /home/runner/work/faststore/faststore/packages/core
|
|
45
45
|
> next build
|
|
46
46
|
|
|
47
47
|
⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
|
|
@@ -80,14 +80,14 @@ Route (pages) Size First Load JS
|
|
|
80
80
|
├ ● /[slug]/p 33.5 kB 171 kB
|
|
81
81
|
├ ├ css/6cd282d958f613bc.css 5.9 kB
|
|
82
82
|
├ ├ css/3d7be7043aee15df.css 6.26 kB
|
|
83
|
-
├ └ css/
|
|
83
|
+
├ └ css/37ee6a2c6adab309.css 16.2 kB
|
|
84
84
|
├ ○ /404 1.55 kB 139 kB
|
|
85
85
|
├ ● /500 1.55 kB 139 kB
|
|
86
86
|
├ λ /api/graphql 0 B 107 kB
|
|
87
87
|
├ λ /api/health/live 0 B 107 kB
|
|
88
88
|
├ λ /api/health/ready 0 B 107 kB
|
|
89
89
|
├ λ /api/preview 0 B 107 kB
|
|
90
|
-
├ ● /checkout 737 B
|
|
90
|
+
├ ● /checkout 737 B 139 kB
|
|
91
91
|
├ ● /login 1.68 kB 139 kB
|
|
92
92
|
├ λ /pvt/account 245 B 107 kB
|
|
93
93
|
├ ● /pvt/account/[...unknown] 283 B 107 kB
|
|
@@ -99,18 +99,18 @@ Route (pages) Size First Load JS
|
|
|
99
99
|
├ └ css/b7fc24e8f1eb011f.css 12.8 kB
|
|
100
100
|
├ λ /pvt/account/orders/[id] 12.2 kB 150 kB
|
|
101
101
|
├ └ css/297be4be3be36ff0.css 12.6 kB
|
|
102
|
-
├ λ /pvt/account/profile 1.79 kB
|
|
102
|
+
├ λ /pvt/account/profile 1.79 kB 140 kB
|
|
103
103
|
├ └ css/831a1f72fe4b2d80.css 3.97 kB
|
|
104
|
-
├ λ /pvt/account/security 3.77 kB
|
|
104
|
+
├ λ /pvt/account/security 3.77 kB 142 kB
|
|
105
105
|
├ └ css/ec7fdad03808422d.css 5.22 kB
|
|
106
|
-
├ λ /pvt/account/user-details 1.74 kB
|
|
106
|
+
├ λ /pvt/account/user-details 1.74 kB 140 kB
|
|
107
107
|
├ └ css/e46393a76c5d93a9.css 4.17 kB
|
|
108
108
|
└ ● /s 3.24 kB 156 kB
|
|
109
|
-
+ First Load JS shared by all
|
|
109
|
+
+ First Load JS shared by all 111 kB
|
|
110
110
|
├ chunks/framework-807b0f81cbc129f0.js 45.4 kB
|
|
111
111
|
├ chunks/main-f658704b53a96ab1.js 33.1 kB
|
|
112
|
-
├ chunks/pages/_app-
|
|
113
|
-
├ chunks/webpack-
|
|
112
|
+
├ chunks/pages/_app-ea99eefec89aef24.js 24.9 kB
|
|
113
|
+
├ chunks/webpack-98c08c89b832fbd2.js 3.85 kB
|
|
114
114
|
└ css/24a5e8f6808266fe.css 3.53 kB
|
|
115
115
|
|
|
116
116
|
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
> @faststore/core@3.86.
|
|
2
|
+
> @faststore/core@3.86.4 test /home/runner/work/faststore/faststore/packages/core
|
|
3
3
|
> jest
|
|
4
4
|
|
|
5
|
-
PASS test/server/cms/global.test.ts (
|
|
6
|
-
PASS test/utils/multipleTemplates.test.ts (
|
|
5
|
+
PASS test/server/cms/global.test.ts (27.821 s)
|
|
6
|
+
PASS test/utils/multipleTemplates.test.ts (28.361 s)
|
|
7
7
|
PASS test/server/cms/index.test.ts
|
|
8
|
-
PASS test/server/index.test.ts (31.
|
|
8
|
+
PASS test/server/index.test.ts (31.668 s)
|
|
9
9
|
|
|
10
10
|
Test Suites: 4 passed, 4 total
|
|
11
11
|
Tests: 22 passed, 22 total
|
|
12
12
|
Snapshots: 0 total
|
|
13
|
-
Time: 32.
|
|
13
|
+
Time: 32.928 s
|
|
14
14
|
Ran all test suites.
|
package/@generated/graphql.ts
CHANGED
|
@@ -1300,7 +1300,7 @@ export type StoreFacetValueBoolean = {
|
|
|
1300
1300
|
/** Facet value label. */
|
|
1301
1301
|
label: Scalars['String']['output']
|
|
1302
1302
|
/** Number of items with this facet. */
|
|
1303
|
-
quantity: Scalars['Int']['output']
|
|
1303
|
+
quantity: Maybe<Scalars['Int']['output']>
|
|
1304
1304
|
/** Indicates whether facet is selected. */
|
|
1305
1305
|
selected: Scalars['Boolean']['output']
|
|
1306
1306
|
/** Facet value. */
|
|
@@ -2470,7 +2470,7 @@ type Filter_Facets_StoreFacetBoolean_Fragment = {
|
|
|
2470
2470
|
label: string
|
|
2471
2471
|
value: string
|
|
2472
2472
|
selected: boolean
|
|
2473
|
-
quantity: number
|
|
2473
|
+
quantity: number | null
|
|
2474
2474
|
}>
|
|
2475
2475
|
}
|
|
2476
2476
|
|
|
@@ -3346,7 +3346,7 @@ export type ClientProductGalleryQueryQuery = {
|
|
|
3346
3346
|
label: string
|
|
3347
3347
|
value: string
|
|
3348
3348
|
selected: boolean
|
|
3349
|
-
quantity: number
|
|
3349
|
+
quantity: number | null
|
|
3350
3350
|
}>
|
|
3351
3351
|
}
|
|
3352
3352
|
| {
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.87.0](https://github.com/vtex/faststore/compare/v3.86.4...v3.87.0) (2025-09-18)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- Delivery Promise 2.2 - in stock filter ([#2972](https://github.com/vtex/faststore/issues/2972)) ([7bfb830](https://github.com/vtex/faststore/commit/7bfb8308c76b0914d59875fbe95d3cab6e98eba3))
|
|
11
|
+
|
|
12
|
+
## [3.86.4](https://github.com/vtex/faststore/compare/v3.86.3...v3.86.4) (2025-09-17)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @faststore/core
|
|
15
|
+
|
|
6
16
|
## [3.86.2](https://github.com/vtex/faststore/compare/v3.86.1...v3.86.2) (2025-09-16)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
|
@@ -287,6 +287,28 @@
|
|
|
287
287
|
"default": "Unavailable for pickup"
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
+
},
|
|
291
|
+
"inStock": {
|
|
292
|
+
"title": "PLP/Search Filter: In Stock",
|
|
293
|
+
"type": "object",
|
|
294
|
+
"properties": {
|
|
295
|
+
"enabled": {
|
|
296
|
+
"title": "Should display In Stock filter?",
|
|
297
|
+
"description": "Allow shoppers to filter only products that are currently in stock. Note: When enabling, ensure that the `hideUnavailableItems` property is set to `false` in the store's `discovery.config.js` file.",
|
|
298
|
+
"type": "boolean",
|
|
299
|
+
"default": false
|
|
300
|
+
},
|
|
301
|
+
"title": {
|
|
302
|
+
"title": "In Stock title",
|
|
303
|
+
"type": "string",
|
|
304
|
+
"default": "Availability"
|
|
305
|
+
},
|
|
306
|
+
"label": {
|
|
307
|
+
"title": "In Stock label",
|
|
308
|
+
"type": "string",
|
|
309
|
+
"default": "In-stock only"
|
|
310
|
+
}
|
|
311
|
+
}
|
|
290
312
|
}
|
|
291
313
|
}
|
|
292
314
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.87.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "vtex/faststore",
|
|
6
6
|
"browserslist": "supports es6-module and not dead",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@envelop/graphql-jit": "^8.0.3",
|
|
45
45
|
"@envelop/parser-cache": "^6.0.2",
|
|
46
46
|
"@envelop/validation-cache": "^6.0.2",
|
|
47
|
-
"@faststore/api": "^3.
|
|
47
|
+
"@faststore/api": "^3.87.0",
|
|
48
48
|
"@faststore/graphql-utils": "^3.81.0",
|
|
49
49
|
"@faststore/lighthouse": "^3.81.0",
|
|
50
50
|
"@faststore/sdk": "^3.85.0",
|
|
51
|
-
"@faststore/ui": "^3.
|
|
51
|
+
"@faststore/ui": "^3.87.0",
|
|
52
52
|
"@graphql-codegen/cli": "5.0.2",
|
|
53
53
|
"@graphql-codegen/client-preset": "4.2.6",
|
|
54
54
|
"@graphql-codegen/typescript": "4.0.7",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"ts-jest": "29.1.1",
|
|
109
109
|
"typescript": "5.3.2"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "d0fb33b01f02c4b6a49c31aef3dde512f4ba53ae"
|
|
112
112
|
}
|
|
@@ -18,7 +18,9 @@ import type { useFilter } from 'src/sdk/search/useFilter'
|
|
|
18
18
|
import type { FilterSliderProps } from './FilterSlider'
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
|
+
DELIVERY_OPTIONS_FACET_KEY,
|
|
21
22
|
PICKUP_ALL_FACET_VALUE,
|
|
23
|
+
SHIPPING_FACET_KEY,
|
|
22
24
|
useDeliveryPromise,
|
|
23
25
|
} from 'src/sdk/deliveryPromise'
|
|
24
26
|
import { getGlobalSettings } from 'src/utils/globalSettings'
|
|
@@ -47,8 +49,7 @@ function FilterDesktop({
|
|
|
47
49
|
const { openRegionSlider } = useUI()
|
|
48
50
|
const {
|
|
49
51
|
facets: filteredFacets,
|
|
50
|
-
|
|
51
|
-
deliveryOptionsLabel,
|
|
52
|
+
labelsMap,
|
|
52
53
|
isPickupAllEnabled,
|
|
53
54
|
shouldDisplayDeliveryButton,
|
|
54
55
|
onDeliveryFacetChange,
|
|
@@ -74,7 +75,7 @@ function FilterDesktop({
|
|
|
74
75
|
testId={testId}
|
|
75
76
|
index={0}
|
|
76
77
|
type=""
|
|
77
|
-
label={
|
|
78
|
+
label={labelsMap[SHIPPING_FACET_KEY] ?? 'Delivery'}
|
|
78
79
|
description={deliveryPromiseSettings?.deliveryMethods?.description}
|
|
79
80
|
>
|
|
80
81
|
<UIButton
|
|
@@ -93,14 +94,11 @@ function FilterDesktop({
|
|
|
93
94
|
const index = shouldDisplayDeliveryButton ? idx + 1 : idx
|
|
94
95
|
const { __typename: type, label } = facet
|
|
95
96
|
const isExpanded = expanded.has(index)
|
|
96
|
-
const isDeliveryMethodFacet = facet.key ===
|
|
97
|
-
const isDeliveryOptionFacet = facet.key ===
|
|
97
|
+
const isDeliveryMethodFacet = facet.key === SHIPPING_FACET_KEY
|
|
98
|
+
const isDeliveryOptionFacet = facet.key === DELIVERY_OPTIONS_FACET_KEY
|
|
98
99
|
|
|
99
|
-
const sectionLabel =
|
|
100
|
-
|
|
101
|
-
: isDeliveryOptionFacet
|
|
102
|
-
? deliveryOptionsLabel
|
|
103
|
-
: label
|
|
100
|
+
const sectionLabel =
|
|
101
|
+
labelsMap[facet.key as keyof typeof labelsMap] ?? label
|
|
104
102
|
|
|
105
103
|
return (
|
|
106
104
|
<UIFilterFacets
|
|
@@ -18,7 +18,9 @@ import type { Filter_FacetsFragment } from '@generated/graphql'
|
|
|
18
18
|
import FilterDeliveryMethodFacet from './FilterDeliveryMethodFacet'
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
|
+
DELIVERY_OPTIONS_FACET_KEY,
|
|
21
22
|
PICKUP_ALL_FACET_VALUE,
|
|
23
|
+
SHIPPING_FACET_KEY,
|
|
22
24
|
useDeliveryPromise,
|
|
23
25
|
} from 'src/sdk/deliveryPromise'
|
|
24
26
|
import type { useFilter } from 'src/sdk/search/useFilter'
|
|
@@ -102,8 +104,7 @@ function FilterSlider({
|
|
|
102
104
|
|
|
103
105
|
const {
|
|
104
106
|
facets: filteredFacets,
|
|
105
|
-
|
|
106
|
-
deliveryOptionsLabel,
|
|
107
|
+
labelsMap,
|
|
107
108
|
isPickupAllEnabled,
|
|
108
109
|
shouldDisplayDeliveryButton,
|
|
109
110
|
onDeliveryFacetChange,
|
|
@@ -169,7 +170,7 @@ function FilterSlider({
|
|
|
169
170
|
testId={testId}
|
|
170
171
|
index={0}
|
|
171
172
|
type=""
|
|
172
|
-
label={
|
|
173
|
+
label={labelsMap[SHIPPING_FACET_KEY] ?? 'Delivery'}
|
|
173
174
|
description={
|
|
174
175
|
deliveryPromiseSettings?.deliveryMethods?.description
|
|
175
176
|
}
|
|
@@ -190,14 +191,12 @@ function FilterSlider({
|
|
|
190
191
|
const index = shouldDisplayDeliveryButton ? idx + 1 : idx
|
|
191
192
|
const { __typename: type, label } = facet
|
|
192
193
|
const isExpanded = expanded.has(index)
|
|
193
|
-
const isDeliveryMethodFacet = facet.key ===
|
|
194
|
-
const isDeliveryOptionFacet =
|
|
194
|
+
const isDeliveryMethodFacet = facet.key === SHIPPING_FACET_KEY
|
|
195
|
+
const isDeliveryOptionFacet =
|
|
196
|
+
facet.key === DELIVERY_OPTIONS_FACET_KEY
|
|
195
197
|
|
|
196
|
-
const sectionLabel =
|
|
197
|
-
|
|
198
|
-
: isDeliveryOptionFacet
|
|
199
|
-
? deliveryOptionsLabel
|
|
200
|
-
: label
|
|
198
|
+
const sectionLabel =
|
|
199
|
+
labelsMap[facet.key as keyof typeof labelsMap] ?? label
|
|
201
200
|
|
|
202
201
|
return (
|
|
203
202
|
<UIFilterFacets
|
|
@@ -14,9 +14,10 @@ import type {
|
|
|
14
14
|
} from '@generated/graphql'
|
|
15
15
|
|
|
16
16
|
import type { useFilter } from 'src/sdk/search/useFilter'
|
|
17
|
-
import { useSession } from 'src/sdk/session'
|
|
18
17
|
import type { GlobalCmsData } from 'src/utils/globalSettings'
|
|
19
18
|
|
|
19
|
+
import { useSession } from 'src/sdk/session'
|
|
20
|
+
|
|
20
21
|
import { deliveryPromise as deliveryPromiseConfig } from 'discovery.config'
|
|
21
22
|
import {
|
|
22
23
|
initialPickupPointsSimulation,
|
|
@@ -32,6 +33,7 @@ export const PICKUP_ALL_FACET_VALUE = 'pickup-all' as const
|
|
|
32
33
|
export const ALL_DELIVERY_OPTIONS_FACET_VALUE = 'all-delivery-options' as const
|
|
33
34
|
export const DELIVERY_OPTIONS_FACET_KEY = 'delivery-options' as const
|
|
34
35
|
export const DYNAMIC_ESTIMATE_FACET_KEY = 'dynamic-estimate' as const
|
|
36
|
+
export const IN_STOCK_FACET_KEY = 'in-stock' as const
|
|
35
37
|
|
|
36
38
|
type Facet = SearchState['selectedFacets'][number]
|
|
37
39
|
type DeliveryType = 'delivery' | 'pickup-in-point'
|
|
@@ -116,6 +118,7 @@ export function useDeliveryPromise({
|
|
|
116
118
|
const isDeliveryPromiseEnabled = deliveryPromiseConfig.enabled
|
|
117
119
|
const isDeliveryOptionsEnabled =
|
|
118
120
|
deliveryPromiseSettings?.deliveryOptions?.enabled ?? true
|
|
121
|
+
const isInStockEnabled = deliveryPromiseSettings?.inStock?.enabled ?? false
|
|
119
122
|
|
|
120
123
|
const selectedFacets = useMemo(
|
|
121
124
|
() => selectedFilterFacets ?? searchState.selectedFacets,
|
|
@@ -210,6 +213,25 @@ export function useDeliveryPromise({
|
|
|
210
213
|
[defaultPickupPoint, selectedFacets]
|
|
211
214
|
)
|
|
212
215
|
|
|
216
|
+
const inStockFacet = useMemo(
|
|
217
|
+
(): Filter_FacetsFragment => ({
|
|
218
|
+
key: IN_STOCK_FACET_KEY,
|
|
219
|
+
label: IN_STOCK_FACET_KEY,
|
|
220
|
+
__typename: 'StoreFacetBoolean',
|
|
221
|
+
values: [
|
|
222
|
+
{
|
|
223
|
+
value: 'true',
|
|
224
|
+
label: deliveryPromiseSettings?.inStock?.label ?? 'In-stock only',
|
|
225
|
+
selected: selectedFacets.some(
|
|
226
|
+
({ key, value }) => key === IN_STOCK_FACET_KEY && value === 'true'
|
|
227
|
+
),
|
|
228
|
+
quantity: null,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
}),
|
|
232
|
+
[deliveryPromiseSettings, selectedFacets]
|
|
233
|
+
)
|
|
234
|
+
|
|
213
235
|
const [allDeliveryMethodsFacet, allDeliveryOptionsFacet] = useMemo(
|
|
214
236
|
() => [
|
|
215
237
|
{
|
|
@@ -300,101 +322,105 @@ export function useDeliveryPromise({
|
|
|
300
322
|
const facets = useMemo(() => {
|
|
301
323
|
if (!allFacets) return []
|
|
302
324
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
.filter(({ key }) => key !== DYNAMIC_ESTIMATE_FACET_KEY) // TODO: remove this filter when dynamic estimate is implemented
|
|
312
|
-
.filter(({ key }) => {
|
|
313
|
-
if (
|
|
314
|
-
!isDeliveryOptionsEnabled &&
|
|
315
|
-
key === DELIVERY_OPTIONS_FACET_KEY
|
|
316
|
-
) {
|
|
317
|
-
return false
|
|
318
|
-
}
|
|
325
|
+
if (!isDeliveryPromiseEnabled || !postalCode) {
|
|
326
|
+
return allFacets.filter(
|
|
327
|
+
({ key }) =>
|
|
328
|
+
key !== SHIPPING_FACET_KEY &&
|
|
329
|
+
key !== DELIVERY_OPTIONS_FACET_KEY &&
|
|
330
|
+
key !== DYNAMIC_ESTIMATE_FACET_KEY
|
|
331
|
+
)
|
|
332
|
+
}
|
|
319
333
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
334
|
+
const filteredFacets = allFacets
|
|
335
|
+
.filter(({ key }) => key !== DYNAMIC_ESTIMATE_FACET_KEY) // TODO: remove this filter when dynamic estimate is implemented
|
|
336
|
+
.filter(({ key }) => {
|
|
337
|
+
if (!isDeliveryOptionsEnabled && key === DELIVERY_OPTIONS_FACET_KEY) {
|
|
338
|
+
return false
|
|
339
|
+
}
|
|
324
340
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
facet.values,
|
|
328
|
-
allDeliveryOptionsFacet
|
|
329
|
-
)
|
|
341
|
+
return true
|
|
342
|
+
})
|
|
330
343
|
|
|
331
|
-
|
|
332
|
-
|
|
344
|
+
if (
|
|
345
|
+
isInStockEnabled &&
|
|
346
|
+
!filteredFacets.find(({ key }) => key === IN_STOCK_FACET_KEY) &&
|
|
347
|
+
filteredFacets.find(({ key }) => key === SHIPPING_FACET_KEY) // Avoid adding in-stock facet if IS doesn't return any shipping facet
|
|
348
|
+
) {
|
|
349
|
+
filteredFacets.push(inStockFacet)
|
|
350
|
+
}
|
|
333
351
|
|
|
334
|
-
|
|
352
|
+
return filteredFacets
|
|
353
|
+
.map((facet) => {
|
|
354
|
+
if (facet.__typename !== 'StoreFacetBoolean') return facet
|
|
335
355
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
allDeliveryMethodsFacet
|
|
339
|
-
)
|
|
340
|
-
const pickupInPointFacetIndex = facet.values.findIndex(
|
|
341
|
-
(item) => item?.value === PICKUP_IN_POINT_FACET_VALUE
|
|
342
|
-
)
|
|
356
|
+
if (facet.key === DELIVERY_OPTIONS_FACET_KEY) {
|
|
357
|
+
facet.values = withUniqueFacet(facet.values, allDeliveryOptionsFacet)
|
|
343
358
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
value === PICKUP_IN_POINT_FACET_VALUE ||
|
|
354
|
-
key === PICKUP_POINT_FACET_KEY
|
|
355
|
-
)
|
|
356
|
-
|
|
357
|
-
selectedPickupInPointFacets.length
|
|
358
|
-
? onDeliveryFacetChange({
|
|
359
|
-
facets: selectedPickupInPointFacets,
|
|
360
|
-
})
|
|
361
|
-
: onDeliveryFacetChange({ facet: selectedShippingFacet })
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Removes pickupInPointIndex from array
|
|
365
|
-
facet.values = facet.values.filter(
|
|
366
|
-
(_, index) => index !== pickupInPointFacetIndex
|
|
367
|
-
)
|
|
368
|
-
}
|
|
369
|
-
// Prevent multiple `pickup in point` facet
|
|
370
|
-
else if (pickupInPointFacetIndex === -1 && defaultPickupPoint) {
|
|
371
|
-
facet.values.push(pickupInPointFacet)
|
|
372
|
-
}
|
|
373
|
-
// Replace current `pickup-in-point` facet with the updated one
|
|
374
|
-
else if (
|
|
375
|
-
facet.values[pickupInPointFacetIndex] &&
|
|
376
|
-
facet.values[pickupInPointFacetIndex]?.label !==
|
|
377
|
-
pickupInPointFacet.label
|
|
378
|
-
) {
|
|
379
|
-
facet.values[pickupInPointFacetIndex] = pickupInPointFacet
|
|
380
|
-
}
|
|
359
|
+
return facet
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (facet.key !== SHIPPING_FACET_KEY) return facet
|
|
363
|
+
|
|
364
|
+
facet.values = withUniqueFacet(facet.values, allDeliveryMethodsFacet)
|
|
365
|
+
const pickupInPointFacetIndex = facet.values.findIndex(
|
|
366
|
+
(item) => item?.value === PICKUP_IN_POINT_FACET_VALUE
|
|
367
|
+
)
|
|
381
368
|
|
|
382
|
-
|
|
383
|
-
|
|
369
|
+
// Remove old pickup `pickup in point` facet from list and search state
|
|
370
|
+
if (pickupInPointFacetIndex !== -1 && !defaultPickupPoint) {
|
|
371
|
+
const selectedShippingFacet = selectedFacets.find(
|
|
372
|
+
({ key }) => key === SHIPPING_FACET_KEY
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
if (selectedShippingFacet) {
|
|
376
|
+
const selectedPickupInPointFacets = selectedFacets.filter(
|
|
377
|
+
({ key, value }) =>
|
|
378
|
+
value === PICKUP_IN_POINT_FACET_VALUE ||
|
|
379
|
+
key === PICKUP_POINT_FACET_KEY
|
|
384
380
|
)
|
|
385
381
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
382
|
+
selectedPickupInPointFacets.length
|
|
383
|
+
? onDeliveryFacetChange({
|
|
384
|
+
facets: selectedPickupInPointFacets,
|
|
385
|
+
})
|
|
386
|
+
: onDeliveryFacetChange({ facet: selectedShippingFacet })
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Removes pickupInPointIndex from array
|
|
390
|
+
facet.values = facet.values.filter(
|
|
391
|
+
(_, index) => index !== pickupInPointFacetIndex
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
// Prevent multiple `pickup in point` facet
|
|
395
|
+
else if (pickupInPointFacetIndex === -1 && defaultPickupPoint) {
|
|
396
|
+
facet.values.push(pickupInPointFacet)
|
|
397
|
+
}
|
|
398
|
+
// Replace current `pickup-in-point` facet with the updated one
|
|
399
|
+
else if (
|
|
400
|
+
facet.values[pickupInPointFacetIndex] &&
|
|
401
|
+
facet.values[pickupInPointFacetIndex]?.label !==
|
|
402
|
+
pickupInPointFacet.label
|
|
403
|
+
) {
|
|
404
|
+
facet.values[pickupInPointFacetIndex] = pickupInPointFacet
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
facet.values = facet.values.sort((a, b) =>
|
|
408
|
+
(a.value ?? '').localeCompare(b.value ?? '')
|
|
409
|
+
)
|
|
395
410
|
|
|
396
|
-
|
|
397
|
-
|
|
411
|
+
return facet
|
|
412
|
+
})
|
|
413
|
+
.sort((a, b) => {
|
|
414
|
+
// Define priority order: shipping (0), delivery-options (1), in-stock (2), others (3)
|
|
415
|
+
const getPriority = (key: string) => {
|
|
416
|
+
if (key === SHIPPING_FACET_KEY) return 0
|
|
417
|
+
if (key === DELIVERY_OPTIONS_FACET_KEY) return 1
|
|
418
|
+
if (key === IN_STOCK_FACET_KEY) return 2
|
|
419
|
+
return 3
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return getPriority(a.key) - getPriority(b.key)
|
|
423
|
+
})
|
|
398
424
|
}, [
|
|
399
425
|
allDeliveryMethodsFacet,
|
|
400
426
|
pickupInPointFacet,
|
|
@@ -441,6 +467,15 @@ export function useDeliveryPromise({
|
|
|
441
467
|
[]
|
|
442
468
|
)
|
|
443
469
|
|
|
470
|
+
const labelsMap = {
|
|
471
|
+
[SHIPPING_FACET_KEY]:
|
|
472
|
+
deliveryPromiseSettings?.deliveryMethods?.title ?? 'Delivery',
|
|
473
|
+
[DELIVERY_OPTIONS_FACET_KEY]:
|
|
474
|
+
deliveryPromiseSettings?.deliveryOptions?.title ?? 'Delivery Option',
|
|
475
|
+
[IN_STOCK_FACET_KEY]:
|
|
476
|
+
deliveryPromiseSettings?.inStock?.title ?? 'Availability',
|
|
477
|
+
}
|
|
478
|
+
|
|
444
479
|
function getBadgeLabel(value: DeliveryType, isAvailable: boolean) {
|
|
445
480
|
const labelMap: Record<
|
|
446
481
|
DeliveryType,
|
|
@@ -539,10 +574,7 @@ export function useDeliveryPromise({
|
|
|
539
574
|
facets,
|
|
540
575
|
onPostalCodeChange,
|
|
541
576
|
onDeliveryFacetChange,
|
|
542
|
-
|
|
543
|
-
deliveryPromiseSettings?.deliveryMethods?.title ?? 'Delivery',
|
|
544
|
-
deliveryOptionsLabel:
|
|
545
|
-
deliveryPromiseSettings?.deliveryOptions?.title ?? 'Delivery Option',
|
|
577
|
+
labelsMap,
|
|
546
578
|
isPickupAllEnabled:
|
|
547
579
|
pickupPoints?.length > 0 &&
|
|
548
580
|
(deliveryPromiseSettings?.deliveryMethods?.pickupAll?.enabled ?? false),
|
|
@@ -552,12 +584,12 @@ export function useDeliveryPromise({
|
|
|
552
584
|
}
|
|
553
585
|
}
|
|
554
586
|
|
|
555
|
-
type
|
|
587
|
+
type BooleanFacet = Extract<
|
|
556
588
|
Filter_FacetsFragment,
|
|
557
589
|
{ __typename: 'StoreFacetBoolean' }
|
|
558
590
|
>['values'][number]
|
|
559
591
|
|
|
560
|
-
function withUniqueFacet(facets: Array<
|
|
592
|
+
function withUniqueFacet(facets: Array<BooleanFacet>, facet: BooleanFacet) {
|
|
561
593
|
return [facet, ...facets.filter((item) => item.value !== facet.value)]
|
|
562
594
|
}
|
|
563
595
|
|