HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/assets/vue/widgets/CommWidget/store/message/actions.js
import {
  MESSAGE_ACTION_SEND_MESSAGE,
  MESSAGE_ACTION_RESET_STATE,
  MESSAGE_MUTATION_RESET,
  MESSAGE_MUTATION_SET_SEND_MESSAGE_API_LOADING_STATUS,
  MESSAGE_MUTATION_SET_SEND_MESSAGE_API_ERROR_MESSAGE,
  MESSAGE_SUCCESSFULLY_SEND,
  ROOT_ACTION_RESET_STATE,
} from '../../constants';

import ExternalWidgetService from '../../../../service/externalWidgetService';
import _ from 'lodash';

export default {
  [MESSAGE_ACTION_RESET_STATE]({ commit, dispatch }) {
    commit(MESSAGE_MUTATION_RESET);
  },
  async [MESSAGE_ACTION_SEND_MESSAGE]({ commit, dispatch }, payload) {
    commit(MESSAGE_MUTATION_SET_SEND_MESSAGE_API_LOADING_STATUS, true);
    const {
      data: { success, message },
    } = await ExternalWidgetService.sendMessage(
      { ..._.omit(payload, 'widgetId') },
      payload.widgetId,
    );
    if (success) {
      commit(MESSAGE_SUCCESSFULLY_SEND);
      setTimeout(() => {
        dispatch(`root/${ROOT_ACTION_RESET_STATE}`, null, {
          root: true,
        });
      }, 3000);
    } else {
      commit(MESSAGE_MUTATION_SET_SEND_MESSAGE_API_ERROR_MESSAGE, message);
    }
    commit(MESSAGE_MUTATION_SET_SEND_MESSAGE_API_LOADING_STATUS, false);
  },
};