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.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.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.projectsHeader": "Projects",
"studio.addProjectsHeader": "Add Projects", "studio.addProjectsHeader": "Add Projects",
"studio.addProject": "Add", "studio.addProject": "Add",

View file

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

View file

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