Skip to content
Permalink
Browse files

createupdateaccount.vue loads the correct account when navigating dir…

…ectly between accounts
  • Loading branch information...
matthiaswh committed Mar 25, 2017
1 parent b815eec commit ae0900071073c3b8a858b04f8c30fbf67e826e87
Showing with 29 additions and 12 deletions.
  1. +27 −11 src/app/accounts/components/CreateUpdateAccount.vue
  2. +2 −1 src/app/accounts/routes.js
@@ -60,25 +60,19 @@ import { CATEGORIES } from '../../../consts';
export default {
name: 'accounts-create-edit-view',
props: ['accountId'],
data: () => {
return {
categories: CATEGORIES,
selectedAccount: {},
editing: false
editing: false,
selectedAccount: {}
};
},
mounted () {
if ('accountId' in this.$route.params) {
this.loadAccounts().then(() => {
let selectedAccount = this.getAccountById(this.$route.params.accountId);
if (selectedAccount) {
this.editing = true;
this.selectedAccount = Object.assign({}, selectedAccount);
}
// TODO: the object does not exist, how do we handle this scenario?
});
if (this.accountId) {
this.loadAccount();
}
},
@@ -108,13 +102,35 @@ export default {
processSave () {
this.editing ? this.saveAccount() : this.saveNewAccount();
},
loadAccount () {
let vm = this;
this.loadAccounts().then(() => {
let selectedAccount = vm.getAccountById(vm.accountId);
if (selectedAccount) {
vm.editing = true;
vm.selectedAccount = Object.assign({}, selectedAccount);
}
// TODO: the object does not exist, how do we handle this scenario?
});
}
},
computed: {
...mapGetters([
'getAccountById'
])
},
watch: {
accountId (newId) {
if (newId) {
this.loadAccount();
}
this.editing = false;
this.selectedAccount = {};
}
}
};
</script>
@@ -14,6 +14,7 @@ export default [
{
path: '/accounts/:accountId/update',
component: components.CreateUpdateAccount,
name: 'updateAccount'
name: 'updateAccount',
props: true
}
];

0 comments on commit ae09000

Please sign in to comment.
You can’t perform that action at this time.