From 4d5d9b320ce2578af26d4193b739c4b381f9d034 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 1 Nov 2022 17:15:18 -0700 Subject: Fix readonly preferences --- modern/src/settings/PreferencesPage.js | 391 +++++++++++++++++---------------- 1 file changed, 199 insertions(+), 192 deletions(-) (limited to 'modern') diff --git a/modern/src/settings/PreferencesPage.js b/modern/src/settings/PreferencesPage.js index 6aad1153..a7115bf8 100644 --- a/modern/src/settings/PreferencesPage.js +++ b/modern/src/settings/PreferencesPage.js @@ -19,6 +19,7 @@ import useMapStyles from '../map/core/useMapStyles'; import useMapOverlays from '../map/overlay/useMapOverlays'; import { useCatch } from '../reactHelper'; import { sessionActions } from '../store'; +import { useRestriction } from '../common/util/permissions'; const deviceFields = [ { id: 'name', name: 'sharedName' }, @@ -60,6 +61,8 @@ const PreferencesPage = () => { const navigate = useNavigate(); const t = useTranslation(); + const readonly = useRestriction('readonly'); + const user = useSelector((state) => state.session.user); const [attributes, setAttributes] = useState(user.attributes); @@ -147,203 +150,207 @@ const PreferencesPage = () => { - - }> - - {t('mapTitle')} - - - - - {t('mapActive')} - - - - {t('mapOverlay')} - - - (positionAttributes.hasOwnProperty(option) ? positionAttributes[option].name : option)} - value={attributes.positionItems?.split(',') || ['speed', 'address', 'totalDistance', 'course']} - onChange={(_, option) => { - setAttributes({ ...attributes, positionItems: option.join(',') }); - }} - filterOptions={(options, params) => { - const filtered = filter(options, params); - if (params.inputValue && !filtered.includes(params.inputValue)) { - filtered.push(params.inputValue); - } - return filtered; - }} - renderInput={(params) => ( - + + }> + + {t('mapTitle')} + + + + + {t('mapActive')} + + + + {t('mapOverlay')} + + + (positionAttributes.hasOwnProperty(option) ? positionAttributes[option].name : option)} + value={attributes.positionItems?.split(',') || ['speed', 'address', 'totalDistance', 'course']} + onChange={(_, option) => { + setAttributes({ ...attributes, positionItems: option.join(',') }); + }} + filterOptions={(options, params) => { + const filtered = filter(options, params); + if (params.inputValue && !filtered.includes(params.inputValue)) { + filtered.push(params.inputValue); + } + return filtered; + }} + renderInput={(params) => ( + + )} /> - )} - /> - - {t('mapLiveRoutes')} - - - - setAttributes({ ...attributes, mapGeofences: e.target.checked })} + + {t('mapLiveRoutes')} + + + + setAttributes({ ...attributes, mapGeofences: e.target.checked })} + /> + )} + label={t('attributeShowGeofences')} /> - )} - label={t('attributeShowGeofences')} - /> - setAttributes({ ...attributes, mapFollow: e.target.checked })} + setAttributes({ ...attributes, mapFollow: e.target.checked })} + /> + )} + label={t('deviceFollow')} /> - )} - label={t('deviceFollow')} - /> - setAttributes({ ...attributes, mapCluster: e.target.checked })} + setAttributes({ ...attributes, mapCluster: e.target.checked })} + /> + )} + label={t('mapClustering')} /> - )} - label={t('mapClustering')} - /> - setAttributes({ ...attributes, mapOnSelect: e.target.checked })} + setAttributes({ ...attributes, mapOnSelect: e.target.checked })} + /> + )} + label={t('mapOnSelect')} /> - )} - label={t('mapOnSelect')} - /> - - - - - }> - - {t('deviceTitle')} - - - - setAttributes({ ...attributes, devicePrimary: e.target.value })} - data={deviceFields} - titleGetter={(it) => t(it.name)} - label={t('devicePrimaryInfo')} - /> - setAttributes({ ...attributes, deviceSecondary: e.target.value })} - data={deviceFields} - titleGetter={(it) => t(it.name)} - label={t('deviceSecondaryInfo')} - /> - - - - }> - - {t('sharedSound')} - - - - setAttributes({ ...attributes, soundEvents: e.target.value.join(',') })} - endpoint="/api/notifications/types" - keyGetter={(it) => it.type} - titleGetter={(it) => t(prefixString('event', it.type))} - label={t('eventsSoundEvents')} - /> - setAttributes({ ...attributes, soundAlarms: e.target.value.join(',') })} - data={alarms} - keyGetter={(it) => it.key} - label={t('eventsSoundAlarms')} - /> - - -
- - -
+ +
+
+ + }> + + {t('deviceTitle')} + + + + setAttributes({ ...attributes, devicePrimary: e.target.value })} + data={deviceFields} + titleGetter={(it) => t(it.name)} + label={t('devicePrimaryInfo')} + /> + setAttributes({ ...attributes, deviceSecondary: e.target.value })} + data={deviceFields} + titleGetter={(it) => t(it.name)} + label={t('deviceSecondaryInfo')} + /> + + + + }> + + {t('sharedSound')} + + + + setAttributes({ ...attributes, soundEvents: e.target.value.join(',') })} + endpoint="/api/notifications/types" + keyGetter={(it) => it.type} + titleGetter={(it) => t(prefixString('event', it.type))} + label={t('eventsSoundEvents')} + /> + setAttributes({ ...attributes, soundAlarms: e.target.value.join(',') })} + data={alarms} + keyGetter={(it) => it.key} + label={t('eventsSoundAlarms')} + /> + + +
+ + +
+ + )} ); -- cgit v1.2.3