@akinon/next 1.14.1 → 1.16.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.
@@ -1,265 +1,265 @@
1
- 'use client';
2
-
3
- import { Middleware } from '@reduxjs/toolkit';
4
- import {
5
- setAddressList,
6
- setBankAccounts,
7
- setCanGuestPurchase,
8
- setCardType,
9
- setDeliveryOptions,
10
- setErrors,
11
- setHasGiftBox,
12
- setInstallmentOptions,
13
- setLoyaltyBalance,
14
- setPaymentChoices,
15
- setPaymentOptions,
16
- setPreOrder,
17
- setRetailStores,
18
- setShippingOptions,
19
- setShippingStepCompleted,
20
- setCreditPaymentOptions
21
- } from '../../redux/reducers/checkout';
22
- import { RootState, TypedDispatch } from 'redux/store';
23
- import { checkoutApi } from '../../data/client/checkout';
24
- import { CheckoutContext, PreOrder } from '../../types';
25
- import { getCookie, setCookie } from '../../utils';
26
- import settings from 'settings';
27
- import { LocaleUrlStrategy } from '../../localization';
28
- import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
29
-
30
- interface CheckoutResult {
31
- payload: {
32
- errors?: any;
33
- pre_order?: PreOrder;
34
- context_list?: CheckoutContext[];
35
- };
36
- }
37
-
38
- interface MiddlewareParams {
39
- getState: () => RootState;
40
- dispatch: TypedDispatch;
41
- }
42
-
43
- export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
44
- return (next) => (action) => {
45
- const result: CheckoutResult = next(action);
46
- const errors = result?.payload?.errors;
47
-
48
- if (errors) {
49
- dispatch(setErrors(errors));
50
- }
51
-
52
- return result;
53
- };
54
- };
55
-
56
- export const preOrderMiddleware: Middleware = ({
57
- getState,
58
- dispatch
59
- }: MiddlewareParams) => {
60
- return (next) => (action) => {
61
- const result: CheckoutResult = next(action);
62
- const preOrder = result?.payload?.pre_order;
63
-
64
- if (
65
- !preOrder ||
66
- action?.meta?.arg?.endpointName === 'guestLogin' ||
67
- action?.meta?.arg?.endpointName === 'getCheckoutLoyaltyBalance'
68
- ) {
69
- return result;
70
- }
71
-
72
- const {
73
- deliveryOptions,
74
- addressList: addresses,
75
- shippingOptions,
76
- paymentOptions,
77
- installmentOptions
78
- } = getState().checkout;
79
- const { endpoints: apiEndpoints } = checkoutApi;
80
-
81
- if (preOrder.is_redirected) {
82
- const contextList = result?.payload?.context_list;
83
-
84
- if (
85
- contextList.find(
86
- (ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
87
- )
88
- ) {
89
- dispatch(
90
- apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
91
- );
92
- return;
93
- }
94
- }
95
-
96
- dispatch(setPreOrder(preOrder));
97
-
98
- if (!preOrder.delivery_option && deliveryOptions.length > 0) {
99
- dispatch(
100
- apiEndpoints.setDeliveryOption.initiate(
101
- deliveryOptions.find((opt) => opt.delivery_option_type === 'customer')
102
- ?.pk
103
- )
104
- );
105
- }
106
-
107
- if (
108
- (!preOrder.shipping_address || !preOrder.billing_address) &&
109
- addresses.length > 0 &&
110
- preOrder.delivery_option?.delivery_option_type === 'customer'
111
- ) {
112
- dispatch(
113
- apiEndpoints.setAddresses.initiate({
114
- shippingAddressPk: addresses[0].pk,
115
- billingAddressPk: addresses[0].pk
116
- })
117
- );
118
- }
119
-
120
- if (
121
- shippingOptions.length > 0 &&
122
- (!preOrder.shipping_option ||
123
- !shippingOptions.find((opt) => opt.pk === preOrder.shipping_option?.pk))
124
- ) {
125
- dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
126
- }
127
-
128
- if (!preOrder.payment_option && paymentOptions.length > 0) {
129
- dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
130
- }
131
-
132
- if (!preOrder.installment && installmentOptions.length > 0) {
133
- dispatch(
134
- apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
135
- );
136
- }
137
-
138
- dispatch(
139
- setShippingStepCompleted(
140
- [
141
- preOrder.delivery_option?.delivery_option_type === 'retail_store'
142
- ? true
143
- : preOrder.shipping_address?.pk,
144
- preOrder.billing_address?.pk,
145
- preOrder.shipping_option?.pk,
146
- addresses.length > 0
147
- ].every(Boolean)
148
- )
149
- );
150
-
151
- return result;
152
- };
153
- };
154
-
155
- export const contextListMiddleware: Middleware = ({
156
- dispatch,
157
- getState
158
- }: MiddlewareParams) => {
159
- return (next) => (action) => {
160
- const { isMobileApp } = getState().root;
161
- const result: CheckoutResult = next(action);
162
-
163
- if (result?.payload?.context_list) {
164
- result.payload.context_list.forEach((context) => {
165
- const redirectUrl = context.page_context.redirect_url;
166
-
167
- if (redirectUrl) {
168
- const currentLocale = getCookie('pz-locale');
169
-
170
- let url = redirectUrl;
171
-
172
- if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
173
- const { defaultLocaleValue, localeUrlStrategy } =
174
- settings.localization;
175
-
176
- url =
177
- currentLocale === defaultLocaleValue &&
178
- localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
179
- ? redirectUrl
180
- : `/${currentLocale}${redirectUrl}`;
181
- }
182
-
183
- const urlObj = new URL(url, window.location.origin);
184
- urlObj.searchParams.set('t', new Date().getTime().toString());
185
-
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
- ) {
193
- showMobile3dIframe(urlObj.toString());
194
- } else {
195
- window.location.href = urlObj.toString();
196
- }
197
-
198
- return;
199
- }
200
-
201
- if (context.page_context.has_gift_box) {
202
- dispatch(setHasGiftBox(context.page_context.has_gift_box));
203
- }
204
-
205
- if (typeof context.page_context.can_guest_purchase === 'boolean') {
206
- dispatch(
207
- setCanGuestPurchase(context.page_context.can_guest_purchase)
208
- );
209
- }
210
-
211
- if (context.page_context.delivery_options) {
212
- dispatch(setDeliveryOptions(context.page_context.delivery_options));
213
- }
214
-
215
- if (context.page_context.addresses) {
216
- dispatch(setAddressList(context.page_context.addresses));
217
- }
218
-
219
- if (context.page_context.shipping_options) {
220
- dispatch(setShippingOptions(context.page_context.shipping_options));
221
- }
222
-
223
- if (context.page_context.payment_options) {
224
- dispatch(setPaymentOptions(context.page_context.payment_options));
225
- }
226
-
227
- if (context.page_context.credit_payment_options) {
228
- dispatch(setCreditPaymentOptions(context.page_context.credit_payment_options));
229
- }
230
-
231
- if (context.page_context.payment_choices) {
232
- dispatch(setPaymentChoices(context.page_context.payment_choices));
233
- }
234
-
235
- if (context.page_context.bank_accounts) {
236
- dispatch(setBankAccounts(context.page_context.bank_accounts));
237
- }
238
-
239
- if (
240
- !result.payload.context_list.find(
241
- (ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
242
- )
243
- ) {
244
- if (context.page_context.card_type) {
245
- dispatch(setCardType(context.page_context.card_type));
246
- }
247
-
248
- if (context.page_context.installments) {
249
- dispatch(setInstallmentOptions(context.page_context.installments));
250
- }
251
- }
252
-
253
- if (context.page_context.balance) {
254
- dispatch(setLoyaltyBalance(context.page_context.balance));
255
- }
256
-
257
- if (context.page_context.retail_stores) {
258
- dispatch(setRetailStores(context.page_context.retail_stores));
259
- }
260
- });
261
- }
262
-
263
- return result;
264
- };
265
- };
1
+ 'use client';
2
+
3
+ import { Middleware } from '@reduxjs/toolkit';
4
+ import {
5
+ setAddressList,
6
+ setBankAccounts,
7
+ setCanGuestPurchase,
8
+ setCardType,
9
+ setDeliveryOptions,
10
+ setErrors,
11
+ setHasGiftBox,
12
+ setInstallmentOptions,
13
+ setLoyaltyBalance,
14
+ setPaymentChoices,
15
+ setPaymentOptions,
16
+ setPreOrder,
17
+ setRetailStores,
18
+ setShippingOptions,
19
+ setShippingStepCompleted,
20
+ setCreditPaymentOptions
21
+ } from '../../redux/reducers/checkout';
22
+ import { RootState, TypedDispatch } from 'redux/store';
23
+ import { checkoutApi } from '../../data/client/checkout';
24
+ import { CheckoutContext, PreOrder } from '../../types';
25
+ import { getCookie, setCookie } from '../../utils';
26
+ import settings from 'settings';
27
+ import { LocaleUrlStrategy } from '../../localization';
28
+ import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
29
+
30
+ interface CheckoutResult {
31
+ payload: {
32
+ errors?: any;
33
+ pre_order?: PreOrder;
34
+ context_list?: CheckoutContext[];
35
+ };
36
+ }
37
+
38
+ interface MiddlewareParams {
39
+ getState: () => RootState;
40
+ dispatch: TypedDispatch;
41
+ }
42
+
43
+ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
44
+ return (next) => (action) => {
45
+ const result: CheckoutResult = next(action);
46
+ const errors = result?.payload?.errors;
47
+
48
+ if (errors) {
49
+ dispatch(setErrors(errors));
50
+ }
51
+
52
+ return result;
53
+ };
54
+ };
55
+
56
+ export const preOrderMiddleware: Middleware = ({
57
+ getState,
58
+ dispatch
59
+ }: MiddlewareParams) => {
60
+ return (next) => (action) => {
61
+ const result: CheckoutResult = next(action);
62
+ const preOrder = result?.payload?.pre_order;
63
+
64
+ if (
65
+ !preOrder ||
66
+ action?.meta?.arg?.endpointName === 'guestLogin' ||
67
+ action?.meta?.arg?.endpointName === 'getCheckoutLoyaltyBalance'
68
+ ) {
69
+ return result;
70
+ }
71
+
72
+ const {
73
+ deliveryOptions,
74
+ addressList: addresses,
75
+ shippingOptions,
76
+ paymentOptions,
77
+ installmentOptions
78
+ } = getState().checkout;
79
+ const { endpoints: apiEndpoints } = checkoutApi;
80
+
81
+ if (preOrder.is_redirected) {
82
+ const contextList = result?.payload?.context_list;
83
+
84
+ if (
85
+ contextList.find(
86
+ (ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
87
+ )
88
+ ) {
89
+ dispatch(
90
+ apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
91
+ );
92
+ return;
93
+ }
94
+ }
95
+
96
+ dispatch(setPreOrder(preOrder));
97
+
98
+ if (!preOrder.delivery_option && deliveryOptions.length > 0) {
99
+ dispatch(
100
+ apiEndpoints.setDeliveryOption.initiate(
101
+ deliveryOptions.find((opt) => opt.delivery_option_type === 'customer')
102
+ ?.pk
103
+ )
104
+ );
105
+ }
106
+
107
+ if (
108
+ (!preOrder.shipping_address || !preOrder.billing_address) &&
109
+ addresses.length > 0 &&
110
+ preOrder.delivery_option?.delivery_option_type === 'customer'
111
+ ) {
112
+ dispatch(
113
+ apiEndpoints.setAddresses.initiate({
114
+ shippingAddressPk: addresses[0].pk,
115
+ billingAddressPk: addresses[0].pk
116
+ })
117
+ );
118
+ }
119
+
120
+ if (
121
+ shippingOptions.length > 0 &&
122
+ (!preOrder.shipping_option ||
123
+ !shippingOptions.find((opt) => opt.pk === preOrder.shipping_option?.pk))
124
+ ) {
125
+ dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
126
+ }
127
+
128
+ if (!preOrder.payment_option && paymentOptions.length > 0) {
129
+ dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
130
+ }
131
+
132
+ if (!preOrder.installment && installmentOptions.length > 0) {
133
+ dispatch(
134
+ apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
135
+ );
136
+ }
137
+
138
+ dispatch(
139
+ setShippingStepCompleted(
140
+ [
141
+ preOrder.delivery_option?.delivery_option_type === 'retail_store'
142
+ ? true
143
+ : preOrder.shipping_address?.pk,
144
+ preOrder.billing_address?.pk,
145
+ preOrder.shipping_option?.pk,
146
+ addresses.length > 0
147
+ ].every(Boolean)
148
+ )
149
+ );
150
+
151
+ return result;
152
+ };
153
+ };
154
+
155
+ export const contextListMiddleware: Middleware = ({
156
+ dispatch,
157
+ getState
158
+ }: MiddlewareParams) => {
159
+ return (next) => (action) => {
160
+ const { isMobileApp } = getState().root;
161
+ const result: CheckoutResult = next(action);
162
+
163
+ if (result?.payload?.context_list) {
164
+ result.payload.context_list.forEach((context) => {
165
+ const redirectUrl = context.page_context.redirect_url;
166
+
167
+ if (redirectUrl) {
168
+ const currentLocale = getCookie('pz-locale');
169
+
170
+ let url = redirectUrl;
171
+
172
+ if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
173
+ const { defaultLocaleValue, localeUrlStrategy } =
174
+ settings.localization;
175
+
176
+ url =
177
+ currentLocale === defaultLocaleValue &&
178
+ localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
179
+ ? redirectUrl
180
+ : `/${currentLocale}${redirectUrl}`;
181
+ }
182
+
183
+ const urlObj = new URL(url, window.location.origin);
184
+ urlObj.searchParams.set('t', new Date().getTime().toString());
185
+
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
+ ) {
193
+ showMobile3dIframe(urlObj.toString());
194
+ } else {
195
+ window.location.href = urlObj.toString();
196
+ }
197
+
198
+ return;
199
+ }
200
+
201
+ if (context.page_context.has_gift_box) {
202
+ dispatch(setHasGiftBox(context.page_context.has_gift_box));
203
+ }
204
+
205
+ if (typeof context.page_context.can_guest_purchase === 'boolean') {
206
+ dispatch(
207
+ setCanGuestPurchase(context.page_context.can_guest_purchase)
208
+ );
209
+ }
210
+
211
+ if (context.page_context.delivery_options) {
212
+ dispatch(setDeliveryOptions(context.page_context.delivery_options));
213
+ }
214
+
215
+ if (context.page_context.addresses) {
216
+ dispatch(setAddressList(context.page_context.addresses));
217
+ }
218
+
219
+ if (context.page_context.shipping_options) {
220
+ dispatch(setShippingOptions(context.page_context.shipping_options));
221
+ }
222
+
223
+ if (context.page_context.payment_options) {
224
+ dispatch(setPaymentOptions(context.page_context.payment_options));
225
+ }
226
+
227
+ if (context.page_context.credit_payment_options) {
228
+ dispatch(setCreditPaymentOptions(context.page_context.credit_payment_options));
229
+ }
230
+
231
+ if (context.page_context.payment_choices) {
232
+ dispatch(setPaymentChoices(context.page_context.payment_choices));
233
+ }
234
+
235
+ if (context.page_context.bank_accounts) {
236
+ dispatch(setBankAccounts(context.page_context.bank_accounts));
237
+ }
238
+
239
+ if (
240
+ !result.payload.context_list.find(
241
+ (ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
242
+ )
243
+ ) {
244
+ if (context.page_context.card_type) {
245
+ dispatch(setCardType(context.page_context.card_type));
246
+ }
247
+
248
+ if (context.page_context.installments) {
249
+ dispatch(setInstallmentOptions(context.page_context.installments));
250
+ }
251
+ }
252
+
253
+ if (context.page_context.balance) {
254
+ dispatch(setLoyaltyBalance(context.page_context.balance));
255
+ }
256
+
257
+ if (context.page_context.retail_stores) {
258
+ dispatch(setRetailStores(context.page_context.retail_stores));
259
+ }
260
+ });
261
+ }
262
+
263
+ return result;
264
+ };
265
+ };
@@ -1,15 +1,15 @@
1
- import rootReducer from './root';
2
- import checkoutReducer from './checkout';
3
- import configReducer from './config';
4
- import headerReducer from './header';
5
- import { api } from '../../data/client/api';
6
-
7
- const reducers = {
8
- [api.reducerPath]: api.reducer,
9
- root: rootReducer,
10
- checkout: checkoutReducer,
11
- config: configReducer,
12
- header: headerReducer
13
- };
14
-
1
+ import rootReducer from './root';
2
+ import checkoutReducer from './checkout';
3
+ import configReducer from './config';
4
+ import headerReducer from './header';
5
+ import { api } from '../../data/client/api';
6
+
7
+ const reducers = {
8
+ [api.reducerPath]: api.reducer,
9
+ root: rootReducer,
10
+ checkout: checkoutReducer,
11
+ config: configReducer,
12
+ header: headerReducer
13
+ };
14
+
15
15
  export default reducers;