import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Select, Typography, Button, HotkeysPreferences } from '@ohif/ui'; import { useTranslation } from 'react-i18next'; const UserPreferences = ({ availableLanguages, defaultLanguage, currentLanguage, disabled, hotkeyDefinitions, hotkeyDefaults, onCancel, onSubmit, onReset }) => { const { t } = useTranslation('UserPreferencesModal'); const [state, setState] = useState({ isDisabled: disabled, hotkeyErrors: {}, hotkeyDefinitions, language: currentLanguage }); const onSubmitHandler = () => { onSubmit(state); }; const onResetHandler = () => { setState(state => ({ ...state, language: defaultLanguage, hotkeyDefinitions: hotkeyDefaults, hotkeyErrors: {}, isDisabled: disabled, })); onReset(); }; const onCancelHandler = () => { setState({ hotkeyDefinitions }); onCancel(); }; const onLanguageChangeHandler = (value) => { setState(state => ({ ...state, language: value })); }; const onHotkeysChangeHandler = (id, definition, errors) => { setState(state => ({ ...state, isDisabled: Object.values(errors).every(e => e !== undefined), hotkeyErrors: errors, hotkeyDefinitions: { ...state.hotkeyDefinitions, [id]: definition, } })); }; const Section = ({ title, children }) => ( <>