@akinon/next 1.89.0 → 1.90.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.90.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e68e120: ZERO-3398: Add redirectUrlMiddleware to handle redirection based on checkout results
8
+
3
9
  ## 1.89.0
4
10
 
5
11
  ## 1.88.0
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",
4
+ "version": "1.90.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -31,7 +31,7 @@
31
31
  "set-cookie-parser": "2.6.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@akinon/eslint-plugin-projectzero": "1.89.0",
34
+ "@akinon/eslint-plugin-projectzero": "1.90.0",
35
35
  "@types/react-redux": "7.1.30",
36
36
  "@types/set-cookie-parser": "2.4.7",
37
37
  "@typescript-eslint/eslint-plugin": "6.7.4",
@@ -36,6 +36,7 @@ interface CheckoutResult {
36
36
  errors?: Record<string, string[]>;
37
37
  pre_order?: PreOrder;
38
38
  context_list?: CheckoutContext[];
39
+ redirect_url?: string;
39
40
  };
40
41
  }
41
42
 
@@ -57,6 +58,33 @@ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
57
58
  };
58
59
  };
59
60
 
61
+ export const redirectUrlMiddleware: Middleware = () => {
62
+ return (next) => (action) => {
63
+ const result: CheckoutResult = next(action);
64
+ const redirectUrl = result?.payload?.redirect_url;
65
+
66
+ if (redirectUrl) {
67
+ const currentLocale = getCookie('pz-locale');
68
+
69
+ let url = redirectUrl;
70
+
71
+ if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
72
+ const { defaultLocaleValue, localeUrlStrategy } = settings.localization;
73
+
74
+ url =
75
+ currentLocale === defaultLocaleValue &&
76
+ localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
77
+ ? redirectUrl
78
+ : `/${currentLocale}${redirectUrl}`;
79
+ }
80
+
81
+ window.location.href = url;
82
+ }
83
+
84
+ return result;
85
+ };
86
+ };
87
+
60
88
  export const contextListMiddleware: Middleware = ({
61
89
  dispatch,
62
90
  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,