@faststore/core 3.66.0 → 3.68.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 +74 -74
- 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 +87 -72
- package/.next/routes-manifest.json +1 -1
- package/.next/server/chunks/1333.js +1 -0
- package/.next/server/chunks/2778.js +2 -2
- package/.next/server/chunks/2792.js +1 -1
- package/.next/server/chunks/3006.js +1 -1
- package/.next/server/chunks/3836.js +1 -1
- package/.next/server/chunks/3918.js +1 -1
- package/.next/server/chunks/3963.js +1 -1
- package/.next/server/chunks/6789.js +1 -1
- package/.next/server/chunks/7178.js +1 -1
- package/.next/server/chunks/7228.js +1 -1
- package/.next/server/chunks/7794.js +1 -1
- package/.next/server/chunks/83.js +1 -1
- package/.next/server/chunks/831.js +1 -1
- package/.next/server/chunks/839.js +1 -0
- package/.next/server/chunks/8569.js +1 -1
- package/.next/server/chunks/8687.js +1 -1
- package/.next/server/chunks/948.js +2 -2
- package/.next/server/chunks/9563.js +2 -2
- package/.next/server/chunks/9630.js +4 -4
- package/.next/server/chunks/UIBannerText.js +1 -1
- package/.next/server/functions-config-manifest.json +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/404.js +1 -1
- package/.next/server/pages/404.js.nft.json +1 -1
- package/.next/server/pages/500.js +1 -1
- package/.next/server/pages/500.js.nft.json +1 -1
- package/.next/server/pages/[...slug].js +1 -1
- package/.next/server/pages/[...slug].js.nft.json +1 -1
- package/.next/server/pages/[slug]/p.js +1 -1
- package/.next/server/pages/[slug]/p.js.nft.json +1 -1
- package/.next/server/pages/_app.js.nft.json +1 -1
- package/.next/server/pages/_document.js.nft.json +1 -1
- package/.next/server/pages/_error.js.nft.json +1 -1
- package/.next/server/pages/account/403.js +1 -1
- package/.next/server/pages/account/403.js.nft.json +1 -1
- package/.next/server/pages/account/404.js +1 -1
- package/.next/server/pages/account/404.js.nft.json +1 -1
- package/.next/server/pages/account/[...unknown].js.nft.json +1 -1
- package/.next/server/pages/account/orders/[id].js +1 -1
- package/.next/server/pages/account/orders/[id].js.nft.json +1 -1
- package/.next/server/pages/account/orders.js +1 -1
- package/.next/server/pages/account/orders.js.nft.json +1 -1
- package/.next/server/pages/account/profile.js +1 -1
- package/.next/server/pages/account/profile.js.nft.json +1 -1
- package/.next/server/pages/account/security.js +1 -1
- package/.next/server/pages/account/security.js.nft.json +1 -1
- package/.next/server/pages/account/user-details.js +1 -1
- package/.next/server/pages/account/user-details.js.nft.json +1 -1
- package/.next/server/pages/account.js.nft.json +1 -1
- package/.next/server/pages/api/graphql.js +2 -2
- package/.next/server/pages/api/graphql.js.nft.json +1 -1
- package/.next/server/pages/api/health/live.js.nft.json +1 -1
- package/.next/server/pages/api/health/ready.js.nft.json +1 -1
- package/.next/server/pages/api/preview.js +1 -1
- package/.next/server/pages/api/preview.js.nft.json +1 -1
- package/.next/server/pages/checkout.js +1 -1
- package/.next/server/pages/checkout.js.nft.json +1 -1
- 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/index.js +1 -1
- package/.next/server/pages/index.js.nft.json +1 -1
- package/.next/server/pages/login.js +1 -1
- package/.next/server/pages/login.js.nft.json +1 -1
- package/.next/server/pages/s.js +1 -1
- package/.next/server/pages/s.js.nft.json +1 -1
- package/.next/server/pages-manifest.json +1 -1
- package/.next/static/chunks/2284.6dd050e60172189a.js +1 -0
- package/.next/static/chunks/3155.243c7558a71f0695.js +1 -0
- package/.next/static/chunks/3166-6af5e854c2f2913a.js +1 -0
- package/.next/static/chunks/3399.93804fb74f79436c.js +1 -0
- package/.next/static/chunks/353.7f2181843462717d.js +1 -0
- package/.next/static/chunks/4803.412bf2a7e15626a6.js +1 -0
- package/.next/static/chunks/5781.28d03feacead66ad.js +1 -0
- package/.next/static/chunks/6355.57d1a07f50ee6cc9.js +1 -0
- package/.next/static/chunks/{6393.361c44eb0818eb7e.js → 6393.53e9ea4f29d1bf23.js} +1 -1
- package/.next/static/chunks/6700.f046aa86e2c83b53.js +1 -0
- package/.next/static/chunks/6857.b2c06171638955ea.js +1 -0
- package/.next/static/chunks/7191-9bdd5f0c18fbd942.js +1 -0
- package/.next/static/chunks/{6410.bd3fa399df59cc80.js → 7351.e90a4cc21797c136.js} +1 -1
- package/.next/static/chunks/7481.3c4ad3642e346232.js +1 -0
- package/.next/static/chunks/7498-0dc4f9a9ed199d3a.js +1 -0
- package/.next/static/chunks/83.ee1fdbe283ac65b6.js +1 -0
- package/.next/static/chunks/9173-88b7ddf38554a5cf.js +1 -0
- package/.next/static/chunks/BannerNewsletter.a9ea51c53885c80f.js +1 -0
- package/.next/static/chunks/{BannerText.695d4d4b6a3f7309.js → BannerText.21f106b180339df1.js} +1 -1
- package/.next/static/chunks/CartSidebar.55cc31a37ffa6ee6.js +1 -0
- package/.next/static/chunks/{Footer.5ed205d931401110.js → Footer.09dddd47ce6c816f.js} +1 -1
- package/.next/static/chunks/Newsletter.2c79d1813e9f9c95.js +1 -0
- package/.next/static/chunks/ProductShelf.299d0989eea49a79.js +1 -0
- package/.next/static/chunks/ProductTiles.ab99b919f3c0215f.js +1 -0
- package/.next/static/chunks/RegionModal.503f063f2e19b936.js +1 -0
- package/.next/static/chunks/RegionSlider.00de4571775d04cc.js +1 -0
- package/.next/static/chunks/Toast.75a18f47eb23b703.js +1 -0
- package/.next/static/chunks/UIBannerText.f4167ceafb96cf67.js +1 -0
- package/.next/static/chunks/UISKUMatrixSidebar.8b6fac58c48f999c.js +1 -0
- package/.next/static/chunks/UIToast.a49584c87d3adc17.js +1 -0
- package/.next/static/chunks/pages/{404-3582ed9196afdf1e.js → 404-dca50618ea3e6fb6.js} +1 -1
- package/.next/static/chunks/pages/{500-1b4eca062588da7f.js → 500-ae6697c7631fb07a.js} +1 -1
- package/.next/static/chunks/pages/[...slug]-debd8b208a0e3d02.js +1 -0
- package/.next/static/chunks/pages/[slug]/p-d782ecb21200f200.js +1 -0
- package/.next/static/chunks/pages/_app-728289774860e9d9.js +1 -0
- package/.next/static/chunks/pages/account/{403-c791997011f970b6.js → 403-a3d8b31b4e9ee8a6.js} +1 -1
- package/.next/static/chunks/pages/account/{404-74e64bb12e8f5a68.js → 404-22b789f04fcdce39.js} +1 -1
- package/.next/static/chunks/pages/account/orders/[id]-a2f44ba3963b81cd.js +1 -0
- package/.next/static/chunks/pages/account/orders-ec040e06c4b516d0.js +1 -0
- package/.next/static/chunks/pages/account/profile-29f93f4c5a55bd87.js +1 -0
- package/.next/static/chunks/pages/account/security-94874fc477520f74.js +1 -0
- package/.next/static/chunks/pages/account/{user-details-6f9fe72e02f5c5df.js → user-details-143cb45d5080d1d9.js} +1 -1
- package/.next/static/chunks/pages/checkout-b0637ee59b1cdca8.js +1 -0
- package/.next/static/chunks/pages/index-b45c9535696b5ab1.js +1 -0
- package/.next/static/chunks/pages/login-bae3a4cdaaed110c.js +1 -0
- package/.next/static/chunks/pages/s-011eedb19dcdccc6.js +1 -0
- package/.next/static/chunks/webpack-8b6c086380cf1398.js +1 -0
- package/.next/static/css/{74e963fcd3434141.css → 118f0b6523312556.css} +1 -1
- package/.next/static/css/{e4b714970415f2eb.css → 2a4b7072e47636f1.css} +1 -1
- package/.next/static/css/{8a3f440e0ff9cd8e.css → 3d41485722b4e3f5.css} +1 -1
- package/.next/static/css/{2841bab51b99dd53.css → 92960607d6088082.css} +1 -1
- package/.next/static/css/d26cb0a54378b3d9.css +1 -0
- package/.next/static/css/f93cf36b16950027.css +1 -0
- package/.next/static/pRYrZEXsDEpvxbtvEobPH/_buildManifest.js +1 -0
- package/.next/trace +135 -132
- package/.turbo/turbo-build.log +36 -33
- package/.turbo/turbo-test.log +5 -5
- package/@generated/gql.ts +8 -0
- package/@generated/graphql.ts +83 -0
- package/@generated/persisted-documents.json +1 -0
- package/@generated/schema.graphql +51 -0
- package/CHANGELOG.md +12 -0
- package/cms/faststore/content-types.json +238 -1
- package/cms/faststore/sections.json +34 -33
- package/cypress/integration/plp.test.js +2 -2
- package/index.ts +9 -0
- package/package.json +6 -6
- package/src/components/cms/GlobalSections.tsx +1 -0
- package/src/components/cms/RenderSections.tsx +8 -4
- package/src/components/cms/global/Components.ts +8 -0
- package/src/components/common/PreviewTag/section.module.scss +2 -2
- package/src/components/navigation/Navbar/Navbar.tsx +5 -6
- package/src/components/navigation/NavbarLinks/NavbarLinks.tsx +23 -4
- package/src/components/region/RegionBar/RegionBar.tsx +48 -12
- package/src/components/region/RegionFilterButton/RegionFilterButton.tsx +57 -0
- package/src/components/region/RegionFilterButton/index.ts +1 -0
- package/src/components/region/RegionModal/RegionModal.tsx +26 -16
- package/src/components/region/RegionModal/useRegion.ts +12 -11
- package/src/components/region/RegionPopover/RegionPopover.tsx +37 -22
- package/src/components/region/RegionSlider/RegionSlider.tsx +407 -0
- package/src/components/region/RegionSlider/index.ts +1 -0
- package/src/components/region/RegionSlider/section.module.scss +72 -0
- package/src/components/search/Filter/FilterDeliveryMethodFacet.tsx +68 -0
- package/src/components/search/Filter/FilterDesktop.tsx +148 -90
- package/src/components/search/Filter/FilterSlider.tsx +193 -104
- package/src/components/search/Filter/section.module.scss +2 -0
- package/src/components/sections/ProductGallery/section.module.scss +2 -0
- package/src/components/sections/RegionBar/DefaultComponents.ts +1 -0
- package/src/components/sections/RegionBar/RegionBar.tsx +2 -1
- package/src/components/templates/LandingPage/LandingPage.tsx +6 -3
- package/src/components/templates/ProductListingPage/ProductListing.tsx +4 -1
- package/src/components/templates/ProductListingPage/ProductListingPage.tsx +3 -0
- package/src/components/templates/SearchPage/SearchPage.tsx +3 -0
- package/src/components/templates/SearchPage/SearchWrapper.tsx +15 -7
- package/src/components/ui/PickupPoints/PickupPointCard.tsx +39 -0
- package/src/components/ui/PickupPoints/PickupPointCards.tsx +102 -0
- package/src/components/ui/PickupPoints/index.ts +5 -0
- package/src/components/ui/ProductGallery/ProductGallery.tsx +6 -9
- package/src/experimental/index.ts +6 -0
- package/src/pages/404.tsx +15 -6
- package/src/pages/500.tsx +15 -6
- package/src/pages/[...slug].tsx +14 -5
- package/src/pages/[slug]/p.tsx +6 -3
- package/src/pages/_app.tsx +15 -10
- package/src/pages/account/403.tsx +30 -27
- package/src/pages/account/404.tsx +27 -20
- package/src/pages/account/orders/[id].tsx +22 -19
- package/src/pages/account/orders/index.tsx +25 -22
- package/src/pages/account/profile.tsx +27 -23
- package/src/pages/account/security.tsx +28 -23
- package/src/pages/account/user-details.tsx +20 -17
- package/src/pages/checkout.tsx +11 -8
- package/src/pages/index.tsx +7 -4
- package/src/pages/login.tsx +16 -7
- package/src/pages/s.tsx +5 -2
- package/src/sdk/deliveryPromise/index.ts +22 -0
- package/src/sdk/deliveryPromise/provider.tsx +119 -0
- package/src/sdk/deliveryPromise/queries.ts +80 -0
- package/src/sdk/deliveryPromise/reducer.ts +137 -0
- package/src/sdk/deliveryPromise/useDeliveryPromise.ts +419 -0
- package/src/sdk/overrides/PageProvider.tsx +9 -4
- package/src/sdk/product/useLocalizedVariables.ts +20 -6
- package/src/sdk/search/useFilter.ts +12 -1
- package/src/server/cms/index.ts +2 -0
- package/src/typings/overrides.ts +2 -1
- package/src/utils/globalSettings.ts +74 -0
- package/src/utils/utilities.ts +5 -0
- package/test/server/index.test.ts +1 -0
- package/.next/server/chunks/6272.js +0 -1
- package/.next/static/chunks/2284.1b43aea18c23c79e.js +0 -1
- package/.next/static/chunks/3155.ea52e06317dab557.js +0 -1
- package/.next/static/chunks/3166-50d81179a0f5a894.js +0 -1
- package/.next/static/chunks/3399.13a97fefb512c902.js +0 -1
- package/.next/static/chunks/3465.af28497e8069330f.js +0 -1
- package/.next/static/chunks/4803.de5b14237d616808.js +0 -1
- package/.next/static/chunks/4949.ea0775ca3029fb98.js +0 -1
- package/.next/static/chunks/6355.f1b1feefc0c84a2a.js +0 -1
- package/.next/static/chunks/6700.4e9426fe8b826dab.js +0 -1
- package/.next/static/chunks/7191-2a7b8ddbd07128b6.js +0 -1
- package/.next/static/chunks/7498-5246b607527180dd.js +0 -1
- package/.next/static/chunks/83.b87d797323ff2034.js +0 -1
- package/.next/static/chunks/9173-c1819846b9006c7a.js +0 -1
- package/.next/static/chunks/9540.69781e999f27cc05.js +0 -1
- package/.next/static/chunks/BannerNewsletter.7c592f132e7048e5.js +0 -1
- package/.next/static/chunks/CartSidebar.a00083c44c87c268.js +0 -1
- package/.next/static/chunks/Newsletter.1004055f09f76d3c.js +0 -1
- package/.next/static/chunks/ProductShelf.d51ba3e6a1b4a57d.js +0 -1
- package/.next/static/chunks/ProductTiles.77284431e2b8c898.js +0 -1
- package/.next/static/chunks/RegionModal.f61aa62e0a09182a.js +0 -1
- package/.next/static/chunks/Toast.6116bc845cd67f49.js +0 -1
- package/.next/static/chunks/UIBannerText.6cc5c00d4ba9b64e.js +0 -1
- package/.next/static/chunks/UISKUMatrixSidebar.782c55a97889e84a.js +0 -1
- package/.next/static/chunks/UIToast.494d0b0ce2c6106a.js +0 -1
- package/.next/static/chunks/pages/[...slug]-0db18c1c0920e8d2.js +0 -1
- package/.next/static/chunks/pages/[slug]/p-a255e4a7352455df.js +0 -1
- package/.next/static/chunks/pages/_app-1885a948b243078c.js +0 -1
- package/.next/static/chunks/pages/account/orders/[id]-b9feb0c860ff1cec.js +0 -1
- package/.next/static/chunks/pages/account/orders-1d8409a8b4b0e581.js +0 -1
- package/.next/static/chunks/pages/account/profile-5a919fa02b76a422.js +0 -1
- package/.next/static/chunks/pages/account/security-b5ab3d1ecbbea9d9.js +0 -1
- package/.next/static/chunks/pages/checkout-3a4983b22625c4e3.js +0 -1
- package/.next/static/chunks/pages/index-6e68be53d1fef20e.js +0 -1
- package/.next/static/chunks/pages/login-de3dd10c6b35159a.js +0 -1
- package/.next/static/chunks/pages/s-9b0f606f120d66b0.js +0 -1
- package/.next/static/chunks/webpack-a24b8ac1ca628dfe.js +0 -1
- package/.next/static/css/202a74b80e6ce63f.css +0 -1
- package/.next/static/pub-GYCLSosy4MirjEMnD/_buildManifest.js +0 -1
- /package/.next/static/{pub-GYCLSosy4MirjEMnD → pRYrZEXsDEpvxbtvEobPH}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export {
|
|
2
|
+
deliveryPromiseStore,
|
|
3
|
+
PICKUP_ALL_FACET_VALUE,
|
|
4
|
+
PICKUP_IN_POINT_FACET_VALUE,
|
|
5
|
+
PICKUP_POINT_FACET_KEY,
|
|
6
|
+
SHIPPING_FACET_KEY,
|
|
7
|
+
useDeliveryPromise,
|
|
8
|
+
} from './useDeliveryPromise'
|
|
9
|
+
export type { DeliveryPromiseStore, PickupPoint } from './useDeliveryPromise'
|
|
10
|
+
|
|
11
|
+
export { getPickupPoints } from './queries'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
deliveryPromiseReducer,
|
|
15
|
+
initializeDeliveryPromiseState,
|
|
16
|
+
initialPickupPointsSimulation,
|
|
17
|
+
type DeliveryPromiseReducerAction,
|
|
18
|
+
type DeliveryPromiseReducerState,
|
|
19
|
+
type PickupPointsSimulation,
|
|
20
|
+
} from './reducer'
|
|
21
|
+
|
|
22
|
+
export { DeliveryPromiseProvider, useDeliveryPromiseContext } from './provider'
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import deepEquals from 'fast-deep-equal'
|
|
2
|
+
import type { Dispatch, PropsWithChildren } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useReducer,
|
|
9
|
+
} from 'react'
|
|
10
|
+
|
|
11
|
+
import { useSession } from 'src/sdk/session'
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
deliveryPromiseReducer,
|
|
15
|
+
deliveryPromiseStore,
|
|
16
|
+
getPickupPoints,
|
|
17
|
+
initialPickupPointsSimulation,
|
|
18
|
+
initializeDeliveryPromiseState,
|
|
19
|
+
type DeliveryPromiseReducerAction,
|
|
20
|
+
type DeliveryPromiseReducerState,
|
|
21
|
+
} from '.'
|
|
22
|
+
|
|
23
|
+
type Context = DeliveryPromiseReducerState & {
|
|
24
|
+
dispatchDeliveryPromiseAction: Dispatch<DeliveryPromiseReducerAction>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const DeliveryPromiseContext = createContext<Context | undefined>(undefined)
|
|
28
|
+
|
|
29
|
+
export function DeliveryPromiseProvider({
|
|
30
|
+
children,
|
|
31
|
+
}: PropsWithChildren<unknown>) {
|
|
32
|
+
const { postalCode, geoCoordinates } = useSession()
|
|
33
|
+
const [state, dispatch] = useReducer(
|
|
34
|
+
deliveryPromiseReducer,
|
|
35
|
+
undefined,
|
|
36
|
+
initializeDeliveryPromiseState
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!postalCode || !state.shouldUpdatePickupPoints) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function fetchPickupPoints() {
|
|
45
|
+
const newPickupPoints = await getPickupPoints({
|
|
46
|
+
geoCoordinates:
|
|
47
|
+
state.simulatePickupPoints &&
|
|
48
|
+
state.pickupPointsSimulation?.geoCoordinates
|
|
49
|
+
? state.pickupPointsSimulation.geoCoordinates
|
|
50
|
+
: geoCoordinates,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// Pickup points simulation
|
|
54
|
+
if (state.simulatePickupPoints) {
|
|
55
|
+
deliveryPromiseStore.set({
|
|
56
|
+
pickupPointsSimulation: {
|
|
57
|
+
...state.pickupPointsSimulation,
|
|
58
|
+
pickupPoints: newPickupPoints,
|
|
59
|
+
},
|
|
60
|
+
shouldUpdatePickupPoints: false,
|
|
61
|
+
simulatePickupPoints: false,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Prevent reset store after reloading the page
|
|
68
|
+
if (
|
|
69
|
+
state.pickupPoints.length !== 0 &&
|
|
70
|
+
deepEquals(state.pickupPoints, newPickupPoints)
|
|
71
|
+
) {
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Check if `changeGlobalPickupPoint` action was already triggered
|
|
76
|
+
// for cases where shopper is changing both postal code and global pickup point
|
|
77
|
+
const isGlobalPickupPointUpdated = newPickupPoints.some(
|
|
78
|
+
({ id }) => id === state.globalPickupPoint?.id
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
deliveryPromiseStore.set({
|
|
82
|
+
globalPickupPoint: isGlobalPickupPointUpdated
|
|
83
|
+
? state.globalPickupPoint
|
|
84
|
+
: null,
|
|
85
|
+
defaultPickupPoint: null,
|
|
86
|
+
pickupPoints: newPickupPoints,
|
|
87
|
+
pickupPointsSimulation: initialPickupPointsSimulation,
|
|
88
|
+
simulatePickupPoints: false,
|
|
89
|
+
shouldUpdatePickupPoints: false,
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fetchPickupPoints()
|
|
94
|
+
}, [state.shouldUpdatePickupPoints, postalCode])
|
|
95
|
+
|
|
96
|
+
const value = useMemo(
|
|
97
|
+
() => ({
|
|
98
|
+
...state,
|
|
99
|
+
dispatchDeliveryPromiseAction: dispatch,
|
|
100
|
+
}),
|
|
101
|
+
[state]
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<DeliveryPromiseContext.Provider value={value}>
|
|
106
|
+
{children}
|
|
107
|
+
</DeliveryPromiseContext.Provider>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function useDeliveryPromiseContext() {
|
|
112
|
+
const context = useContext(DeliveryPromiseContext)
|
|
113
|
+
|
|
114
|
+
if (context === undefined) {
|
|
115
|
+
throw new Error('Missing Delivery Promise context on React tree')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return context
|
|
119
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { gql } from '@generated'
|
|
2
|
+
import type {
|
|
3
|
+
ClientPickupPointsQueryQuery as ClientPickupPointsQuery,
|
|
4
|
+
ClientPickupPointsQueryQueryVariables as ClientPickupPointsQueryVariables,
|
|
5
|
+
} from '@generated/graphql'
|
|
6
|
+
|
|
7
|
+
import { deliveryPromise } from 'discovery.config'
|
|
8
|
+
import { request } from 'src/sdk/graphql/request'
|
|
9
|
+
|
|
10
|
+
const pickupPointsQuery = gql(`
|
|
11
|
+
query ClientPickupPointsQuery(
|
|
12
|
+
$geoCoordinates: IStoreGeoCoordinates
|
|
13
|
+
) {
|
|
14
|
+
pickupPoints(geoCoordinates: $geoCoordinates) {
|
|
15
|
+
pickupPointDistances {
|
|
16
|
+
pickupId
|
|
17
|
+
distance
|
|
18
|
+
pickupName
|
|
19
|
+
isActive
|
|
20
|
+
address {
|
|
21
|
+
city
|
|
22
|
+
state
|
|
23
|
+
number
|
|
24
|
+
postalCode
|
|
25
|
+
street
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`)
|
|
31
|
+
|
|
32
|
+
type GetPickupPointsProps = {
|
|
33
|
+
geoCoordinates: {
|
|
34
|
+
latitude: number
|
|
35
|
+
longitude: number
|
|
36
|
+
} | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const getPickupPoints = async ({
|
|
40
|
+
geoCoordinates,
|
|
41
|
+
}: GetPickupPointsProps) => {
|
|
42
|
+
if (!deliveryPromise.enabled) {
|
|
43
|
+
return []
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!geoCoordinates) {
|
|
47
|
+
return []
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const variables = {
|
|
51
|
+
geoCoordinates: geoCoordinates ?? undefined,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const data = await request<
|
|
55
|
+
ClientPickupPointsQuery,
|
|
56
|
+
ClientPickupPointsQueryVariables
|
|
57
|
+
>(pickupPointsQuery, variables)
|
|
58
|
+
|
|
59
|
+
if (!data) {
|
|
60
|
+
return []
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const pickupPoints = data.pickupPoints?.pickupPointDistances
|
|
64
|
+
?.filter((pickupPoint) => pickupPoint.isActive)
|
|
65
|
+
.map((pickupPoint) => ({
|
|
66
|
+
id: pickupPoint?.pickupId,
|
|
67
|
+
name: pickupPoint?.pickupName,
|
|
68
|
+
totalItems: data.pickupPoints?.pickupPointDistances?.length ?? 0,
|
|
69
|
+
address: {
|
|
70
|
+
street: pickupPoint?.address?.street,
|
|
71
|
+
number: pickupPoint?.address?.number,
|
|
72
|
+
postalCode: pickupPoint?.address?.postalCode,
|
|
73
|
+
city: pickupPoint?.address?.city,
|
|
74
|
+
state: pickupPoint?.address?.state,
|
|
75
|
+
},
|
|
76
|
+
distance: pickupPoint?.distance,
|
|
77
|
+
}))
|
|
78
|
+
|
|
79
|
+
return pickupPoints
|
|
80
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Session } from '@faststore/sdk'
|
|
2
|
+
|
|
3
|
+
import type { PickupPoint } from '.'
|
|
4
|
+
|
|
5
|
+
export type PickupPointsSimulation = {
|
|
6
|
+
pickupPoints?: PickupPoint[]
|
|
7
|
+
geoCoordinates: Session['geoCoordinates'] | null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const initialPickupPointsSimulation: PickupPointsSimulation = {
|
|
11
|
+
pickupPoints: [],
|
|
12
|
+
geoCoordinates: null,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type DeliveryPromiseReducerState = {
|
|
16
|
+
pickupPoints?: PickupPoint[]
|
|
17
|
+
defaultPickupPoint?: PickupPoint
|
|
18
|
+
globalPickupPoint?: PickupPoint
|
|
19
|
+
shouldUpdatePickupPoints?: boolean
|
|
20
|
+
simulatePickupPoints?: boolean
|
|
21
|
+
pickupPointsSimulation?: PickupPointsSimulation
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type DeliveryPromiseReducerAction =
|
|
25
|
+
| {
|
|
26
|
+
type: 'updatePickupPoints'
|
|
27
|
+
payload: DeliveryPromiseReducerState
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
type: 'changePickupPoint'
|
|
31
|
+
payload: DeliveryPromiseReducerState['defaultPickupPoint']
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
type: 'changeGlobalPickupPoint'
|
|
35
|
+
payload: DeliveryPromiseReducerState['globalPickupPoint']
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
type: 'onPostalCodeChange'
|
|
39
|
+
payload?: {
|
|
40
|
+
simulatePickupPoints: DeliveryPromiseReducerState['simulatePickupPoints']
|
|
41
|
+
validatedSession: Partial<Session>
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
type: 'updateDeliveryPromiseState'
|
|
46
|
+
payload: DeliveryPromiseReducerState
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
type: 'clearPickupPointsSimulation'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const initializeDeliveryPromiseState =
|
|
53
|
+
(): DeliveryPromiseReducerState => ({
|
|
54
|
+
pickupPoints: [],
|
|
55
|
+
defaultPickupPoint: null,
|
|
56
|
+
globalPickupPoint: null,
|
|
57
|
+
shouldUpdatePickupPoints: false,
|
|
58
|
+
simulatePickupPoints: false,
|
|
59
|
+
pickupPointsSimulation: initialPickupPointsSimulation,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export const deliveryPromiseReducer = (
|
|
63
|
+
state: DeliveryPromiseReducerState,
|
|
64
|
+
action: DeliveryPromiseReducerAction
|
|
65
|
+
): DeliveryPromiseReducerState => {
|
|
66
|
+
const { type } = action
|
|
67
|
+
|
|
68
|
+
switch (type) {
|
|
69
|
+
case 'updatePickupPoints': {
|
|
70
|
+
const { payload } = action
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
defaultPickupPoint: null,
|
|
75
|
+
globalPickupPoint: null,
|
|
76
|
+
pickupPoints: payload.pickupPoints,
|
|
77
|
+
shouldUpdatePickupPoints: payload.shouldUpdatePickupPoints,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
case 'onPostalCodeChange': {
|
|
82
|
+
if (action.payload) {
|
|
83
|
+
const {
|
|
84
|
+
payload: { simulatePickupPoints, validatedSession },
|
|
85
|
+
} = action
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
...state,
|
|
89
|
+
simulatePickupPoints,
|
|
90
|
+
pickupPointsSimulation: {
|
|
91
|
+
...state.pickupPointsSimulation,
|
|
92
|
+
geoCoordinates: validatedSession.geoCoordinates,
|
|
93
|
+
},
|
|
94
|
+
shouldUpdatePickupPoints: true,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
...state,
|
|
100
|
+
pickupPointsSimulation: initialPickupPointsSimulation,
|
|
101
|
+
shouldUpdatePickupPoints: true,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
case 'changePickupPoint': {
|
|
106
|
+
const { payload } = action
|
|
107
|
+
|
|
108
|
+
return { ...state, defaultPickupPoint: payload }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
case 'changeGlobalPickupPoint': {
|
|
112
|
+
const { payload } = action
|
|
113
|
+
|
|
114
|
+
return { ...state, globalPickupPoint: payload }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case 'updateDeliveryPromiseState': {
|
|
118
|
+
const { payload } = action
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
...state,
|
|
122
|
+
...payload,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
case 'clearPickupPointsSimulation': {
|
|
127
|
+
return {
|
|
128
|
+
...state,
|
|
129
|
+
simulatePickupPoints: false,
|
|
130
|
+
pickupPointsSimulation: initialPickupPointsSimulation,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
default:
|
|
135
|
+
throw new Error(`Action ${type} not implemented`)
|
|
136
|
+
}
|
|
137
|
+
}
|