Commit ddce2ec2 authored by ZeHiro's avatar ZeHiro Committed by ZeHiro
Browse files

Set defaultAccountId to '' when the according account is deleted. Fixes #556

parent 91317ec2
Pipeline #14926 passed with stage
in 2 minutes and 42 seconds
......@@ -126,10 +126,11 @@ const basic = {
};
},
deleteAccess(accessId) {
deleteAccess(accessId, accountsIds) {
return {
type: DELETE_ACCESS,
accessId
accessId,
accountsIds
};
},
......@@ -272,14 +273,14 @@ export function deleteOperation(operationId) {
};
}
export function deleteAccess(accessId) {
export function deleteAccess(accessId, get) {
assert(typeof accessId === 'string', 'deleteAccess expects a string id');
return dispatch => {
return (dispatch, getState) => {
let accountsIds = get.accountsByAccessId(getState(), accessId).map(acc => acc.id);
dispatch(basic.deleteAccess(accessId));
backend.deleteAccess(accessId)
.then(() => {
dispatch(success.deleteAccess(accessId));
dispatch(success.deleteAccess(accessId, accountsIds));
}).catch(err => {
dispatch(fail.deleteAccess(err, accessId));
});
......@@ -301,7 +302,7 @@ export function deleteAccount(accountId) {
}
export function resyncBalance(accountId) {
assert(typeof accountId === 'string', 'deleteAccount expects a string id');
assert(typeof accountId === 'string', 'resyncBalance expects a string id');
return dispatch => {
dispatch(basic.resyncBalance(accountId));
......
......@@ -351,7 +351,7 @@ export const actions = {
deleteAccount(dispatch, accountId) {
assertDefined(dispatch);
dispatch(Bank.deleteAccount(accountId));
dispatch(Bank.deleteAccount(accountId, get));
},
createAccess(dispatch, uuid, login, password, fields) {
......@@ -380,7 +380,7 @@ export const actions = {
deleteAccess(dispatch, accessId) {
assertDefined(dispatch);
dispatch(Bank.deleteAccess(accessId));
dispatch(Bank.deleteAccess(accessId, get));
},
createOperation(dispatch, newOperation) {
......
......@@ -302,13 +302,43 @@ function reduceExportInstance(state, action) {
return state;
}
function reduceDeleteAccount(state, action) {
let { status } = action;
if (status === SUCCESS) {
let { accountId } = action;
if (accountId === getDefaultAccountId(state)) {
let defaultAccountId = DefaultSettings.get('defaultAccountId');
return u({ map: { defaultAccountId } }, state);
}
}
return state;
}
function reduceDeleteAccess(state, action) {
let { status } = action;
if (status === SUCCESS) {
let { accountsIds } = action;
if (accountsIds.includes(getDefaultAccountId(state))) {
let defaultAccountId = DefaultSettings.get('defaultAccountId');
return u({ map: { defaultAccountId } }, state);
}
}
return state;
}
const reducers = {
IMPORT_INSTANCE: reduceImportInstance,
EXPORT_INSTANCE: reduceExportInstance,
SET_SETTING: reduceSet,
SEND_TEST_EMAIL: reduceSendTestEmail,
UPDATE_WEBOOB: reduceUpdateWeboob,
UPDATE_ACCESS: reduceUpdateAccess
UPDATE_ACCESS: reduceUpdateAccess,
DELETE_ACCOUNT: reduceDeleteAccount,
DELETE_ACCESS: reduceDeleteAccess
};
export const reducer = createReducerFromMap(settingsState, reducers);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment