Skip to content

Commit d420d30

Browse files
committed
front: custom help modal
Signed-off-by: ElysaSrc <[email protected]>
1 parent fbb9361 commit d420d30

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

front/public/locales/en/home/navbar.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"about": "About",
33
"attributions": "Attributions",
44
"disconnect": "Sign out",
5+
"help": "Help",
56
"informations": {
67
"application": "Application",
78
"releaseInformations": "Libraries & licenses",

front/public/locales/fr/home/navbar.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"about": "À propos",
33
"attributions": "Attributions",
44
"disconnect": "Déconnexion",
5+
"help": "Aide",
56
"informations": {
67
"application": "Application",
78
"releaseInformations": "Librairies & licences",

front/src/common/BootstrapSNCF/NavBarSNCF.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { type ReactElement } from 'react';
22

3-
import { Gear, Info, ShieldCheck, SignOut } from '@osrd-project/ui-icons';
3+
import { Gear, Info, Report, ShieldCheck, SignOut } from '@osrd-project/ui-icons';
44
import getUnicodeFlagIcon from 'country-flag-icons/unicode';
55
import i18n from 'i18next';
66
import { useTranslation } from 'react-i18next';
77
import { useSelector } from 'react-redux';
88
import { Link } from 'react-router-dom';
99

1010
import ChangeLanguageModal from 'common/ChangeLanguageModal';
11+
import HelpModal from 'common/HelpModal/HelpModal';
1112
import ReleaseInformations from 'common/ReleaseInformations/ReleaseInformations';
1213
import UserSettings from 'common/UserSettings';
1314
import { getUserSafeWord } from 'reducers/user/userSelectors';
@@ -78,6 +79,17 @@ const LegacyNavBarSNCF = ({ appName, logo = getLogo() }: Props) => {
7879
</span>
7980
{t('about')}
8081
</button>,
82+
<button
83+
type="button"
84+
className="btn-link text-reset"
85+
onClick={() => openModal(<HelpModal />, 'lg')}
86+
key="help"
87+
>
88+
<span className="mr-2">
89+
<Report />
90+
</span>
91+
{t('help')}
92+
</button>,
8193
<button
8294
type="button"
8395
className="btn-link text-reset"
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { useState, useEffect } from 'react';
2+
3+
import { useTranslation } from 'react-i18next';
4+
import ReactMarkdown from 'react-markdown';
5+
import remarkGfm from 'remark-gfm';
6+
7+
import ModalBodySNCF from 'common/BootstrapSNCF/ModalSNCF/ModalBodySNCF';
8+
import ModalHeaderSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalHeaderSNCF';
9+
10+
const DEFAULT_TEXT = '# [email protected]';
11+
12+
const HelpModal = () => {
13+
const { t } = useTranslation('home/navbar');
14+
const [helpModalText, setHelpModalText] = useState<string>('');
15+
16+
useEffect(() => {
17+
const checkHelpMarkdown = async () => {
18+
try {
19+
const response = await fetch('/help.md');
20+
21+
if (!response.ok || response.headers.get('Content-Type') !== 'text/markdown') {
22+
setHelpModalText(DEFAULT_TEXT);
23+
return;
24+
}
25+
26+
setHelpModalText(await response.text());
27+
} catch {
28+
setHelpModalText(DEFAULT_TEXT);
29+
}
30+
};
31+
checkHelpMarkdown();
32+
}, []);
33+
34+
return (
35+
<div className="informations-modal">
36+
<ModalHeaderSNCF withCloseButton>{t('help')}</ModalHeaderSNCF>
37+
<ModalBodySNCF>
38+
<ReactMarkdown remarkPlugins={[remarkGfm]}>{helpModalText}</ReactMarkdown>
39+
</ModalBodySNCF>
40+
</div>
41+
);
42+
};
43+
44+
export default HelpModal;

0 commit comments

Comments
 (0)