add clearing user data in ui

This commit is contained in:
MaysWind
2021-01-20 21:45:25 +08:00
parent 34f082273e
commit 2e6aac19af
5 changed files with 104 additions and 2 deletions
+2
View File
@@ -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
View File
@@ -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);
}