feat: add handler for actions
Takes care of dispatching a 🍞 on success/error
This commit is contained in:
parent
746a454612
commit
704578e964
|
@ -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;
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue