Handle more types of project add errors

This commit is contained in:
Paul Kaplan 2021-05-17 15:24:51 -04:00
parent b6baedcbab
commit efe961e103
2 changed files with 19 additions and 3 deletions

View file

@ -26,7 +26,11 @@
"studio.projectsEmpty1": "This studio has no projects yet.", "studio.projectsEmpty1": "This studio has no projects yet.",
"studio.projectsEmpty2": "Suggest projects you want to add in the comments!", "studio.projectsEmpty2": "Suggest projects you want to add in the comments!",
"studio.browseProjects": "Browse Projects", "studio.browseProjects": "Browse Projects",
"studio.projectErrors.checkUrl": "Could not add project. Check the URL and try again.", "studio.projectErrors.checkUrl": "Could not find that project. Check the URL and try again.",
"studio.projectErrors.generic": "Could not add project",
"studio.projectErrors.tooFast": "You are adding projects too quickly",
"studio.projectErrors.permission": "You do not have permission to add that project",
"studio.projectErrors.duplicate": "That project is already in this studio",
"studio.creatorRole": "Studio Creator", "studio.creatorRole": "Studio Creator",

View file

@ -5,10 +5,22 @@ import {connect} from 'react-redux';
import classNames from 'classnames'; import classNames from 'classnames';
import {FormattedMessage, intlShape, injectIntl} from 'react-intl'; import {FormattedMessage, intlShape, injectIntl} from 'react-intl';
import {addProject} from './lib/studio-project-actions'; import {Errors, addProject} from './lib/studio-project-actions';
import UserProjectsModal from './modals/user-projects-modal.jsx'; import UserProjectsModal from './modals/user-projects-modal.jsx';
import ValidationMessage from '../../components/forms/validation-message.jsx'; import ValidationMessage from '../../components/forms/validation-message.jsx';
const errorToMessageId = error => {
switch (error) {
case Errors.NETWORK: return 'studio.projectErrors.generic';
case Errors.SERVER: return 'studio.projectErrors.generic';
case Errors.PERMISSION: return 'studio.projectErrors.permission';
case Errors.DUPLICATE: return 'studio.projectErrors.duplicate';
case Errors.RATE_LIMIT: return 'studio.projectErrors.tooFast';
case Errors.UNKNOWN_PROJECT: return 'studio.projectErrors.checkUrl';
default: return 'studio.projectErrors.generic';
}
};
const StudioProjectAdder = ({intl, onSubmit}) => { const StudioProjectAdder = ({intl, onSubmit}) => {
const [value, setValue] = useState(''); const [value, setValue] = useState('');
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
@ -30,7 +42,7 @@ const StudioProjectAdder = ({intl, onSubmit}) => {
<ValidationMessage <ValidationMessage
mode="error" mode="error"
className="validation-left" className="validation-left"
message={<FormattedMessage id="studio.projectErrors.checkUrl" />} message={<FormattedMessage id={errorToMessageId(error)} />}
/> />
</div>} </div>}
<input <input