Commit 5ba6bb83 authored by Eric Rosenbaum's avatar Eric Rosenbaum

hide validation on click outside for description

parent b0a9bab7
...@@ -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 {selectStudioDescription, selectIsFetchingInfo} from '../../redux/studio'; import {selectStudioDescription, selectIsFetchingInfo} from '../../redux/studio';
import {selectCanEditInfo, selectShowEditMuteError} from '../../redux/studio-permissions'; import {selectCanEditInfo, selectShowEditMuteError} from '../../redux/studio-permissions';
...@@ -28,6 +29,11 @@ const StudioDescription = ({ ...@@ -28,6 +29,11 @@ const StudioDescription = ({
descriptionError, isFetching, isMutating, isMutedEditor, description, canEditInfo, handleUpdate descriptionError, isFetching, isMutating, isMutedEditor, description, canEditInfo, handleUpdate
}) => { }) => {
const [showMuteMessage, setShowMuteMessage] = useState(false); const [showMuteMessage, setShowMuteMessage] = useState(false);
const [hideValidationMessage, setHideValidationMessage] = useState(false);
StudioDescription.handleClickOutside = () => {
setHideValidationMessage(true);
};
const fieldClassName = classNames('studio-description', { const fieldClassName = classNames('studio-description', {
'mod-fetching': isFetching, 'mod-fetching': isFetching,
...@@ -49,10 +55,12 @@ const StudioDescription = ({ ...@@ -49,10 +55,12 @@ const StudioDescription = ({
className={fieldClassName} className={fieldClassName}
disabled={isMutating || isFetching || isMutedEditor} disabled={isMutating || isFetching || isMutedEditor}
defaultValue={description} defaultValue={description}
onBlur={e => e.target.value !== description && onBlur={e => {
handleUpdate(e.target.value)} if (e.target.value !== description) handleUpdate(e.target.value);
setHideValidationMessage(false);
}}
/> />
{descriptionError && <ValidationMessage {descriptionError && !hideValidationMessage && <ValidationMessage
mode="error" mode="error"
message={<FormattedMessage id={errorToMessageId(descriptionError)} />} message={<FormattedMessage id={errorToMessageId(descriptionError)} />}
/>} />}
...@@ -71,6 +79,10 @@ const StudioDescription = ({ ...@@ -71,6 +79,10 @@ const StudioDescription = ({
); );
}; };
const clickOutsideConfig = {
handleClickOutside: () => StudioDescription.handleClickOutside
};
StudioDescription.propTypes = { StudioDescription.propTypes = {
descriptionError: PropTypes.string, descriptionError: PropTypes.string,
canEditInfo: PropTypes.bool, canEditInfo: PropTypes.bool,
...@@ -81,7 +93,7 @@ StudioDescription.propTypes = { ...@@ -81,7 +93,7 @@ StudioDescription.propTypes = {
handleUpdate: PropTypes.func handleUpdate: PropTypes.func
}; };
export default connect( const connectedStudioDescription = connect(
state => ({ state => ({
description: selectStudioDescription(state), description: selectStudioDescription(state),
canEditInfo: selectCanEditInfo(state), canEditInfo: selectCanEditInfo(state),
...@@ -94,3 +106,5 @@ export default connect( ...@@ -94,3 +106,5 @@ export default connect(
handleUpdate: mutateStudioDescription handleUpdate: mutateStudioDescription
} }
)(StudioDescription); )(StudioDescription);
export default onClickOutside(connectedStudioDescription, 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