import React, { FocusEvent, useCallback, useState } from 'react'; import { useDispatch } from 'react-redux'; import * as commandNames from 'Commands/commandNames'; import FieldSet from 'Components/FieldSet'; import FormGroup from 'Components/Form/FormGroup'; import FormInputButton from 'Components/Form/FormInputButton'; import FormInputGroup from 'Components/Form/FormInputGroup'; import FormLabel from 'Components/Form/FormLabel'; import { EnhancedSelectInputValue } from 'Components/Form/Select/EnhancedSelectInput'; import Icon from 'Components/Icon'; import ClipboardButton from 'Components/Link/ClipboardButton'; import ConfirmModal from 'Components/Modal/ConfirmModal'; import { icons, inputTypes, kinds } from 'Helpers/Props'; import { executeCommand } from 'Store/Actions/commandActions'; import { InputChanged } from 'typings/inputs'; import { PendingSection } from 'typings/pending'; import General from 'typings/Settings/General'; import translate from 'Utilities/String/translate'; export const authenticationMethodOptions: EnhancedSelectInputValue[] = [ { key: 'none', get value() { return translate('None'); }, isDisabled: true, }, { key: 'external', get value() { return translate('External'); }, isHidden: true, }, { key: 'basic', get value() { return translate('AuthBasic'); }, isDisabled: true, isHidden: true, }, { key: 'forms', get value() { return translate('AuthForm'); }, }, ]; export const authenticationRequiredOptions: EnhancedSelectInputValue[] = [ { key: 'enabled', get value() { return translate('Enabled'); }, }, { key: 'disabledForLocalAddresses', get value() { return translate('DisabledForLocalAddresses'); }, }, ]; const certificateValidationOptions: EnhancedSelectInputValue[] = [ { key: 'enabled', get value() { return translate('Enabled'); }, }, { key: 'disabledForLocalAddresses', get value() { return translate('DisabledForLocalAddresses'); }, }, { key: 'disabled', get value() { return translate('Disabled'); }, }, ]; interface SecuritySettingsProps { authenticationMethod: PendingSection['authenticationMethod']; authenticationRequired: PendingSection['authenticationRequired']; username: PendingSection['username']; password: PendingSection['password']; passwordConfirmation: PendingSection['passwordConfirmation']; apiKey: PendingSection['apiKey']; certificateValidation: PendingSection['certificateValidation']; isResettingApiKey: boolean; onInputChange: (change: InputChanged) => void; } function SecuritySettings({ authenticationMethod, authenticationRequired, username, password, passwordConfirmation, apiKey, certificateValidation, isResettingApiKey, onInputChange, }: SecuritySettingsProps) { const dispatch = useDispatch(); const [isConfirmApiKeyResetModalOpen, setIsConfirmApiKeyResetModalOpen] = useState(false); const handleApikeyFocus = useCallback( (event: FocusEvent) => { event.target.select(); }, [] ); const handleResetApiKeyPress = useCallback(() => { setIsConfirmApiKeyResetModalOpen(true); }, []); const handleConfirmResetApiKey = useCallback(() => { setIsConfirmApiKeyResetModalOpen(false); dispatch(executeCommand({ name: commandNames.RESET_API_KEY })); }, [dispatch]); const handleCloseResetApiKeyModal = useCallback(() => { setIsConfirmApiKeyResetModalOpen(false); }, []); // createCommandExecutingSelector(commandNames.RESET_API_KEY), const authenticationEnabled = authenticationMethod && authenticationMethod.value !== 'none'; return (
{translate('Authentication')} {authenticationEnabled ? ( {translate('AuthenticationRequired')} ) : null} {authenticationEnabled ? ( {translate('Username')} ) : null} {authenticationEnabled ? ( {translate('Password')} ) : null} {authenticationEnabled ? ( {translate('PasswordConfirmation')} ) : null} {translate('ApiKey')} , , ]} onChange={onInputChange} onFocus={handleApikeyFocus} {...apiKey} /> {translate('CertificateValidation')}
); } export default SecuritySettings;