Merge pull request #5013 from betagouv/auto-upload-fix-retry
Usager : améliorations sur le bouton "Réessayer l'envoi" des pièces justificatives
This commit is contained in:
commit
b290564df2
3 changed files with 16 additions and 5 deletions
|
@ -93,7 +93,18 @@ export default class AutoUploadController {
|
||||||
this.input.disabled = false;
|
this.input.disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isError422(error) {
|
||||||
|
// Ajax errors have an xhr attribute
|
||||||
|
if (error && error.xhr && error.xhr.status == 422) return true;
|
||||||
|
// Rails DirectUpload errors are returned as a String, e.g. 'Error creating Blob for "Demain.txt". Status: 422'
|
||||||
|
if (error && error.toString().includes('422')) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_messageFromError(error) {
|
_messageFromError(error) {
|
||||||
|
let allowRetry = !this._isError422(error);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
error.xhr &&
|
error.xhr &&
|
||||||
error.xhr.status == 422 &&
|
error.xhr.status == 422 &&
|
||||||
|
@ -104,13 +115,13 @@ export default class AutoUploadController {
|
||||||
return {
|
return {
|
||||||
title: error.response.errors[0],
|
title: error.response.errors[0],
|
||||||
description: '',
|
description: '',
|
||||||
retry: false
|
retry: allowRetry
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
title: 'Une erreur s’est produite pendant l’envoi du fichier.',
|
title: 'Une erreur s’est produite pendant l’envoi du fichier.',
|
||||||
description: error.message || error.toString(),
|
description: error.message || error.toString(),
|
||||||
retry: true
|
retry: allowRetry
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ delegate('change', fileInputSelector, event => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const retryButtonSelector = `button.attachment-error-retry`;
|
const retryButtonSelector = `button.attachment-error-retry`;
|
||||||
delegate('click', retryButtonSelector, event => {
|
delegate('click', retryButtonSelector, function() {
|
||||||
const inputSelector = event.target.dataset.inputTarget;
|
const inputSelector = this.dataset.inputTarget;
|
||||||
const input = document.querySelector(inputSelector);
|
const input = document.querySelector(inputSelector);
|
||||||
startUpload(input);
|
startUpload(input);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
try {
|
try {
|
||||||
window.scroll({ top: 0, left: 0, behavior: 'smooth' });
|
window.scroll({ top: 0, left: 0, behavior: 'smooth' });
|
||||||
} catch {
|
} catch(e) {
|
||||||
window.scroll(0, 0);
|
window.scroll(0, 0);
|
||||||
}
|
}
|
||||||
<%= remove_element('#user-satisfaction') %>
|
<%= remove_element('#user-satisfaction') %>
|
||||||
|
|
Loading…
Reference in a new issue