@akinon/next 1.13.1 → 1.14.1

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