@treely/strapi-slices 5.4.0 → 5.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treely/strapi-slices",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "license": "MIT",
5
5
  "author": "Tree.ly GmbH",
6
6
  "description": "@treely/strapi-slices is a open source library maintained by Tree.ly.",
@@ -80,7 +80,7 @@ describe('The SmallCheckout component', () => {
80
80
 
81
81
  await waitFor(() => {
82
82
  expect(pushSpy).toHaveBeenCalledWith(
83
- 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=2000'
83
+ 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=2000&cancelPath=%2F'
84
84
  );
85
85
  });
86
86
  });
@@ -106,7 +106,7 @@ describe('The SmallCheckout component', () => {
106
106
 
107
107
  await waitFor(() => {
108
108
  expect(pushSpy).toHaveBeenCalledWith(
109
- 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=3000'
109
+ 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=3000&cancelPath=%2F'
110
110
  );
111
111
  });
112
112
  });
@@ -56,7 +56,7 @@ const SmallCheckout = ({
56
56
  button,
57
57
  }: SmallCheckoutProps) => {
58
58
  const { formatNumber, formatMessage, locale } = useContext(IntlContext);
59
- const { push } = useRouter();
59
+ const { asPath, push } = useRouter();
60
60
 
61
61
  const validateForm = useCallback(
62
62
  (values: SmallCheckoutForm) => {
@@ -85,13 +85,21 @@ const SmallCheckout = ({
85
85
  [locale]
86
86
  );
87
87
 
88
- const onSubmit = async ({ contributionValueCurrency }: SmallCheckoutForm) =>
89
- push(
90
- `${FPM_API_URI}/v1/webhooks/shop/checkout?batchId=${batchId}&quantity=${Math.floor(
91
- contributionValueCurrency / pricePerKg
92
- )}`
88
+ const onSubmit = async ({ contributionValueCurrency }: SmallCheckoutForm) => {
89
+ const url = new URL(`${FPM_API_URI}/v1/webhooks/shop/checkout`);
90
+
91
+ url.searchParams.append('batchId', batchId);
92
+
93
+ url.searchParams.append(
94
+ 'quantity',
95
+ Math.floor(contributionValueCurrency / pricePerKg).toString()
93
96
  );
94
97
 
98
+ url.searchParams.append('cancelPath', asPath);
99
+
100
+ push(url.toString());
101
+ };
102
+
95
103
  return (
96
104
  <Flex
97
105
  width="full"
@@ -58,7 +58,7 @@ describe('The ShowCheckout section', () => {
58
58
 
59
59
  await waitFor(() => {
60
60
  expect(pushSpy).toHaveBeenCalledWith(
61
- 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=1000'
61
+ 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=1000&cancelPath=%2F'
62
62
  );
63
63
  });
64
64
  });
@@ -72,7 +72,7 @@ describe('The ShowCheckout section', () => {
72
72
 
73
73
  await waitFor(() => {
74
74
  expect(pushSpy).toHaveBeenCalledWith(
75
- 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=1000&couponId=coupon-id'
75
+ 'https://api.fpm.t-staging.com/v1/webhooks/shop/checkout?batchId=batchId&quantity=1000&cancelPath=%2F&couponId=coupon-id'
76
76
  );
77
77
  });
78
78
  });
@@ -18,7 +18,6 @@ import {
18
18
  Wrapper,
19
19
  } from 'boemly';
20
20
  import { Field, FieldProps, Form, Formik, FormikProps } from 'formik';
21
- import { useRouter } from 'next/router';
22
21
  import { FPM_API_URI } from '../../constants/api';
23
22
  import CheckoutForm from '../../models/forms/CheckoutForm';
24
23
  import {
@@ -26,6 +25,7 @@ import {
26
25
  MINIMUM_CONTRIBUTION_VALUE_IN_MONEY,
27
26
  } from '../../constants/domain';
28
27
  import { IntlContext } from '../../components/ContextProvider';
28
+ import { useRouter } from 'next/router';
29
29
 
30
30
  export interface ShopCheckoutProps {
31
31
  slice: {
@@ -45,7 +45,7 @@ export interface ShopCheckoutProps {
45
45
  export const ShopCheckout = ({ slice }: ShopCheckoutProps): JSX.Element => {
46
46
  const [primary50] = useToken('colors', ['primary.50']);
47
47
  const { formatMessage, formatNumber, locale } = useContext(IntlContext);
48
- const { push } = useRouter();
48
+ const { asPath, push } = useRouter();
49
49
 
50
50
  const validateForm = useCallback(
51
51
  (values: CheckoutForm) => {
@@ -84,6 +84,8 @@ export const ShopCheckout = ({ slice }: ShopCheckoutProps): JSX.Element => {
84
84
  Math.floor(contributionValue / slice.pricePerKg).toString()
85
85
  );
86
86
 
87
+ url.searchParams.append('cancelPath', asPath);
88
+
87
89
  if (slice.couponId) url.searchParams.append('couponId', slice.couponId);
88
90
 
89
91
  push(url.toString());