I want to loop over a array with object through a function to create per object a call through store dispatch.
const action = [{ action: 'FILE_CREATE'}, {action: 'MEDIA_CREATE}]
Call the function:
saveComponent(action)
Function
const saveComponent = async (actions, actionOption, redirect, reload) => {
await Promise.all(actions.map(obj =>
store.dispatch(Actions[obj.action]).then(() => {
console.log(obj.action + ' test ')
}).catch((error) => {
Swal.fire({
text: "Sorry, looks like there are some errors detected, please try again.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary",
},
});
return false;
}).finally(() => {
loading.value = false;
})
));
}
The error on console I get is the following: Uncaught (in promise) Error: [vuex] expects string as the type, but found undefined. which results on the following line: store.dispatch(Actions[obj.action])
If I delete the store.dispatch function, and replace it with: console.log(obj.action) it shows the correct data. Also if I just create one store.dispatch function without the Promise.all. It does work. The actions are registered and working fully.
What am I doing wrong?