Skip to content

Commit 28acbe5

Browse files
committed
Implement customHints logic
1 parent 91d7797 commit 28acbe5

7 files changed

Lines changed: 91 additions & 1 deletion

File tree

public/assets/data/requirement-profiles/requirement-profiles-hydration.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,16 @@
17021702
"de": "Substitutionstherapie",
17031703
"en": "Substitution Therapy"
17041704
},
1705+
"customHints": [
1706+
{
1707+
"pattern": {
1708+
"ff:healthInsurance": false
1709+
},
1710+
"de": "Sie haben angegeben, dass Sie keine Krankenversicherung haben. Bitte beachten Sie, dass sie darauf einen Anspruch haben und es Voraussetzung für diese Leistung ist.",
1711+
"de_es": "Sie haben angegeben, dass Sie keine Krankenversicherung haben. Bitte beachten Sie, dass sie darauf einen Anspruch haben und es Voraussetzung für diese Leistung ist.",
1712+
"en": "You have indicated that you do not have health insurance. Please note that you are entitled to it and it is a prerequisite for this benefit."
1713+
}
1714+
],
17051715
"teaser": {
17061716
"de": "In der Suchtmedizin ist die Substitutionstherapie eine Behandlung, bei der heroinabhängige Menschen ein ärztlich verordnetes Ersatzopioid wie Methadon oder Buprenorphin erhalten. Ziel der Behandlung ist es, den Konsum von Heroin zu verhindern, bzw. zu verringern.",
17071717
"de_es": "In der Suchtmedizin gibt es die Substitutionstherapie. Das heißt, Menschen, die von Heroin abhängig sind, bekommen ein anderes Medikament. Das Medikament ersetzt das Heroin. Das Medikament ist zum Beispiel Methadon oder Buprenorphin. Die Menschen bekommen das Medikament von einem Arzt oder einer Ärztin. So sollen die Menschen weniger Heroin nehmen oder gar kein Heroin mehr nehmen.",

src/ui/language/translations.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ const translations = {
312312
btn: "Show local information",
313313
btnClose: "Close local information",
314314
},
315+
customHints: {
316+
title: "Hints for you based on your profile"
317+
},
315318
goals: "Goals",
316319
benefitType: "Benefit type",
317320
benefitScope: "Benefit scope",
@@ -701,6 +704,9 @@ const translations = {
701704
btn: "Unterstützung vor Ort anzeigen",
702705
btnClose: "Unterstützung vor Ort schließen"
703706
},
707+
customHints: {
708+
title: "Hinweise für Sie, basierend auf Ihrem Profil"
709+
},
704710
description: "Beschreibung",
705711
goals: "Ziele",
706712
benefitType: "Leistungsgegenstand",

src/ui/screens/benefit-page/BenefitPageScreen.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import BenefitPageGeneral from './components/BenefitPageGeneral';
77
import BenefitPageApplication from './components/BenefitPageApplication';
88
import BenefitPageRequirements from './components/BenefitPageRequirements';
99
import BenefitPageLocal from './components/BenefitPageLocal';
10+
import BenefitPageCustomHints from "@/ui/screens/benefit-page/components/BenefitPageCustomHints";
1011

1112
const BenefitPageScreen = ({
1213
t,
1314
id,
1415
isDesktop,
1516
benefitPageData,
1617
localisedData,
18+
customHints,
1719
xml,
1820
targetClass,
1921
validatedStatus,
@@ -35,6 +37,11 @@ const BenefitPageScreen = ({
3537
categoryTitles={categoryTitles}
3638
/>
3739
<VBox sx={{ gap: { xs: 4, md: 8 }}}>
40+
{
41+
customHints && customHints.length > 0 && (
42+
<BenefitPageCustomHints t={t} isDesktop={isDesktop} customHints={customHints} />
43+
)
44+
}
3845
<BenefitPageGeneral t={t} isDesktop={isDesktop} benefitPageData={benefitPageData} />
3946
<BenefitPageApplication t={t} isDesktop={isDesktop} benefitPageData={benefitPageData} xml={xml} />
4047
{

src/ui/screens/benefit-page/BenefitPageScreenContainer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import matchingEngineManager from "@/core/managers/matchingEngineManager";
1010
import { useUserStore } from '@/ui/storage/zustand';
1111
import { useStore } from "@/ui/shared-components/ViewportUpdater";
1212
import { useFetchLocaliseData } from './hooks/useFetchLocalisedData';
13+
import { useFetchCustomBenefitPageHints } from "@/ui/screens/benefit-page/hooks/useFetchCustomBenefitPageHints";
1314
import useFetchData from '@/ui/shared-hooks/utility/useFetchResource';
1415
import useFetchTargetClass from './hooks/useFetchTargetClass';
1516

@@ -24,7 +25,8 @@ const BenefitPageScreenContainer = () => {
2425
const categoryTitles = useBuildCategoryTitles(id, language);
2526
const {validatedStatus, validationResult} = useValidatedStatus(id);
2627
const activeUserId = useUserStore((state) => state.activeUserId);
27-
const localisedData = useFetchLocaliseData(benefitPageData);
28+
const localisedData = useFetchLocaliseData(benefitPageData); // merge this logic with customHints? TODO
29+
const customHints = useFetchCustomBenefitPageHints(benefitPageData);
2830
const xml = useFetchData(`assets/data/xml/${id.split(":")[1]}.xml`);
2931
const targetClass = useFetchTargetClass(id);
3032

@@ -49,6 +51,7 @@ const BenefitPageScreenContainer = () => {
4951
isDesktop={isDesktop}
5052
benefitPageData={benefitPageData}
5153
localisedData={localisedData}
54+
customHints={customHints}
5255
xml={xml}
5356
validatedStatus={validatedStatus}
5457
validationResult={validationResult}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Typography, Box } from '@mui/material';
3+
import { VBox } from '@/ui/shared-components/LayoutBoxes';
4+
import theme from '@/theme';
5+
import WarningAmberIcon from '@mui/icons-material/WarningAmber';
6+
7+
const BenefitPageCustomHints = ({ t, isDesktop, customHints }) => {
8+
return (
9+
<VBox sx={{
10+
backgroundColor: theme.palette.error.light,
11+
color: theme.palette.white.main,
12+
padding: { xs: '12px', md: '16px' },
13+
borderRadius: theme.shape.borderRadius,
14+
gap: 1,
15+
}}>
16+
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
17+
<WarningAmberIcon sx={{ color: theme.palette.black.main }} />
18+
<Typography variant="h3" sx={{ color: theme.palette.black.main }}>
19+
{t ? t('app.benefitPage.customHints.title', 'Important notes') : 'Important notes'}
20+
</Typography>
21+
</Box>
22+
<Box component="ul" sx={{ m: 0, pl: 3, '& li': { color: theme.palette.black.main, mb: 0.5 }}}>
23+
{customHints.map((hint, idx) => (
24+
<Box component="li" key={idx}>
25+
<Typography variant="body1" sx={{ color: theme.palette.black.main }}>
26+
{hint}
27+
</Typography>
28+
</Box>
29+
))}
30+
</Box>
31+
</VBox>
32+
);
33+
}
34+
35+
export default BenefitPageCustomHints;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useMemo } from "react";
2+
import { pickLang } from "@/ui/language/useTranslation";
3+
import { useLanguageStore } from "@/ui/storage/useLanguageStore";
4+
import { useUserStore } from "@/ui/storage/zustand";
5+
import userManager from "@/core/managers/userManager";
6+
7+
export const useFetchCustomBenefitPageHints = (benefitPageData) => {
8+
const language = useLanguageStore(s => s.language);
9+
const activeUserId = useUserStore(s => s.activeUserId);
10+
11+
return useMemo(() => {
12+
if (!activeUserId) return null;
13+
const hints = benefitPageData?.customHints ?? [];
14+
if (!hints.length) return null;
15+
16+
let triggeredHints = [];
17+
for (let hint of hints) {
18+
let isTriggered = true;
19+
for (const [datafield, triggerValue] of Object.entries(hint.pattern)) {
20+
const actualValue = userManager.retrieveUserField(activeUserId, datafield);
21+
if (actualValue === null || actualValue !== triggerValue) isTriggered = false;
22+
}
23+
if (isTriggered) triggeredHints.push(pickLang(hint, language, null));
24+
}
25+
26+
return triggeredHints;
27+
}, [activeUserId, benefitPageData, language]);
28+
};

src/ui/screens/benefit-page/hooks/useFetchStaticBenefitPageData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const useFetchStaticBenefitPageData = (id, language) => {
2727
examplesList : pickLang(resource?.general?.examples, language, null),
2828
applicationProcess: pickLang(resource?.application_process?.brief, language, null),
2929
localisedData: resource?.specific ? resource.specific : null,
30+
customHints: resource?.customHints ? resource.customHints : null,
3031
};
3132
}, [hydrationData, id, language]);
3233

0 commit comments

Comments
 (0)