@akinon/next 1.89.0-rc.19 → 1.89.0-rc.20

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.89.0-rc.20
4
+
5
+ ### Minor Changes
6
+
7
+ - e68e120: ZERO-3398: Add redirectUrlMiddleware to handle redirection based on checkout results
8
+
3
9
  ## 1.89.0-rc.19
4
10
 
5
11
  ### Minor Changes
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.89.0-rc.19",
4
+ "version": "1.89.0-rc.20",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "set-cookie-parser": "2.6.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@akinon/eslint-plugin-projectzero": "1.89.0-rc.19",
37
+ "@akinon/eslint-plugin-projectzero": "1.89.0-rc.20",
38
38
  "@babel/core": "7.26.10",
39
39
  "@babel/preset-env": "7.26.9",
40
40
  "@babel/preset-typescript": "7.27.0",
@@ -37,6 +37,7 @@ interface CheckoutResult {
37
37
  errors?: Record<string, string[]>;
38
38
  pre_order?: PreOrder;
39
39
  context_list?: CheckoutContext[];
40
+ redirect_url?: string;
40
41
  };
41
42
  }
42
43
 
@@ -62,6 +63,33 @@ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
62
63
  };
63
64
  };
64
65
 
66
+ export const redirectUrlMiddleware: Middleware = () => {
67
+ return (next) => (action) => {
68
+ const result: CheckoutResult = next(action);
69
+ const redirectUrl = result?.payload?.redirect_url;
70
+
71
+ if (redirectUrl) {
72
+ const currentLocale = getCookie('pz-locale');
73
+
74
+ let url = redirectUrl;
75
+
76
+ if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
77
+ const { defaultLocaleValue, localeUrlStrategy } = settings.localization;
78
+
79
+ url =
80
+ currentLocale === defaultLocaleValue &&
81
+ localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
82
+ ? redirectUrl
83
+ : `/${currentLocale}${redirectUrl}`;
84
+ }
85
+
86
+ window.location.href = url;
87
+ }
88
+
89
+ return result;
90
+ };
91
+ };
92
+
65
93
  export const contextListMiddleware: Middleware = ({
66
94
  dispatch,
67
95
  getState
@@ -5,6 +5,7 @@ import { ROUTES } from 'routes';
5
5
  import type { Middleware } from '@reduxjs/toolkit';
6
6
  import {
7
7
  errorMiddleware,
8
+ redirectUrlMiddleware,
8
9
  contextListMiddleware,
9
10
  hepsiPayMiddleware,
10
11
  walletPaymentMiddleware
@@ -50,6 +51,7 @@ const middlewares = [
50
51
  rtkQueryResponseHandler,
51
52
  rtkQueryErrorHandler,
52
53
  errorMiddleware,
54
+ redirectUrlMiddleware,
53
55
  ...preOrderMiddlewares,
54
56
  contextListMiddleware,
55
57
  hepsiPayMiddleware,