mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 23:47:33 +08:00
add clearing user data in ui
This commit is contained in:
@@ -52,6 +52,7 @@ import {
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserData,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
currentUserNickname,
|
||||
@@ -735,6 +736,7 @@ const stores = {
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserData,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
|
||||
|
||||
+46
-1
@@ -11,7 +11,9 @@ import {
|
||||
CLEAR_USER_INFO,
|
||||
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE
|
||||
} from './mutations.js';
|
||||
|
||||
export function authorize(context, { loginName, password }) {
|
||||
@@ -271,6 +273,49 @@ export function updateUserProfile(context, { profile, currentPassword }) {
|
||||
});
|
||||
}
|
||||
|
||||
export function clearUserData(context, { password }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.clearData({
|
||||
password: password
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
reject({ message: 'Unable to clear user data' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.state.accountListStateInvalid) {
|
||||
context.commit(UPDATE_ACCOUNT_LIST_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionCategoryListStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionTagListStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionOverviewStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to clear user data', error);
|
||||
|
||||
if (error && error.processed) {
|
||||
reject(error);
|
||||
} else if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
reject({ error: error.response.data });
|
||||
} else {
|
||||
reject({ message: 'Unable to clear user data' });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function clearUserInfoState(context) {
|
||||
context.commit(CLEAR_USER_INFO);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user