-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathUserSettings.tsx
88 lines (80 loc) · 3.03 KB
/
UserSettings.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { useEffect, useState } from 'react';
import { Gear, ShieldCheck } from '@osrd-project/ui-icons';
import cx from 'classnames';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import { ModalBodySNCF, ModalHeaderSNCF } from 'common/BootstrapSNCF/ModalSNCF';
import { updateUserPreferences } from 'reducers/user';
import { getIsSuperUser, getUserPreferences } from 'reducers/user/userSelectors';
import { useAppDispatch } from 'store';
import { useDebounce } from 'utils/helpers';
import SwitchSNCF from './BootstrapSNCF/SwitchSNCF/SwitchSNCF';
const UserSettings = () => {
const userPreferences = useSelector(getUserPreferences);
const [safeWordText, setSafeWordText] = useState(userPreferences.safeWord);
const dispatch = useAppDispatch();
const isSuperUser = useSelector(getIsSuperUser);
const debouncedSafeWord = useDebounce(safeWordText, 500);
useEffect(() => {
dispatch(updateUserPreferences({ ...userPreferences, safeWord: debouncedSafeWord }));
}, [debouncedSafeWord]);
const { t } = useTranslation(['home/navbar', 'operationalStudies/scenario']);
return (
<>
<ModalHeaderSNCF withCloseButton>
<h1 className="d-flex align-items-center">
<Gear variant="fill" size="lg" />
<span className="ml-2">{t('userSettings')}</span>
</h1>
</ModalHeaderSNCF>
<ModalBodySNCF>
<InputSNCF
id="safe-word-input"
label={t('safeWord')}
clearButton
onClear={() => {
dispatch(updateUserPreferences({ ...userPreferences, safeWord: '' }));
setSafeWordText('');
}}
placeholder={t('yourSafeWord')}
onChange={(e) => setSafeWordText(e.target.value)}
value={safeWordText}
type="text"
noMargin
unit={
<span className={cx('lead', safeWordText !== '' && 'text-success')}>
<ShieldCheck />
</span>
}
/>
<small id="safeWordHelpBlock" className="form-text text-muted">
{t('safeWordHelp')}
</small>
{
// TODO PACEDTRAIN: Remove switch after development pacedTrain feature
isSuperUser && (
<div className="d-flex align-items-center mt-2">
<SwitchSNCF
id="paced-train-switch"
type="switch"
name={t('operationalStudies/scenario:pacedTrain.pacedTrain')}
checked={userPreferences.showPacedTrains}
onChange={() =>
dispatch(
updateUserPreferences({
...userPreferences,
showPacedTrains: !userPreferences.showPacedTrains,
})
)
}
/>
<div className="ml-2">{t('operationalStudies/scenario:pacedTrain.pacedTrain')}</div>
</div>
)
}
</ModalBodySNCF>
</>
);
};
export default UserSettings;