@treely/strapi-slices 7.15.2 → 7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treely/strapi-slices",
3
- "version": "7.15.2",
3
+ "version": "7.16.0",
4
4
  "license": "MIT",
5
5
  "author": "Tree.ly FlexCo",
6
6
  "description": "@treely/strapi-slices is a open source library maintained by Tree.ly.",
@@ -42,6 +42,7 @@ import Locale from '../../models/Locale';
42
42
  import { ContextProvider } from '../ContextProvider';
43
43
  import Timeline from '../../slices/Timeline';
44
44
  import Events from '../../slices/Events';
45
+ import Redirect from '../../slices/Redirect';
45
46
  import { AnalyticsFunction } from '../ContextProvider/ContextProvider';
46
47
 
47
48
  export interface CustomSliceProps {
@@ -316,6 +317,10 @@ export const SliceRenderer = ({
316
317
  return (
317
318
  <Events key={`${slice.__component}-${slice.id}`} slice={slice} />
318
319
  );
320
+ case 'sections.redirect':
321
+ return (
322
+ <Redirect key={`${slice.__component}-${slice.id}`} slice={slice} />
323
+ );
319
324
  default:
320
325
  if (CustomSlice) {
321
326
  return (
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { render } from '../../test/testUtils';
3
+ import { mergeDeep } from '../../utils/mergeDeep';
4
+ import { redirectSpy } from '../../../__mocks__/next/navigation';
5
+ import Redirect from '.';
6
+ import { RedirectProps } from './Redirect';
7
+ import { RedirectType } from 'next/navigation';
8
+
9
+ const defaultProps: RedirectProps = {
10
+ slice: {
11
+ url: 'https://redirect.com',
12
+ },
13
+ };
14
+
15
+ const setup = (props = {}) => {
16
+ const combinedProps = mergeDeep(defaultProps, props);
17
+ render(<Redirect {...combinedProps} />);
18
+ };
19
+
20
+ describe('The Redirect component', () => {
21
+ afterEach(() => {
22
+ redirectSpy.mockRestore();
23
+ });
24
+
25
+ it('calls the redirect URL when rendering', () => {
26
+ setup();
27
+
28
+ expect(redirectSpy).toHaveBeenCalledWith(
29
+ 'https://redirect.com',
30
+ RedirectType.replace
31
+ );
32
+ });
33
+ });
@@ -0,0 +1,17 @@
1
+ import React, { useEffect } from 'react';
2
+ import { RedirectType, redirect } from 'next/navigation';
3
+
4
+ export interface RedirectProps {
5
+ slice: {
6
+ url: string;
7
+ };
8
+ }
9
+
10
+ export const Redirect = ({ slice }: RedirectProps): JSX.Element => {
11
+ useEffect(() => {
12
+ // When using `replace`, the current browser history entry will be replaced
13
+ redirect(slice.url, RedirectType.replace);
14
+ }, [slice.url]);
15
+
16
+ return <></>;
17
+ };
@@ -0,0 +1,3 @@
1
+ import { Redirect } from './Redirect';
2
+
3
+ export default Redirect;