Replace debug error on StudioFollow

This commit is contained in:
Paul Kaplan 2021-06-18 11:27:00 -04:00
parent 4c2b588926
commit fa8aff5837
3 changed files with 37 additions and 8 deletions

View file

@ -18,6 +18,9 @@
"studio.updateErrors.thumbnailTooLarge": "Maximum file size is 512 KB and less than 500x500 pixels.",
"studio.updateErrors.thumbnailInvalid": "Upload a valid image. The file you uploaded was either not an image or a corrupted image.",
"studio.followErrors.confirmEmail": "Please confirm your email address first",
"studio.followErrors.generic": "Something went wrong following the studio",
"studio.projectsHeader": "Projects",
"studio.addProjectsHeader": "Add Projects",
"studio.addProject": "Add",

View file

@ -1,15 +1,24 @@
/* eslint-disable react/jsx-no-bind */
import React from 'react';
import React, {useState} from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import {FormattedMessage} from 'react-intl';
import onClickOutside from 'react-onclickoutside';
import {selectIsFollowing} from '../../redux/studio';
import {selectCanFollowStudio} from '../../redux/studio-permissions';
import {
mutateFollowingStudio, selectIsMutatingFollowing, selectFollowingMutationError
mutateFollowingStudio, selectIsMutatingFollowing, selectFollowingMutationError, Errors
} from '../../redux/studio-mutations';
import classNames from 'classnames';
import ValidationMessage from '../../components/forms/validation-message.jsx';
const errorToMessageId = error => {
switch (error) {
case Errors.PERMISSION: return 'studio.followErrors.confirmEmail';
default: return 'studio.followErrors.generic';
}
};
const StudioFollow = ({
canFollow,
@ -18,16 +27,24 @@ const StudioFollow = ({
followingError,
handleFollow
}) => {
if (!canFollow) return null;
const fieldClassName = classNames('button', 'studio-follow-button', {
'mod-mutating': isMutating
});
const [hideValidationMessage, setHideValidationMessage] = useState(false);
StudioFollow.handleClickOutside = () => {
setHideValidationMessage(true);
};
if (!canFollow) return null;
return (
<React.Fragment>
<div className="studio-info-section">
<button
className={fieldClassName}
disabled={isMutating}
onClick={() => handleFollow(!isFollowing)}
onClick={() => {
setHideValidationMessage(false);
handleFollow(!isFollowing);
}}
>
{isMutating ? '...' : (
isFollowing ?
@ -35,8 +52,11 @@ const StudioFollow = ({
<FormattedMessage id="studio.followStudio" />
)}
</button>
{followingError && <div>Error mutating following: {followingError}</div>}
</React.Fragment >
{followingError && !hideValidationMessage && <ValidationMessage
mode="error"
message={<FormattedMessage id={errorToMessageId(followingError)} />}
/>}
</div>
);
};
@ -48,6 +68,10 @@ StudioFollow.propTypes = {
handleFollow: PropTypes.func
};
const clickOutsideConfig = {
handleClickOutside: () => StudioFollow.handleClickOutside
};
export default connect(
state => ({
canFollow: selectCanFollowStudio(state),
@ -58,4 +82,4 @@ export default connect(
{
handleFollow: mutateFollowingStudio
}
)(StudioFollow);
)(onClickOutside(StudioFollow, clickOutsideConfig));

View file

@ -169,6 +169,8 @@ $radius: 8px;
padding-bottom: 14px;
font-size: 14px;
margin: 0;
width: 100%;
box-sizing: border-box;
}
}