diff --git a/web/modals/keyserver-selection/add-keyserver-modal.css b/web/modals/keyserver-selection/add-keyserver-modal.css index 6bdaf3900..8e2c1c7a7 100644 --- a/web/modals/keyserver-selection/add-keyserver-modal.css +++ b/web/modals/keyserver-selection/add-keyserver-modal.css @@ -1,17 +1,18 @@ .container { padding: 16px 0; } .inputTitle { color: var(--text-background-primary-default); margin-bottom: 8px; } .button { width: 100%; } .errorMessage { color: var(--text-background-danger-default); margin-top: 8px; + height: 20px; } diff --git a/web/modals/keyserver-selection/add-keyserver-modal.react.js b/web/modals/keyserver-selection/add-keyserver-modal.react.js index 2efdd266e..d507e679b 100644 --- a/web/modals/keyserver-selection/add-keyserver-modal.react.js +++ b/web/modals/keyserver-selection/add-keyserver-modal.react.js @@ -1,134 +1,131 @@ // @flow import * as React from 'react'; import { addKeyserverActionType } from 'lib/actions/keyserver-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js'; import type { KeyserverInfo } from 'lib/types/keyserver-types.js'; import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; import css from './add-keyserver-modal.css'; import Button, { buttonThemes } from '../../components/button.react.js'; import { useSelector } from '../../redux/redux-utils.js'; import { useStaffCanSee } from '../../utils/staff-utils.js'; import Input from '../input.react.js'; import Modal from '../modal.react.js'; function AddKeyserverModal(): React.Node { const { popModal } = useModalContext(); const dispatch = useDispatch(); const staffCanSee = useStaffCanSee(); const currentUserID = useSelector(state => state.currentUserInfo?.id); const customServer = useSelector(state => state.customServer); const [keyserverURL, setKeyserverURL] = React.useState( customServer && staffCanSee ? customServer : '', ); const [showErrorMessage, setShowErrorMessage] = React.useState(false); const onChangeKeyserverURL = React.useCallback( (event: SyntheticEvent) => setKeyserverURL(event.currentTarget.value), [], ); const isKeyserverURLValidCallback = useIsKeyserverURLValid(keyserverURL); const onClickAddKeyserver = React.useCallback(async () => { setShowErrorMessage(false); if (!currentUserID || !keyserverURL) { return; } const keyserverVersionData = await isKeyserverURLValidCallback(); if (!keyserverVersionData) { setShowErrorMessage(true); return; } const newKeyserverInfo: KeyserverInfo = defaultKeyserverInfo(keyserverURL); dispatch({ type: addKeyserverActionType, payload: { keyserverAdminUserID: keyserverVersionData.ownerID, newKeyserverInfo, }, }); popModal(); }, [ currentUserID, dispatch, keyserverURL, popModal, isKeyserverURLValidCallback, ]); const errorMessage = React.useMemo(() => { - if (!showErrorMessage) { - return null; + let errorText; + if (showErrorMessage) { + errorText = + 'Cannot connect to keyserver. Please check the URL or your ' + + 'connection and try again.'; } - - return ( -
- Cannot connect to keyserver. Please check the URL or your connection and - try again. -
- ); + return
{errorText}
; }, [showErrorMessage]); const addKeyserverButton = React.useMemo( () => ( ), [keyserverURL, onClickAddKeyserver], ); const addKeyserverModal = React.useMemo( () => (
Keyserver URL
{errorMessage}
), [ addKeyserverButton, errorMessage, keyserverURL, onChangeKeyserverURL, popModal, ], ); return addKeyserverModal; } export default AddKeyserverModal;