@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/README.md +2 -0
- package/dist/__mocks__/next/navigation.d.ts +7 -0
- package/dist/slices/Redirect/Redirect.d.ts +7 -0
- package/dist/slices/Redirect/index.d.ts +2 -0
- package/dist/strapi-slices.cjs.development.js +247 -287
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +247 -287
- package/dist/strapi-slices.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/SliceRenderer/SliceRenderer.tsx +5 -0
- package/src/components/portfolio/ProjectInfo/ProjectInfo.tsx +39 -33
- package/src/slices/Redirect/Rediect.test.tsx +33 -0
- package/src/slices/Redirect/Redirect.tsx +17 -0
- package/src/slices/Redirect/index.ts +3 -0
package/package.json
CHANGED
|
@@ -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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
>
|
|
218
|
-
<
|
|
219
|
-
|
|
220
|
-
label
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
259
|
-
<
|
|
260
|
-
|
|
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
|
+
};
|