Commit 6af78c45 authored by Eric Rosenbaum's avatar Eric Rosenbaum

hide validation message on click outside

parent 82ef1747
...@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; ...@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import classNames from 'classnames'; import classNames from 'classnames';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import onClickOutside from 'react-onclickoutside';
import {selectStudioTitle, selectIsFetchingInfo} from '../../redux/studio'; import {selectStudioTitle, selectIsFetchingInfo} from '../../redux/studio';
import {selectCanEditInfo, selectShowEditMuteError} from '../../redux/studio-permissions'; import {selectCanEditInfo, selectShowEditMuteError} from '../../redux/studio-permissions';
...@@ -31,6 +32,11 @@ const StudioTitle = ({ ...@@ -31,6 +32,11 @@ const StudioTitle = ({
}); });
const [showMuteMessage, setShowMuteMessage] = useState(false); const [showMuteMessage, setShowMuteMessage] = useState(false);
const [hideValidationMessage, setHideValidationMessage] = useState(false);
StudioTitle.handleClickOutside = () => {
setHideValidationMessage(true);
};
return ( return (
<div <div
...@@ -45,10 +51,12 @@ const StudioTitle = ({ ...@@ -45,10 +51,12 @@ const StudioTitle = ({
disabled={isMutating || !canEditInfo || isFetching} disabled={isMutating || !canEditInfo || isFetching}
defaultValue={title} defaultValue={title}
onKeyDown={e => e.key === 'Enter' && e.target.blur()} onKeyDown={e => e.key === 'Enter' && e.target.blur()}
onBlur={e => e.target.value !== title && onBlur={e => {
handleUpdate(e.target.value)} if (e.target.value !== title) handleUpdate(e.target.value);
setHideValidationMessage(false);
}}
/> />
{titleError && <ValidationMessage {titleError && !hideValidationMessage && <ValidationMessage
mode="error" mode="error"
message={<FormattedMessage id={errorToMessageId(titleError)} />} message={<FormattedMessage id={errorToMessageId(titleError)} />}
/>} />}
...@@ -61,6 +69,10 @@ const StudioTitle = ({ ...@@ -61,6 +69,10 @@ const StudioTitle = ({
); );
}; };
const clickOutsideConfig = {
handleClickOutside: () => StudioTitle.handleClickOutside
};
StudioTitle.propTypes = { StudioTitle.propTypes = {
titleError: PropTypes.string, titleError: PropTypes.string,
canEditInfo: PropTypes.bool, canEditInfo: PropTypes.bool,
...@@ -71,7 +83,7 @@ StudioTitle.propTypes = { ...@@ -71,7 +83,7 @@ StudioTitle.propTypes = {
handleUpdate: PropTypes.func handleUpdate: PropTypes.func
}; };
export default connect( export default onClickOutside(connect(
state => ({ state => ({
title: selectStudioTitle(state), title: selectStudioTitle(state),
canEditInfo: selectCanEditInfo(state), canEditInfo: selectCanEditInfo(state),
...@@ -83,4 +95,4 @@ export default connect( ...@@ -83,4 +95,4 @@ export default connect(
{ {
handleUpdate: mutateStudioTitle handleUpdate: mutateStudioTitle
} }
)(StudioTitle); )(StudioTitle), clickOutsideConfig);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment