Implement currentBudget and move infos to sidebar
This commit is contained in:
@ -9,7 +9,7 @@ const budget = {
|
||||
},
|
||||
mutations: {
|
||||
setAccounts (state, accounts) {
|
||||
state.Accounts = accounts;
|
||||
state.Accounts = accounts;
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
|
@ -11,24 +11,30 @@ const dashboard = {
|
||||
},
|
||||
addBudget(state, budget) {
|
||||
state.Budgets.push(budget);
|
||||
},
|
||||
setCurrentBudget(state, budget) {
|
||||
state.CurrentBudget = budget;
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
Budgets(state) {
|
||||
return state.Budgets || [];
|
||||
},
|
||||
CurrentBudget(state) {
|
||||
return state.CurrentBudget || {};
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
fetchDashboard ({state, commit, rootState}) {
|
||||
fetch("/api/v1/dashboard", {
|
||||
async fetchDashboard ({state, commit, rootState}) {
|
||||
const response = await fetch("/api/v1/dashboard", {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + rootState.Session.Token
|
||||
}
|
||||
})
|
||||
.then(x => x.json())
|
||||
.then(x => commit("setBudgets", x.Budgets));
|
||||
const data = await response.json();
|
||||
commit("setBudgets", data.Budgets);
|
||||
},
|
||||
newBudget ({state, commit, rootState}, budgetName) {
|
||||
async newBudget ({state, commit, rootState}, budgetName) {
|
||||
fetch("/api/v1/budget/new", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({name: budgetName}),
|
||||
@ -38,6 +44,17 @@ const dashboard = {
|
||||
})
|
||||
.then(x => x.json())
|
||||
.then(x => commit("addBudget", x));
|
||||
},
|
||||
async setCurrentBudget({state, commit, dispatch}, budgetid) {
|
||||
await dispatch("fetchDashboard");
|
||||
for (const element of state.Budgets) {
|
||||
if(element.ID != budgetid)
|
||||
continue
|
||||
|
||||
commit("setCurrentBudget", element);
|
||||
break
|
||||
}
|
||||
await dispatch("fetchBudget", budgetid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user