Permalink
Browse files

refactor! renamed some files and functions for more consistency; squa…

…shed a pernicious bug that erased our account balances when editing
  • Loading branch information...
matthiaswh committed Feb 17, 2017
1 parent f144a6e commit 324fbe9d19c02f2ccd2ef1d8bcf4c2211b7a8941
@@ -19,7 +19,7 @@ export const saveAccount = (account) => {
});
};
export const removeAccount = (account) => {
export const deleteAccount = (account) => {
return localforage.removeItem(
ACCOUNT_NAMESPACE + account.id
).then(() => {
@@ -10,7 +10,7 @@
<span class="tag is-small is-info">{{ categories[account.category] }}</span>
${{ account.balance }}
<a @click="confirmDeleteAccount(account)">Delete</a>
<router-link :to="{ name: 'editAccount', params: { accountId: account.id } }">Edit</router-link>
<router-link :to="{ name: 'updateAccount', params: { accountId: account.id } }">Edit</router-link>
</li>
</ul>
</div>
@@ -55,11 +55,7 @@ export default {
let selectedAccount = this.getAccountById(this.$route.params.accountId);
if (selectedAccount) {
this.editing = true;
this.selectedAccount = {
name: selectedAccount.name,
category: selectedAccount.category,
id: selectedAccount.id
};
this.selectedAccount = Object.assign({}, selectedAccount);
}
// TODO: the object does not exist, how do we handle this scenario?
});
@@ -68,7 +64,7 @@ export default {
methods: {
...mapActions([
'addAccount',
'createAccount',
'updateAccount',
'loadAccounts'
]),
@@ -79,7 +75,7 @@ export default {
},
saveNewAccount () {
this.addAccount(this.selectedAccount).then(() => {
this.createAccount(this.selectedAccount).then(() => {
this.resetAndGo();
});
},
@@ -1,2 +1,2 @@
export { default as AccountsListView } from './AccountsListView';
export { default as CreateEditAccount } from './CreateEditAccount';
export { default as AccountsListView } from './AccountsList';
export { default as CreateUpdateAccount } from './CreateUpdateAccount';
@@ -8,12 +8,12 @@ export default [
},
{
path: '/accounts/create',
component: components.CreateEditAccount,
component: components.CreateUpdateAccount,
name: 'createAccount'
},
{
path: '/accounts/:accountId/edit',
component: components.CreateEditAccount,
name: 'editAccount'
path: '/accounts/:accountId/update',
component: components.CreateUpdateAccount,
name: 'updateAccount'
}
];
@@ -1,10 +1,10 @@
import { guid } from '../../../utils';
import { removeAccount, saveAccount, fetchAccounts } from '../api';
import { deleteAccount as deleteAccountFromAPI, saveAccount, fetchAccounts } from '../api';
export const addAccount = ({ commit }, data) => {
export const createAccount = ({ commit }, data) => {
let id = guid();
let account = Object.assign({ id: id }, data);
commit('ADD_ACCOUNT', {account: account});
commit('CREATE_ACCOUNT', {account: account});
saveAccount(account).then((value) => {
// we've saved the account, what now
});
@@ -17,7 +17,7 @@ export const updateAccount = ({ commit }, data) => {
export const deleteAccount = ({ commit }, data) => {
commit('DELETE_ACCOUNT', { account: data });
removeAccount(data);
deleteAccountFromAPI(data);
};
export const loadAccounts = (state) => {
@@ -1,7 +1,7 @@
import Vue from 'vue';
export default {
ADD_ACCOUNT (state, payload) {
CREATE_ACCOUNT (state, payload) {
state.accounts[payload.account.id] = payload.account;
},
@@ -1 +1 @@
export { default as BudgetsListView } from './BudgetsListView';
export { default as BudgetsListView } from './BudgetsList';
@@ -1 +1 @@
export { default as TransactionsListView } from './TransactionsListView';
export { default as TransactionsListView } from './TransactionsList';

0 comments on commit 324fbe9

Please sign in to comment.