@treely/strapi-slices 7.15.1 → 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.1",
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 (
@@ -43,7 +43,6 @@ export const ProjectInfo: React.FC<ProjectInfoProps> = ({
43
43
  subtitles,
44
44
  }: ProjectInfoProps) => {
45
45
  const { formatMessage, formatNumber, formatDate } = useContext(IntlContext);
46
-
47
46
  return (
48
47
  <Container p="2" width="full">
49
48
  <Heading size="xl" textAlign="left">
@@ -208,36 +207,39 @@ export const ProjectInfo: React.FC<ProjectInfoProps> = ({
208
207
  <></>
209
208
  )}
210
209
  <SimpleGrid columns={[1, null, null, 2]} spacingX="10" spacingY="8">
211
- {project.averageSellableAmountPerYear &&
212
- project.averageSellableAmountPerYear > 0 && (
213
- <Tooltip
214
- label={formatMessage({
215
- id: 'features.projectInfo.properties.projectVolume.toolTip',
216
- })}
217
- >
218
- <Box>
219
- <LabelTextPair
220
- label={formatMessage({
221
- id: 'features.projectInfo.properties.projectVolume.label',
222
- })}
223
- text={formatMessage(
224
- {
225
- id: 'unit.formatter.tonsCo2PerYear',
226
- },
227
- {
228
- number: formatNumber(
229
- convertCo2AmountKgToTons(
230
- project.averageSellableAmountPerYear.toString()
231
- ),
232
- { maximumFractionDigits: 0 }
210
+ {project.averageSellableAmountPerYear > 0 ? (
211
+ <Tooltip
212
+ label={formatMessage({
213
+ id: 'features.projectInfo.properties.projectVolume.toolTip',
214
+ })}
215
+ >
216
+ <Box>
217
+ <LabelTextPair
218
+ label={formatMessage({
219
+ id: 'features.projectInfo.properties.projectVolume.label',
220
+ })}
221
+ text={formatMessage(
222
+ {
223
+ id: 'unit.formatter.tonsCo2PerYear',
224
+ },
225
+ {
226
+ number: formatNumber(
227
+ convertCo2AmountKgToTons(
228
+ project.averageSellableAmountPerYear.toString()
233
229
  ),
234
- }
235
- )}
236
- caption={subtitles.averageSellableAmountPerYearSubtitle}
237
- />
238
- </Box>
239
- </Tooltip>
240
- )}
230
+ { maximumFractionDigits: 0 }
231
+ ),
232
+ }
233
+ )}
234
+ caption={subtitles.averageSellableAmountPerYearSubtitle}
235
+ />
236
+ </Box>
237
+ </Tooltip>
238
+ ) : (
239
+ <Box>
240
+ <CreditsAvailableBadge status={project.creditAvailability} />
241
+ </Box>
242
+ )}
241
243
 
242
244
  {project.riskBuffer && (
243
245
  <Box>
@@ -255,9 +257,13 @@ export const ProjectInfo: React.FC<ProjectInfoProps> = ({
255
257
  )}
256
258
  </SimpleGrid>
257
259
 
258
- <Box mt="2">
259
- <CreditsAvailableBadge status={project.creditAvailability} />
260
- </Box>
260
+ {project.averageSellableAmountPerYear > 0 ? (
261
+ <Box mt="2">
262
+ <CreditsAvailableBadge status={project.creditAvailability} />
263
+ </Box>
264
+ ) : (
265
+ <></>
266
+ )}
261
267
  </Container>
262
268
  );
263
269
  };
@@ -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;