feat: add handler for actions

Takes care of dispatching a 🍞 on success/error
This commit is contained in:
Zephyrrus 2020-07-09 02:22:48 +03:00
parent 746a454612
commit 704578e964
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import AlertTypes from '~/constants/alertTypes';
export default ({ store }, inject) => {
inject('handler', {
async executeAction(action, param) {
try {
const response = await store.dispatch(action, param);
store.commit('alert/set', {
message: response?.message ?? 'Executed sucesfully',
type: AlertTypes.SUCCESS,
});
return response;
} catch (e) {
store.commit('alert/set', {
message: e.message,
type: AlertTypes.ERROR,
});
return null;
}
},
});
};