-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user can now create accounts and view the list of all accounts - adde…
…d action, mutation, view, and form for adding an account; also added basic navigation between list and create accounts
- Loading branch information
1 parent
bb85b37
commit d569fce
Showing
10 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<template> | ||
<div id="accounts-create-edit-view"> | ||
You can create and edit accounts with me, yippee! | ||
|
||
<router-link :to="{ name: 'accountsListView' }">View all accounts</router-link> | ||
|
||
<form class="form" @submit.prevent="saveNewAccount"> | ||
<label for="name" class="label">Name</label> | ||
<p class="control"> | ||
<input type="text" class="input" name="name" v-model="newAccount.name"> | ||
</p> | ||
<label for="category" class="label">Category</label> | ||
<p class="control"> | ||
<span class="select"> | ||
<select name="category" v-model="newAccount.category"> | ||
<option v-for="value, key in categories" :value="key">{{ value }}</option> | ||
</select> | ||
</span> | ||
</p> | ||
<label for="balance" class="label">Balance</label> | ||
<p class="control"> | ||
<input type="text" class="input" name="balance" v-model="newAccount.balance"> | ||
</p> | ||
<div class="control is-grouped"> | ||
<p class="control"> | ||
<button class="button is-primary">Submit</button> | ||
</p> | ||
<p class="control"> | ||
<router-link :to="{ name: 'accountsListView' }"><button class="button is-link">Cancel</button></router-link> | ||
</p> | ||
</div> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapActions } from 'vuex'; | ||
import { CATEGORIES } from '../../../consts'; | ||
export default { | ||
name: 'accounts-create-edit-view', | ||
data: () => { | ||
return { | ||
categories: CATEGORIES, | ||
newAccount: {} | ||
}; | ||
}, | ||
methods: { | ||
...mapActions([ | ||
'addAccount' | ||
]), | ||
saveNewAccount () { | ||
this.addAccount(this.newAccount).then(() => { | ||
this.newAccount = {}; | ||
this.$router.push({ name: 'accountsListView' }); | ||
}); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped lang='scss'> | ||
#accounts-create-edit-view { | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as AccountsListView } from './AccountsListView'; | ||
export { default as CreateEditAccount } from './CreateEditAccount'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const doSomething = ({ commit }, data) => { | ||
commit('DO_SOMETHING', { data: data }); | ||
export const addAccount = ({ commit }, data) => { | ||
commit('ADD_ACCOUNT', { account: data }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { guid } from '../../../utils'; | ||
|
||
export default { | ||
DO_SOMETHING (state, { data }) { | ||
state.something = data; | ||
ADD_ACCOUNT (state, payload) { | ||
let id = guid(); | ||
state.accounts[id] = Object.assign({ id: id }, payload.account); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const CATEGORIES = { | ||
'CREDIT_CARD': 'Credit Card', | ||
'CHECKING': 'Checking', | ||
'SAVINGS': 'Savings' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// thanks to http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript | ||
export const guid = function () { | ||
function s4 () { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | ||
s4() + '-' + s4() + s4() + s4(); | ||
}; |