mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Show server error in notification if one is given for failed piece registrations
This commit is contained in:
parent
1b4c6938f6
commit
ad17a9d6f3
@ -19,8 +19,9 @@ import ApiUrls from '../../../../../../constants/api_urls';
|
|||||||
|
|
||||||
import requests from '../../../../../../utils/requests';
|
import requests from '../../../../../../utils/requests';
|
||||||
|
|
||||||
import { getLangText } from '../../../../../../utils/lang_utils';
|
import { getErrorNotificationMessage } from '../../../../../../utils/error_utils';
|
||||||
import { setCookie } from '../../../../../../utils/fetch_api_utils';
|
import { setCookie } from '../../../../../../utils/fetch_api_utils';
|
||||||
|
import { getLangText } from '../../../../../../utils/lang_utils';
|
||||||
import { formSubmissionValidation } from '../../../../../ascribe_uploader/react_s3_fine_uploader_utils';
|
import { formSubmissionValidation } from '../../../../../ascribe_uploader/react_s3_fine_uploader_utils';
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
|
|
||||||
mixins: [History],
|
mixins: [History],
|
||||||
|
|
||||||
getInitialState(){
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
digitalWorkKeyReady: true,
|
digitalWorkKeyReady: true,
|
||||||
thumbnailKeyReady: true,
|
thumbnailKeyReady: true,
|
||||||
@ -56,14 +57,14 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
submit() {
|
submit() {
|
||||||
if(!this.validateForms()) {
|
if(!this.validateForms()) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
// disable the submission button right after the user
|
|
||||||
// clicks on it to avoid double submission
|
|
||||||
this.setState({
|
|
||||||
submitted: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disable the submission button right after the user
|
||||||
|
// clicks on it to avoid double submission
|
||||||
|
this.setState({
|
||||||
|
submitted: true
|
||||||
|
});
|
||||||
|
|
||||||
const { currentUser } = this.props;
|
const { currentUser } = this.props;
|
||||||
const { registerPieceForm,
|
const { registerPieceForm,
|
||||||
additionalDataForm,
|
additionalDataForm,
|
||||||
@ -106,10 +107,18 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
})
|
})
|
||||||
.then(() => this.history.pushState(null, `/pieces/${this.state.piece.id}`))
|
.then(() => this.history.pushState(null, `/pieces/${this.state.piece.id}`))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const notificationMessage = new GlobalNotificationModel(getLangText("Oops! We weren't able to send your submission. Contact: support@ascribe.io"), 'danger', 5000);
|
const errMessage = (getErrorNotificationMessage(err) || getLangText("Oops! We weren't able to send your submission.")) +
|
||||||
|
getLangText(' Please contact support@ascribe.io');
|
||||||
|
|
||||||
|
const notificationMessage = new GlobalNotificationModel(errMessage, 'danger', 10000);
|
||||||
GlobalNotificationActions.appendGlobalNotification(notificationMessage);
|
GlobalNotificationActions.appendGlobalNotification(notificationMessage);
|
||||||
|
|
||||||
console.logGlobal(new Error('Portfolio Review piece registration failed'), err);
|
console.logGlobal(new Error('Portfolio Review piece registration failed'), err);
|
||||||
|
|
||||||
|
// Reset the submit button
|
||||||
|
this.setState({
|
||||||
|
submitted: false
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -35,3 +35,31 @@ export function initLogging() {
|
|||||||
|
|
||||||
console.logGlobal = logGlobal;
|
console.logGlobal = logGlobal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets the json errors from the error as an array
|
||||||
|
* @param {Error} error A Javascript error
|
||||||
|
* @return {Array} List of json errors
|
||||||
|
*/
|
||||||
|
export function getJsonErrorsAsArray(error) {
|
||||||
|
const { json: { errors = {} } = {} } = error;
|
||||||
|
|
||||||
|
const errorArrays = Object
|
||||||
|
.keys(errors)
|
||||||
|
.map((errorKey) => {
|
||||||
|
return errors[errorKey];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Collapse each errorKey's errors into a flat array
|
||||||
|
return [].concat(...errorArrays);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tries to get an error message from the error, either by using its notification
|
||||||
|
* property or first json error (if any)
|
||||||
|
* @param {Error} error A Javascript error
|
||||||
|
* @return {string} Error message string
|
||||||
|
*/
|
||||||
|
export function getErrorNotificationMessage(error) {
|
||||||
|
return (error && error.notification) || getJsonErrorsAsArray(error)[0] || '';
|
||||||
|
}
|
||||||
|
@ -84,8 +84,6 @@ export function formatText() {
|
|||||||
* Checks a list of objects for key duplicates and returns a boolean
|
* Checks a list of objects for key duplicates and returns a boolean
|
||||||
*/
|
*/
|
||||||
function _doesObjectListHaveDuplicates(l) {
|
function _doesObjectListHaveDuplicates(l) {
|
||||||
let mergedList = [];
|
|
||||||
|
|
||||||
l = l.map((obj) => {
|
l = l.map((obj) => {
|
||||||
if(!obj) {
|
if(!obj) {
|
||||||
throw new Error('The object you are trying to merge is null instead of an empty object');
|
throw new Error('The object you are trying to merge is null instead of an empty object');
|
||||||
@ -94,11 +92,11 @@ function _doesObjectListHaveDuplicates(l) {
|
|||||||
return Object.keys(obj);
|
return Object.keys(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Taken from: http://stackoverflow.com/a/10865042
|
// Taken from: http://stackoverflow.com/a/10865042 (but even better with rest)
|
||||||
// How to flatten an array of arrays in javascript.
|
// How to flatten an array of arrays in javascript.
|
||||||
// If two objects contain the same key, then these two keys
|
// If two objects contain the same key, then these two keys
|
||||||
// will actually be represented in the merged array
|
// will actually be represented in the merged array
|
||||||
mergedList = mergedList.concat.apply(mergedList, l);
|
let mergedList = [].concat(...l);
|
||||||
|
|
||||||
// Taken from: http://stackoverflow.com/a/7376645/1263876
|
// Taken from: http://stackoverflow.com/a/7376645/1263876
|
||||||
// By casting the array to a set, and then checking if the size of the array
|
// By casting the array to a set, and then checking if the size of the array
|
||||||
|
Loading…
Reference in New Issue
Block a user