Adds snackbar to success and error situations from collectionPresets

This commit is contained in:
mateuswetah 2022-10-20 10:08:00 -03:00
parent b3d659e3f5
commit d70e471002
2 changed files with 39 additions and 4 deletions

View File

@ -91,6 +91,11 @@
:active.sync="isLoadingMetadatumMappers"
:can-cancel="false"/>
<b-loading
:is-full-page="false"
:active.sync="isCreatingCollectionPreset"
:can-cancel="false"/>
<footer class="field is-grouped form-submit">
<div class="control">
<button
@ -106,6 +111,7 @@
<script>
import { mapActions, mapGetters } from 'vuex';
import axios from 'axios';
import { tainacanErrorHandler } from '../../js/axios';
export default {
name: 'CollectionCreationModal',
@ -113,7 +119,8 @@ export default {
return {
selectedEstrategy: 'mappers',
isLoadingMetadatumMappers: true,
collectionPresets: []
collectionPresets: [],
isCreatingCollectionPreset: false
}
},
computed: {
@ -163,13 +170,41 @@ export default {
'getMetadatumMappers'
]),
onNewCollectionPreset(collectionPreset) {
this.isCreatingCollectionPreset = true;
axios.post(collectionPreset.endpoint)
.then(() => {
if (typeof collectionPreset.onSuccess === 'function') {
const successMessage = collectionPreset.onSuccess();
this.$buefy.snackbar.open({
message: successMessage,
type: 'is-secondary',
position: 'is-bottom-right',
pauseOnHover: true,
duration: 3500,
queue: false
});
}
this.isCreatingCollectionPreset = false;
this.$router.push(this.$routerHelper.getCollectionsPath());
this.$parent.close();
})
.catch((error) =>{
this.$console.error(error);
if (typeof collectionPreset.onError === 'function') {
const errorMessage = collectionPreset.onError();
this.$buefy.snackbar.open({
message: errorMessage,
type: 'is-danger',
position: 'is-bottom-right',
pauseOnHover: true,
duration: 3500,
queue: false
});
} else {
tainacanErrorHandler(error);
}
this.isCreatingCollectionPreset = false;
});
}
}

View File

@ -9,7 +9,7 @@ const i18nGet = function (key) {
return (string !== undefined && string !== null && string !== '' ) ? string : "ERROR: Invalid i18n key!";
};
const tainacanErrorHandler = function(error) {
export const tainacanErrorHandler = function(error) {
console.error(error)
if (error.response && error.response.status) {
// The request was made and the server responded with a status code
@ -106,4 +106,4 @@ export const CancelToken = axios.CancelToken;
export const isCancel = axios.isCancel;
export const all = axios.all;
export default { tainacan, wp, CancelToken, isCancel, all};
export default { tainacan, wp, CancelToken, isCancel, all, tainacanErrorHandler};