mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 11:37:58 +00:00
Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
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;
|
|
},
|
|
getSelectedPushFlags: $state => {
|
|
return $state.record.selected_push_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 }, { selectedEmailFlags, selectedPushFlags }) => {
|
|
commit(types.default.SET_USER_NOTIFICATION_UI_FLAG, { isUpdating: true });
|
|
try {
|
|
const response = await UserNotificationSettings.update({
|
|
notification_settings: {
|
|
selected_email_flags: selectedEmailFlags,
|
|
selected_push_flags: selectedPushFlags,
|
|
},
|
|
});
|
|
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) => {
|
|
$state.record = data;
|
|
},
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
};
|