mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-30 18:47:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			78 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import Vue from 'vue';
 | |
| import * as types from '../mutation-types';
 | |
| import UserNotificationSettings from '../../api/userNotificationSettings';
 | |
| 
 | |
| const state = {
 | |
|   record: {},
 | |
|   uiFlags: {
 | |
|     isFetching: false,
 | |
|     isUpdating: false,
 | |
|   },
 | |
| };
 | |
| 
 | |
| export const getters = {
 | |
|   getUIFlags($state) {
 | |
|     return $state.uiFlags;
 | |
|   },
 | |
|   getSelectedEmailFlags: $state => {
 | |
|     return $state.record.selected_email_flags;
 | |
|   },
 | |
| };
 | |
| 
 | |
| export const actions = {
 | |
|   get: async ({ commit }) => {
 | |
|     commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, { isFetching: true });
 | |
|     try {
 | |
|       const response = await UserNotificationSettings.get();
 | |
|       commit(types.default.SET_USER_NOTIFICATION, response.data);
 | |
|       commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, {
 | |
|         isFetching: false,
 | |
|       });
 | |
|     } catch (error) {
 | |
|       commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, {
 | |
|         isFetching: false,
 | |
|       });
 | |
|     }
 | |
|   },
 | |
| 
 | |
|   update: async ({ commit }, params) => {
 | |
|     commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, { isUpdating: true });
 | |
|     try {
 | |
|       const response = await UserNotificationSettings.update({
 | |
|         notification_settings: {
 | |
|           selected_email_flags: params,
 | |
|         },
 | |
|       });
 | |
|       commit(types.default.SET_USER_NOTIFICATION, response.data);
 | |
|       commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, {
 | |
|         isUpdating: false,
 | |
|       });
 | |
|     } catch (error) {
 | |
|       commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, {
 | |
|         isUpdating: false,
 | |
|       });
 | |
|       throw error;
 | |
|     }
 | |
|   },
 | |
| };
 | |
| 
 | |
| export const mutations = {
 | |
|   [types.default.SET_USER_NOTIFICATION_UI_FLAG]($state, data) {
 | |
|     $state.uiFlags = {
 | |
|       ...$state.uiFlags,
 | |
|       ...data,
 | |
|     };
 | |
|   },
 | |
|   [types.default.SET_USER_NOTIFICATION]: ($state, data) => {
 | |
|     Vue.set($state, 'record', data);
 | |
|   },
 | |
| };
 | |
| 
 | |
| export default {
 | |
|   namespaced: true,
 | |
|   state,
 | |
|   getters,
 | |
|   actions,
 | |
|   mutations,
 | |
| };
 | 
