@akinon/next 1.52.0-rc.0 → 1.53.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 +9 -485
- package/api/client.ts +17 -50
- package/assets/styles/index.scss +26 -50
- package/bin/pz-prebuild.js +0 -1
- package/bin/pz-predev.js +0 -1
- package/components/index.ts +0 -1
- package/components/input.tsx +7 -21
- package/components/link.tsx +13 -17
- package/components/price.tsx +4 -11
- package/components/pz-root.tsx +3 -15
- package/components/selected-payment-option-view.tsx +38 -26
- package/data/client/account.ts +9 -10
- package/data/client/address.ts +8 -32
- package/data/client/api.ts +1 -1
- package/data/client/b2b.ts +2 -35
- package/data/client/basket.ts +5 -6
- package/data/client/checkout.ts +4 -47
- package/data/client/user.ts +2 -3
- package/data/client/wishlist.ts +1 -1
- package/data/server/category.ts +19 -43
- package/data/server/flatpage.ts +7 -29
- package/data/server/form.ts +11 -29
- package/data/server/landingpage.ts +7 -26
- package/data/server/list.ts +6 -16
- package/data/server/menu.ts +2 -15
- package/data/server/product.ts +21 -46
- package/data/server/seo.ts +24 -17
- package/data/server/special-page.ts +5 -15
- package/data/server/widget.ts +7 -14
- package/data/urls.ts +1 -8
- package/hocs/server/with-segment-defaults.tsx +1 -4
- package/hooks/index.ts +1 -2
- package/hooks/use-pagination.ts +2 -2
- package/hooks/use-payment-options.ts +1 -2
- package/lib/cache.ts +6 -8
- package/middlewares/default.ts +8 -87
- package/middlewares/pretty-url.ts +1 -11
- package/middlewares/url-redirection.ts +0 -4
- package/package.json +3 -4
- package/plugins.d.ts +0 -1
- package/redux/middlewares/checkout.ts +11 -70
- package/redux/reducers/checkout.ts +5 -24
- package/redux/reducers/config.ts +0 -2
- package/types/commerce/account.ts +0 -1
- package/types/commerce/address.ts +1 -1
- package/types/commerce/b2b.ts +2 -12
- package/types/commerce/checkout.ts +0 -30
- package/types/commerce/misc.ts +0 -2
- package/types/commerce/order.ts +0 -5
- package/types/index.ts +2 -18
- package/utils/app-fetch.ts +8 -17
- package/utils/generate-commerce-search-params.ts +1 -3
- package/utils/index.ts +6 -27
- package/utils/server-translation.ts +1 -11
- package/utils/server-variables.ts +1 -2
- package/with-pz-config.js +2 -13
- package/assets/styles/index.css +0 -49
- package/assets/styles/index.css.map +0 -1
- package/bin/pz-generate-translations.js +0 -41
- package/components/file-input.tsx +0 -8
- package/hooks/use-message-listener.ts +0 -24
- package/lib/cache-handler.mjs +0 -33
- package/routes/pretty-url.tsx +0 -192
- package/utils/redirection-iframe.ts +0 -85
package/data/urls.ts
CHANGED
|
@@ -83,8 +83,6 @@ export const checkout = {
|
|
|
83
83
|
setDeliveryOption: '/orders/checkout/?page=DeliveryOptionSelectionPage',
|
|
84
84
|
setAddresses: '/orders/checkout/?page=AddressSelectionPage',
|
|
85
85
|
setShippingOption: '/orders/checkout/?page=ShippingOptionSelectionPage',
|
|
86
|
-
setDataSourceShippingOption:
|
|
87
|
-
'/orders/checkout/?page=DataSourceShippingOptionSelectionPage',
|
|
88
86
|
setPaymentOption: '/orders/checkout/?page=PaymentOptionSelectionPage',
|
|
89
87
|
setBinNumber: '/orders/checkout/?page=BinNumberPage',
|
|
90
88
|
setMasterpassBinNumber: '/orders/checkout/?page=MasterpassBinNumberPage',
|
|
@@ -111,8 +109,6 @@ export const checkout = {
|
|
|
111
109
|
loyaltyMoneyUsage: '/orders/checkout/?page=LoyaltyMoneyUsagePage',
|
|
112
110
|
setOrderNote: '/orders/checkout/?page=OrderNotePage',
|
|
113
111
|
couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage',
|
|
114
|
-
setAttributeBasedShippingOption:
|
|
115
|
-
'/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage',
|
|
116
112
|
deliveryBagsPage: '/orders/checkout/?page=DeliveryBagsPage'
|
|
117
113
|
};
|
|
118
114
|
|
|
@@ -202,10 +198,7 @@ export const b2b = {
|
|
|
202
198
|
draftBaskets: '/b2b/basket/drafts/',
|
|
203
199
|
divisions: '/b2b/my-divisions/',
|
|
204
200
|
myQuotations: '/b2b/my-quotations/',
|
|
205
|
-
loadBasket: (id) => `/b2b/basket/${id}/load
|
|
206
|
-
statusBasket: (cacheKey) => `/b2b/basket/?status_cache_key=${cacheKey}`,
|
|
207
|
-
basketExport: (queryString) => `/b2b/basket/?upload=true&${queryString}`,
|
|
208
|
-
basketImport: '/b2b/basket/bulk-import/'
|
|
201
|
+
loadBasket: (id) => `/b2b/basket/${id}/load/`
|
|
209
202
|
};
|
|
210
203
|
|
|
211
204
|
export const widgets = {
|
|
@@ -2,6 +2,7 @@ import settings from 'settings';
|
|
|
2
2
|
import { LayoutProps, PageProps, RootLayoutProps } from '../../types';
|
|
3
3
|
import { redirect } from 'next/navigation';
|
|
4
4
|
import { ServerVariables } from '../../utils/server-variables';
|
|
5
|
+
import { getTranslations } from '../../utils/server-translation';
|
|
5
6
|
import { ROUTES } from 'routes';
|
|
6
7
|
import logger from '../../utils/log';
|
|
7
8
|
|
|
@@ -49,11 +50,7 @@ const addRootLayoutProps = async (componentProps: RootLayoutProps) => {
|
|
|
49
50
|
return redirect(ROUTES.HOME);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
const { getTranslations } = settings.useOptimizedTranslations
|
|
53
|
-
? require('translations')
|
|
54
|
-
: require('../../utils/server-translation');
|
|
55
53
|
const translations = await getTranslations(params.locale);
|
|
56
|
-
|
|
57
54
|
componentProps.translations = translations;
|
|
58
55
|
|
|
59
56
|
const locale = settings.localization.locales.find(
|
package/hooks/index.ts
CHANGED
|
@@ -8,5 +8,4 @@ export * from './use-media-query';
|
|
|
8
8
|
export * from './use-on-click-outside';
|
|
9
9
|
export * from './use-mobile-iframe-handler';
|
|
10
10
|
export * from './use-payment-options';
|
|
11
|
-
export * from './use-pagination';
|
|
12
|
-
export * from './use-message-listener';
|
|
11
|
+
export * from './use-pagination';
|
package/hooks/use-pagination.ts
CHANGED
|
@@ -116,7 +116,7 @@ export default function usePagination(
|
|
|
116
116
|
urlSearchParams.set('page', (Number(state.page) - 1).toString());
|
|
117
117
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
118
118
|
}
|
|
119
|
-
return
|
|
119
|
+
return '#';
|
|
120
120
|
}, [state.page, pathname, urlSearchParams]);
|
|
121
121
|
|
|
122
122
|
const next = useMemo(() => {
|
|
@@ -124,7 +124,7 @@ export default function usePagination(
|
|
|
124
124
|
urlSearchParams.set('page', (Number(state.page) + 1).toString());
|
|
125
125
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
126
126
|
}
|
|
127
|
-
return
|
|
127
|
+
return '#';
|
|
128
128
|
}, [state.page, state.last, pathname, urlSearchParams]);
|
|
129
129
|
|
|
130
130
|
return {
|
|
@@ -18,8 +18,7 @@ export const usePaymentOptions = () => {
|
|
|
18
18
|
pay_on_delivery: 'pz-pay-on-delivery',
|
|
19
19
|
bkm_express: 'pz-bkm',
|
|
20
20
|
credit_payment: 'pz-credit-payment',
|
|
21
|
-
masterpass: 'pz-masterpass'
|
|
22
|
-
gpay: 'pz-gpay'
|
|
21
|
+
masterpass: 'pz-masterpass'
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
const isInitialTypeIncluded = (type: string) => initialTypes.has(type);
|
package/lib/cache.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { RedisClientType } from 'redis';
|
|
|
3
3
|
import Settings from 'settings';
|
|
4
4
|
import { CacheOptions } from '../types';
|
|
5
5
|
import logger from '../utils/log';
|
|
6
|
+
import { ServerVariables } from '../utils/server-variables';
|
|
6
7
|
|
|
7
8
|
const hashCacheKey = (object?: Record<string, string>) => {
|
|
8
9
|
if (!object) {
|
|
@@ -58,8 +59,10 @@ export const CacheKey = {
|
|
|
58
59
|
export class Cache {
|
|
59
60
|
static PROXY_URL = `${process.env.NEXT_PUBLIC_URL}/api/cache`;
|
|
60
61
|
|
|
61
|
-
static formatKey(key: string
|
|
62
|
-
return encodeURIComponent(
|
|
62
|
+
static formatKey(key: string) {
|
|
63
|
+
return encodeURIComponent(
|
|
64
|
+
`${Settings.commerceUrl}_${ServerVariables.locale}_${key}`
|
|
65
|
+
);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
static clientPool: Pool<RedisClientType> = createPool(
|
|
@@ -152,14 +155,9 @@ export class Cache {
|
|
|
152
155
|
|
|
153
156
|
static async wrap<T = any>(
|
|
154
157
|
key: string,
|
|
155
|
-
locale: string,
|
|
156
158
|
handler: () => Promise<T>,
|
|
157
159
|
options?: CacheOptions
|
|
158
160
|
): Promise<T> {
|
|
159
|
-
if (Settings.usePrettyUrlRoute) {
|
|
160
|
-
return await handler();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
161
|
const requiredVariables = [
|
|
164
162
|
process.env.CACHE_HOST,
|
|
165
163
|
process.env.CACHE_PORT,
|
|
@@ -176,7 +174,7 @@ export class Cache {
|
|
|
176
174
|
};
|
|
177
175
|
|
|
178
176
|
const _options = Object.assign(defaultOptions, options);
|
|
179
|
-
const formattedKey = Cache.formatKey(key
|
|
177
|
+
const formattedKey = Cache.formatKey(key);
|
|
180
178
|
|
|
181
179
|
logger.debug('Cache wrap', { key, formattedKey, _options });
|
|
182
180
|
|
package/middlewares/default.ts
CHANGED
|
@@ -88,44 +88,14 @@ const withPzDefault =
|
|
|
88
88
|
req.nextUrl.pathname.includes('/orders/hooks/') ||
|
|
89
89
|
req.nextUrl.pathname.includes('/orders/checkout-with-token/')
|
|
90
90
|
) {
|
|
91
|
-
|
|
92
|
-
const currency = url.searchParams.get('currency')?.toLowerCase();
|
|
93
|
-
|
|
94
|
-
const headers = {};
|
|
95
|
-
|
|
96
|
-
if (segment) {
|
|
97
|
-
headers['X-Segment-Id'] = segment;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (currency) {
|
|
101
|
-
headers['x-currency'] = currency;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const response = NextResponse.rewrite(
|
|
91
|
+
return NextResponse.rewrite(
|
|
105
92
|
new URL(
|
|
106
93
|
`${Settings.commerceUrl}${req.nextUrl.pathname.replace(
|
|
107
94
|
urlLocaleMatcherRegex,
|
|
108
95
|
''
|
|
109
96
|
)}`
|
|
110
|
-
)
|
|
111
|
-
{
|
|
112
|
-
headers
|
|
113
|
-
}
|
|
97
|
+
)
|
|
114
98
|
);
|
|
115
|
-
|
|
116
|
-
if (segment) {
|
|
117
|
-
response.cookies.set('pz-segment', segment);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (currency) {
|
|
121
|
-
response.cookies.set('pz-currency', currency, {
|
|
122
|
-
sameSite: 'none',
|
|
123
|
-
secure: true,
|
|
124
|
-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7) // 7 days
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return response;
|
|
129
99
|
}
|
|
130
100
|
|
|
131
101
|
if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
|
|
@@ -219,41 +189,10 @@ const withPzDefault =
|
|
|
219
189
|
''
|
|
220
190
|
);
|
|
221
191
|
|
|
222
|
-
middlewareResult = (await middleware(
|
|
223
|
-
req,
|
|
224
|
-
event
|
|
225
|
-
)) as NextResponse | void;
|
|
226
|
-
|
|
227
|
-
let customRewriteUrlDiff = '';
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
middlewareResult instanceof NextResponse &&
|
|
231
|
-
middlewareResult.headers.get(
|
|
232
|
-
'pz-override-response'
|
|
233
|
-
) &&
|
|
234
|
-
middlewareResult.headers.get(
|
|
235
|
-
'x-middleware-rewrite'
|
|
236
|
-
)
|
|
237
|
-
) {
|
|
238
|
-
const rewriteUrl = new URL(
|
|
239
|
-
middlewareResult.headers.get(
|
|
240
|
-
'x-middleware-rewrite'
|
|
241
|
-
)
|
|
242
|
-
);
|
|
243
|
-
const originalUrl = new URL(req.url);
|
|
244
|
-
customRewriteUrlDiff =
|
|
245
|
-
rewriteUrl.pathname.replace(
|
|
246
|
-
originalUrl.pathname,
|
|
247
|
-
''
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
192
|
url.basePath = `/${commerceUrl}`;
|
|
252
193
|
url.pathname = `/${
|
|
253
194
|
locale.length ? `${locale}/` : ''
|
|
254
|
-
}${currency}
|
|
255
|
-
prettyUrl ?? pathnameWithoutLocale
|
|
256
|
-
}`.replace(/\/+/g, '/');
|
|
195
|
+
}${currency}${prettyUrl ?? pathnameWithoutLocale}`;
|
|
257
196
|
|
|
258
197
|
if (
|
|
259
198
|
!req.middlewareParams.found &&
|
|
@@ -268,20 +207,6 @@ const withPzDefault =
|
|
|
268
207
|
);
|
|
269
208
|
}
|
|
270
209
|
|
|
271
|
-
if (
|
|
272
|
-
Settings.usePrettyUrlRoute &&
|
|
273
|
-
url.searchParams.toString().length > 0 &&
|
|
274
|
-
!Object.entries(ROUTES).find(([, value]) =>
|
|
275
|
-
new RegExp(`^${value}/?$`).test(
|
|
276
|
-
pathnameWithoutLocale
|
|
277
|
-
)
|
|
278
|
-
)
|
|
279
|
-
) {
|
|
280
|
-
url.pathname =
|
|
281
|
-
url.pathname +
|
|
282
|
-
`searchparams|${url.searchParams.toString()}`;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
210
|
Settings.rewrites.forEach((rewrite) => {
|
|
286
211
|
url.pathname = url.pathname.replace(
|
|
287
212
|
rewrite.source,
|
|
@@ -289,6 +214,11 @@ const withPzDefault =
|
|
|
289
214
|
);
|
|
290
215
|
});
|
|
291
216
|
|
|
217
|
+
middlewareResult = (await middleware(
|
|
218
|
+
req,
|
|
219
|
+
event
|
|
220
|
+
)) as NextResponse | void;
|
|
221
|
+
|
|
292
222
|
// if middleware.ts has a return value for current url
|
|
293
223
|
if (middlewareResult instanceof NextResponse) {
|
|
294
224
|
// pz-override-response header is used to prevent 404 page for custom responses.
|
|
@@ -301,15 +231,6 @@ const withPzDefault =
|
|
|
301
231
|
'x-middleware-rewrite',
|
|
302
232
|
url.href
|
|
303
233
|
);
|
|
304
|
-
} else if (
|
|
305
|
-
middlewareResult.headers.get(
|
|
306
|
-
'x-middleware-rewrite'
|
|
307
|
-
) &&
|
|
308
|
-
middlewareResult.headers.get(
|
|
309
|
-
'pz-override-response'
|
|
310
|
-
) === 'true'
|
|
311
|
-
) {
|
|
312
|
-
middlewareResult = NextResponse.rewrite(url);
|
|
313
234
|
}
|
|
314
235
|
} else {
|
|
315
236
|
// if middleware.ts doesn't have a return value.
|
|
@@ -43,14 +43,9 @@ const resolvePrettyUrlHandler =
|
|
|
43
43
|
return prettyUrlResult;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const resolvePrettyUrl = async (
|
|
47
|
-
pathname: string,
|
|
48
|
-
locale: string,
|
|
49
|
-
ip: string | null
|
|
50
|
-
) => {
|
|
46
|
+
const resolvePrettyUrl = async (pathname: string, ip: string | null) => {
|
|
51
47
|
return Cache.wrap(
|
|
52
48
|
CacheKey.PrettyUrl(pathname),
|
|
53
|
-
locale,
|
|
54
49
|
resolvePrettyUrlHandler(pathname, ip),
|
|
55
50
|
{
|
|
56
51
|
useProxy: true
|
|
@@ -61,10 +56,6 @@ const resolvePrettyUrl = async (
|
|
|
61
56
|
const withPrettyUrl =
|
|
62
57
|
(middleware: NextMiddleware) =>
|
|
63
58
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
64
|
-
if (Settings.usePrettyUrlRoute) {
|
|
65
|
-
return middleware(req, event);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
59
|
const url = req.nextUrl.clone();
|
|
69
60
|
const matchedLanguagePrefix = url.pathname.match(
|
|
70
61
|
urlLocaleMatcherRegex
|
|
@@ -93,7 +84,6 @@ const withPrettyUrl =
|
|
|
93
84
|
)
|
|
94
85
|
? url.pathname
|
|
95
86
|
: prettyUrlPathname,
|
|
96
|
-
matchedLanguagePrefix,
|
|
97
87
|
ip
|
|
98
88
|
);
|
|
99
89
|
|
|
@@ -11,10 +11,6 @@ import { ROUTES } from 'routes';
|
|
|
11
11
|
const withUrlRedirection =
|
|
12
12
|
(middleware: NextMiddleware) =>
|
|
13
13
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
14
|
-
if (settings.usePrettyUrlRoute) {
|
|
15
|
-
return middleware(req, event);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
const url = req.nextUrl.clone();
|
|
19
15
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
20
16
|
const pathnameWithoutLocale = url.pathname.replace(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/next",
|
|
3
3
|
"description": "Core package for Project Zero Next",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.53.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -20,17 +20,16 @@
|
|
|
20
20
|
"@opentelemetry/sdk-trace-node": "1.19.0",
|
|
21
21
|
"@opentelemetry/semantic-conventions": "1.19.0",
|
|
22
22
|
"@reduxjs/toolkit": "1.9.7",
|
|
23
|
-
"@neshca/cache-handler": "1.5.1",
|
|
24
23
|
"cross-spawn": "7.0.3",
|
|
25
24
|
"generic-pool": "3.9.0",
|
|
26
25
|
"react-redux": "8.1.3",
|
|
27
26
|
"react-string-replace": "1.1.1",
|
|
28
|
-
"redis": "4.
|
|
27
|
+
"redis": "4.5.1",
|
|
29
28
|
"semver": "7.6.2",
|
|
30
29
|
"set-cookie-parser": "2.6.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@akinon/eslint-plugin-projectzero": "1.
|
|
32
|
+
"@akinon/eslint-plugin-projectzero": "1.53.0",
|
|
34
33
|
"@types/react-redux": "7.1.30",
|
|
35
34
|
"@types/set-cookie-parser": "2.4.7",
|
|
36
35
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
package/plugins.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ declare module '@akinon/pz-masterpass/src/utils' {
|
|
|
12
12
|
declare module '@akinon/pz-masterpass/src/redux/reducer' {
|
|
13
13
|
export const setError: any;
|
|
14
14
|
export const setOtpModalVisible: any;
|
|
15
|
-
export const setCvcRequired: any;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
declare module '@akinon/pz-otp' {
|
|
@@ -16,10 +16,8 @@ import {
|
|
|
16
16
|
setPreOrder,
|
|
17
17
|
setRetailStores,
|
|
18
18
|
setShippingOptions,
|
|
19
|
-
setDataSourceShippingOptions,
|
|
20
19
|
setShippingStepCompleted,
|
|
21
|
-
setCreditPaymentOptions
|
|
22
|
-
setAttributeBasedShippingOptions
|
|
20
|
+
setCreditPaymentOptions
|
|
23
21
|
} from '../../redux/reducers/checkout';
|
|
24
22
|
import { RootState, TypedDispatch } from 'redux/store';
|
|
25
23
|
import { checkoutApi } from '../../data/client/checkout';
|
|
@@ -28,11 +26,10 @@ import { getCookie, setCookie } from '../../utils';
|
|
|
28
26
|
import settings from 'settings';
|
|
29
27
|
import { LocaleUrlStrategy } from '../../localization';
|
|
30
28
|
import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
|
|
31
|
-
import { showRedirectionIframe } from '../../utils/redirection-iframe';
|
|
32
29
|
|
|
33
30
|
interface CheckoutResult {
|
|
34
31
|
payload: {
|
|
35
|
-
errors?:
|
|
32
|
+
errors?: any;
|
|
36
33
|
pre_order?: PreOrder;
|
|
37
34
|
context_list?: CheckoutContext[];
|
|
38
35
|
};
|
|
@@ -76,10 +73,8 @@ export const preOrderMiddleware: Middleware = ({
|
|
|
76
73
|
deliveryOptions,
|
|
77
74
|
addressList: addresses,
|
|
78
75
|
shippingOptions,
|
|
79
|
-
dataSourceShippingOptions,
|
|
80
76
|
paymentOptions,
|
|
81
|
-
installmentOptions
|
|
82
|
-
attributeBasedShippingOptions
|
|
77
|
+
installmentOptions
|
|
83
78
|
} = getState().checkout;
|
|
84
79
|
const { endpoints: apiEndpoints } = checkoutApi;
|
|
85
80
|
|
|
@@ -130,40 +125,6 @@ export const preOrderMiddleware: Middleware = ({
|
|
|
130
125
|
dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
|
|
131
126
|
}
|
|
132
127
|
|
|
133
|
-
if (
|
|
134
|
-
dataSourceShippingOptions.length > 0 &&
|
|
135
|
-
!preOrder.data_source_shipping_options
|
|
136
|
-
) {
|
|
137
|
-
const selectedDataSourceShippingOptionsPks =
|
|
138
|
-
dataSourceShippingOptions.map(
|
|
139
|
-
(opt) => opt.data_source_shipping_options[0].pk
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
dispatch(
|
|
143
|
-
apiEndpoints.setDataSourceShippingOptions.initiate(
|
|
144
|
-
selectedDataSourceShippingOptionsPks
|
|
145
|
-
)
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
Object.keys(attributeBasedShippingOptions).length > 0 &&
|
|
151
|
-
!preOrder.attribute_based_shipping_options
|
|
152
|
-
) {
|
|
153
|
-
const initialSelectedOptions: Record<string, number> = Object.fromEntries(
|
|
154
|
-
Object.entries(attributeBasedShippingOptions).map(([key, options]) => [
|
|
155
|
-
key,
|
|
156
|
-
options[0].pk
|
|
157
|
-
])
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
dispatch(
|
|
161
|
-
apiEndpoints.setAttributeBasedShippingOptions.initiate(
|
|
162
|
-
initialSelectedOptions
|
|
163
|
-
)
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
128
|
if (!preOrder.payment_option && paymentOptions.length > 0) {
|
|
168
129
|
dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
|
|
169
130
|
}
|
|
@@ -202,7 +163,6 @@ export const contextListMiddleware: Middleware = ({
|
|
|
202
163
|
if (result?.payload?.context_list) {
|
|
203
164
|
result.payload.context_list.forEach((context) => {
|
|
204
165
|
const redirectUrl = context.page_context.redirect_url;
|
|
205
|
-
const isIframe = context.page_context.is_frame ?? false;
|
|
206
166
|
|
|
207
167
|
if (redirectUrl) {
|
|
208
168
|
const currentLocale = getCookie('pz-locale');
|
|
@@ -221,19 +181,16 @@ export const contextListMiddleware: Middleware = ({
|
|
|
221
181
|
}
|
|
222
182
|
|
|
223
183
|
const urlObj = new URL(url, window.location.origin);
|
|
224
|
-
const isMobileDevice =
|
|
225
|
-
isMobileApp ||
|
|
226
|
-
/iPad|iPhone|iPod|Android/i.test(navigator.userAgent);
|
|
227
|
-
const isIframePaymentOptionExcluded =
|
|
228
|
-
!settings.checkout?.iframeExcludedPaymentOptions?.includes(
|
|
229
|
-
result.payload?.pre_order?.payment_option?.slug
|
|
230
|
-
);
|
|
231
184
|
urlObj.searchParams.set('t', new Date().getTime().toString());
|
|
232
185
|
|
|
233
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
(isMobileApp ||
|
|
188
|
+
/iPad|iPhone|iPod|Android/i.test(navigator.userAgent)) &&
|
|
189
|
+
!settings.checkout?.iframeExcludedPaymentOptions?.includes(
|
|
190
|
+
result.payload?.pre_order?.payment_option?.slug
|
|
191
|
+
)
|
|
192
|
+
) {
|
|
234
193
|
showMobile3dIframe(urlObj.toString());
|
|
235
|
-
} else if (isIframe && !isIframePaymentOptionExcluded) {
|
|
236
|
-
showRedirectionIframe(urlObj.toString());
|
|
237
194
|
} else {
|
|
238
195
|
window.location.href = urlObj.toString();
|
|
239
196
|
}
|
|
@@ -263,28 +220,12 @@ export const contextListMiddleware: Middleware = ({
|
|
|
263
220
|
dispatch(setShippingOptions(context.page_context.shipping_options));
|
|
264
221
|
}
|
|
265
222
|
|
|
266
|
-
if (context.page_context.data_sources) {
|
|
267
|
-
dispatch(
|
|
268
|
-
setDataSourceShippingOptions(context.page_context.data_sources)
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (context.page_context.attribute_based_shipping_options) {
|
|
273
|
-
dispatch(
|
|
274
|
-
setAttributeBasedShippingOptions(
|
|
275
|
-
context.page_context.attribute_based_shipping_options
|
|
276
|
-
)
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
223
|
if (context.page_context.payment_options) {
|
|
281
224
|
dispatch(setPaymentOptions(context.page_context.payment_options));
|
|
282
225
|
}
|
|
283
226
|
|
|
284
227
|
if (context.page_context.credit_payment_options) {
|
|
285
|
-
dispatch(
|
|
286
|
-
setCreditPaymentOptions(context.page_context.credit_payment_options)
|
|
287
|
-
);
|
|
228
|
+
dispatch(setCreditPaymentOptions(context.page_context.credit_payment_options));
|
|
288
229
|
}
|
|
289
230
|
|
|
290
231
|
if (context.page_context.payment_choices) {
|
|
@@ -14,13 +14,12 @@ import {
|
|
|
14
14
|
CheckoutCreditPaymentOption,
|
|
15
15
|
PreOrder,
|
|
16
16
|
RetailStore,
|
|
17
|
-
ShippingOption
|
|
18
|
-
DataSource,
|
|
19
|
-
AttributeBasedShippingOption
|
|
17
|
+
ShippingOption
|
|
20
18
|
} from '../../types';
|
|
21
19
|
|
|
22
20
|
export interface CheckoutState {
|
|
23
|
-
|
|
21
|
+
// TODO: Add types
|
|
22
|
+
errors: any;
|
|
24
23
|
hasGiftBox: boolean;
|
|
25
24
|
canGuestPurchase: boolean;
|
|
26
25
|
steps: {
|
|
@@ -38,7 +37,6 @@ export interface CheckoutState {
|
|
|
38
37
|
addressList: Address[];
|
|
39
38
|
deliveryOptions: DeliveryOption[];
|
|
40
39
|
shippingOptions: ShippingOption[];
|
|
41
|
-
dataSourceShippingOptions: DataSource[];
|
|
42
40
|
paymentOptions: PaymentOption[];
|
|
43
41
|
creditPaymentOptions: CheckoutCreditPaymentOption[];
|
|
44
42
|
selectedCreditPaymentPk: number;
|
|
@@ -49,8 +47,6 @@ export interface CheckoutState {
|
|
|
49
47
|
selectedBankAccountPk: number;
|
|
50
48
|
loyaltyBalance?: string;
|
|
51
49
|
retailStores: RetailStore[];
|
|
52
|
-
attributeBasedShippingOptions: AttributeBasedShippingOption[];
|
|
53
|
-
selectedShippingOptions: Record<string, number>;
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
const initialState: CheckoutState = {
|
|
@@ -72,7 +68,6 @@ const initialState: CheckoutState = {
|
|
|
72
68
|
addressList: [],
|
|
73
69
|
deliveryOptions: [],
|
|
74
70
|
shippingOptions: [],
|
|
75
|
-
dataSourceShippingOptions: [],
|
|
76
71
|
paymentOptions: [],
|
|
77
72
|
creditPaymentOptions: [],
|
|
78
73
|
selectedCreditPaymentPk: null,
|
|
@@ -81,9 +76,7 @@ const initialState: CheckoutState = {
|
|
|
81
76
|
installmentOptions: [],
|
|
82
77
|
bankAccounts: [],
|
|
83
78
|
selectedBankAccountPk: null,
|
|
84
|
-
retailStores: []
|
|
85
|
-
attributeBasedShippingOptions: [],
|
|
86
|
-
selectedShippingOptions: {}
|
|
79
|
+
retailStores: []
|
|
87
80
|
};
|
|
88
81
|
|
|
89
82
|
const checkoutSlice = createSlice({
|
|
@@ -129,9 +122,6 @@ const checkoutSlice = createSlice({
|
|
|
129
122
|
setShippingOptions(state, { payload }) {
|
|
130
123
|
state.shippingOptions = payload;
|
|
131
124
|
},
|
|
132
|
-
setDataSourceShippingOptions(state, { payload }) {
|
|
133
|
-
state.dataSourceShippingOptions = payload;
|
|
134
|
-
},
|
|
135
125
|
setPaymentOptions(state, { payload }) {
|
|
136
126
|
state.paymentOptions = payload;
|
|
137
127
|
},
|
|
@@ -161,12 +151,6 @@ const checkoutSlice = createSlice({
|
|
|
161
151
|
},
|
|
162
152
|
setRetailStores(state, { payload }) {
|
|
163
153
|
state.retailStores = payload;
|
|
164
|
-
},
|
|
165
|
-
setAttributeBasedShippingOptions(state, { payload }) {
|
|
166
|
-
state.attributeBasedShippingOptions = payload;
|
|
167
|
-
},
|
|
168
|
-
setSelectedShippingOptions: (state, { payload }) => {
|
|
169
|
-
state.selectedShippingOptions = payload;
|
|
170
154
|
}
|
|
171
155
|
}
|
|
172
156
|
});
|
|
@@ -185,7 +169,6 @@ export const {
|
|
|
185
169
|
setAddressList,
|
|
186
170
|
setDeliveryOptions,
|
|
187
171
|
setShippingOptions,
|
|
188
|
-
setDataSourceShippingOptions,
|
|
189
172
|
setPaymentOptions,
|
|
190
173
|
setCreditPaymentOptions,
|
|
191
174
|
setSelectedCreditPaymentPk,
|
|
@@ -195,9 +178,7 @@ export const {
|
|
|
195
178
|
setBankAccounts,
|
|
196
179
|
setSelectedBankAccountPk,
|
|
197
180
|
setLoyaltyBalance,
|
|
198
|
-
setRetailStores
|
|
199
|
-
setAttributeBasedShippingOptions,
|
|
200
|
-
setSelectedShippingOptions
|
|
181
|
+
setRetailStores
|
|
201
182
|
} = checkoutSlice.actions;
|
|
202
183
|
|
|
203
184
|
export default checkoutSlice.reducer;
|
package/redux/reducers/config.ts
CHANGED
package/types/commerce/b2b.ts
CHANGED
|
@@ -72,7 +72,7 @@ export type BasketItemType = {
|
|
|
72
72
|
divisions: BasketItemDivision[];
|
|
73
73
|
product: ProductB2b;
|
|
74
74
|
product_remote_id: number;
|
|
75
|
-
}
|
|
75
|
+
}
|
|
76
76
|
|
|
77
77
|
export type BasketParams = {
|
|
78
78
|
division: string;
|
|
@@ -91,7 +91,7 @@ export type CreateQuotationParams = {
|
|
|
91
91
|
export type UpdateProductParams = {
|
|
92
92
|
product_remote_id: number;
|
|
93
93
|
division: number;
|
|
94
|
-
quantity: number
|
|
94
|
+
quantity: number
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
export type DeleteProductParams = {
|
|
@@ -115,13 +115,3 @@ export type DraftResponse = {
|
|
|
115
115
|
total_amount: number;
|
|
116
116
|
total_quantity: number;
|
|
117
117
|
};
|
|
118
|
-
|
|
119
|
-
export type BasketStatusResponse = {
|
|
120
|
-
is_ready: boolean;
|
|
121
|
-
status: string;
|
|
122
|
-
url: string;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export type ExportBasketResponse = {
|
|
126
|
-
cache_key: string;
|
|
127
|
-
};
|