Unverified Commit 05b3a062 authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub

Merge pull request #5670 from paulkaplan/show-rate-limit-error-correctly

parents 07c7ab81 b2c9c922
...@@ -3,6 +3,7 @@ import React, {useContext, useState} from 'react'; ...@@ -3,6 +3,7 @@ import React, {useContext, useState} from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import AlertContext from '../../../components/alert/alert-context.js'; import AlertContext from '../../../components/alert/alert-context.js';
import {errorToMessageId} from '../studio-project-adder.jsx';
const UserProjectsTile = ({id, title, image, inStudio, onAdd, onRemove}) => { const UserProjectsTile = ({id, title, image, inStudio, onAdd, onRemove}) => {
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
...@@ -10,17 +11,19 @@ const UserProjectsTile = ({id, title, image, inStudio, onAdd, onRemove}) => { ...@@ -10,17 +11,19 @@ const UserProjectsTile = ({id, title, image, inStudio, onAdd, onRemove}) => {
const {errorAlert} = useContext(AlertContext); const {errorAlert} = useContext(AlertContext);
const toggle = () => { const toggle = () => {
setSubmitting(true); setSubmitting(true);
(added ? onRemove(id) : onAdd(id)) const adding = !added; // for clarity, the current action is opposite of previous state
(adding ? onAdd(id) : onRemove(id))
.then(() => { .then(() => {
setAdded(!added); setAdded(adding);
setSubmitting(false); setSubmitting(false);
}) })
.catch(() => { .catch(e => {
// if adding, use the same error messages as the add-by-url component
// otherwise use a single generic message for remove errors
const errorId = adding ? errorToMessageId(e) :
'studio.alertProjectRemoveError';
setSubmitting(false); setSubmitting(false);
errorAlert({ errorAlert({id: errorId}, null);
id: added ? 'studio.alertProjectRemoveError' :
'studio.alertProjectAddError'
}, null);
}); });
}; };
return ( return (
......
...@@ -103,3 +103,5 @@ const mapDispatchToProps = ({ ...@@ -103,3 +103,5 @@ const mapDispatchToProps = ({
}); });
export default connect(mapStateToProps, mapDispatchToProps)(StudioProjectAdder); export default connect(mapStateToProps, mapDispatchToProps)(StudioProjectAdder);
export {errorToMessageId};
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