Files
chatwoot/app/javascript/dashboard/store/captain/bulkActions.js
Sivin Varghese 6eecd84b22 feat: Add support for bulk action for Captain FAQs (#10905)
Co-authored-by: Pranav <pranav@chatwoot.com>
Co-authored-by: Pranav <pranavrajs@gmail.com>
2025-02-27 17:05:33 -08:00

57 lines
1.7 KiB
JavaScript

import CaptainBulkActionsAPI from 'dashboard/api/captain/bulkActions';
import { createStore } from './storeFactory';
import { throwErrorMessage } from 'dashboard/store/utils/api';
export default createStore({
name: 'CaptainBulkAction',
API: CaptainBulkActionsAPI,
actions: mutations => ({
processBulkAction: async function processBulkAction(
{ commit },
{ type, actionType, ids }
) {
commit(mutations.SET_UI_FLAG, { isUpdating: true });
try {
const response = await CaptainBulkActionsAPI.create({
type: type,
ids,
fields: { status: actionType },
});
commit(mutations.SET_UI_FLAG, { isUpdating: false });
return response.data;
} catch (error) {
commit(mutations.SET_UI_FLAG, { isUpdating: false });
return throwErrorMessage(error);
}
},
handleBulkDelete: async function handleBulkDelete({ dispatch }, ids) {
const response = await dispatch('processBulkAction', {
type: 'AssistantResponse',
actionType: 'delete',
ids,
});
// Update the response store after successful API call
await dispatch('captainResponses/removeBulkResponses', ids, {
root: true,
});
return response;
},
handleBulkApprove: async function handleBulkApprove({ dispatch }, ids) {
const response = await dispatch('processBulkAction', {
type: 'AssistantResponse',
actionType: 'approve',
ids,
});
// Update response store after successful API call
await dispatch('captainResponses/updateBulkResponses', response, {
root: true,
});
return response;
},
}),
});