Chatwoot/app/javascript/widget/store/modules/conversationAttributes.js
Pranav Raj S f28ec29b8c
Feature: Customise widget for bot conversations (#834)
* Feature: Customise widget for bot conversations
2020-05-09 22:02:43 +05:30

49 lines
963 B
JavaScript

import {
SET_CONVERSATION_ATTRIBUTES,
UPDATE_CONVERSATION_ATTRIBUTES,
} from '../types';
import { getConversationAPI } from '../../api/conversation';
const state = {
id: '',
status: '',
};
export const getters = {
getConversationParams: $state => $state,
};
export const actions = {
get: async ({ commit }) => {
try {
const { data } = await getConversationAPI();
commit(SET_CONVERSATION_ATTRIBUTES, data);
} catch (error) {
// Ignore error
}
},
update({ commit }, data) {
commit(UPDATE_CONVERSATION_ATTRIBUTES, data);
},
};
export const mutations = {
[SET_CONVERSATION_ATTRIBUTES]($state, data) {
$state.id = data.id;
$state.status = data.status;
},
[UPDATE_CONVERSATION_ATTRIBUTES]($state, data) {
if (data.id === $state.id) {
$state.id = data.id;
$state.status = data.status;
}
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};