allow user choosing whether add preset categories in registration page

This commit is contained in:
MaysWind
2021-01-07 17:29:24 +08:00
parent d073550aa7
commit aec708cdd3
7 changed files with 266 additions and 30 deletions
+13
View File
@@ -18,6 +18,7 @@ import {
UPDATE_ACCOUNT_LIST_INVALID_STATE,
LOAD_TRANSACTION_CATEGORY_LIST,
UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE,
LOAD_TRANSACTION_TAG_LIST,
ADD_TAG_TO_TRANSACTION_TAG_LIST,
@@ -33,6 +34,7 @@ import twoFactorAuth from './twoFactorAuth.js';
import token from './token.js';
import exchangeRates from './exchangeRates.js';
import account from './account.js';
import transactionCategory from './transactionCategory.js';
import transactionTag from './transactionTag.js';
const stores = {
@@ -46,6 +48,7 @@ const stores = {
accountListStateInvalid: true,
allTransactionCategories: [],
allTransactionCategoriesMap: {},
transactionCategoryListStateInvalid: true,
allTransactionTags: [],
allTransactionTagsMap: {},
transactionTagListStateInvalid: true,
@@ -209,6 +212,9 @@ const stores = {
state.allTransactionCategoriesMap[category.id] = category;
}
},
[UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE] (state, invalidState) {
state.transactionCategoryListStateInvalid = invalidState;
},
[LOAD_TRANSACTION_TAG_LIST] (state, tags) {
state.allTransactionTags = tags;
state.allTransactionTagsMap = {};
@@ -265,16 +271,20 @@ const stores = {
updateUserProfile: user.updateUserProfile,
clearUserInfoState: user.clearUserInfoState,
resetState: user.resetState,
get2FAStatus: twoFactorAuth.get2FAStatus,
enable2FA: twoFactorAuth.enable2FA,
confirmEnable2FA: twoFactorAuth.confirmEnable2FA,
disable2FA: twoFactorAuth.disable2FA,
regenerate2FARecoveryCode: twoFactorAuth.regenerate2FARecoveryCode,
getAllTokens: token.getAllTokens,
refreshTokenAndRevokeOldToken: token.refreshTokenAndRevokeOldToken,
revokeToken: token.revokeToken,
revokeAllTokens: token.revokeAllTokens,
getLatestExchangeRates: exchangeRates.getLatestExchangeRates,
loadAllAccounts: account.loadAllAccounts,
saveAccount: account.saveAccount,
getAccount: account.getAccount,
@@ -282,6 +292,9 @@ const stores = {
updateAccountDisplayOrders: account.updateAccountDisplayOrders,
hideAccount: account.hideAccount,
deleteAccount: account.deleteAccount,
addTransactionCategoryBatch: transactionCategory.addTransactionCategoryBatch,
loadAllTags: transactionTag.loadAllTags,
saveTag: transactionTag.saveTag,
changeTagDisplayOrder: transactionTag.changeTagDisplayOrder,
+1
View File
@@ -14,6 +14,7 @@ export const REMOVE_ACCOUNT_FROM_ACCOUNT_LIST = 'REMOVE_ACCOUNT_FROM_ACCOUNT_LIS
export const UPDATE_ACCOUNT_LIST_INVALID_STATE = 'UPDATE_ACCOUNT_LIST_INVALID_STATE';
export const LOAD_TRANSACTION_CATEGORY_LIST = 'LOAD_TRANSACTION_CATEGORY_LIST';
export const UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE = 'UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE';
export const LOAD_TRANSACTION_TAG_LIST = 'LOAD_TRANSACTION_TAG_LIST';
export const ADD_TAG_TO_TRANSACTION_TAG_LIST = 'ADD_TAG_TO_TRANSACTION_TAG_LIST';
+39
View File
@@ -0,0 +1,39 @@
import services from '../lib/services.js';
import logger from '../lib/logger.js';
import {
UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE,
} from './mutations.js';
function addTransactionCategoryBatch(context, { categories }) {
return new Promise((resolve, reject) => {
services.addTransactionCategoryBatch({
categories: categories
}).then(response => {
const data = response.data;
if (!data || !data.success || !data.result) {
reject({ message: 'Unable to add preset categories' });
return;
}
context.commit(UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE);
resolve(data.result);
}).catch(error => {
logger.error('failed to add preset categories', error);
if (error.response && error.response.data && error.response.data.errorMessage) {
reject({ error: error.response.data });
} else if (!error.processed) {
reject({ message: 'Unable to add preset categories' });
} else {
reject(error);
}
});
});
}
export default {
addTransactionCategoryBatch,
}