Implement currentBudget and move infos to sidebar

This commit is contained in:
2022-01-25 08:37:38 +00:00
parent 33990bdccf
commit af3252277c
6 changed files with 91 additions and 66 deletions

View File

@ -9,7 +9,7 @@ const budget = {
},
mutations: {
setAccounts (state, accounts) {
state.Accounts = accounts;
state.Accounts = accounts;
}
},
getters: {

View File

@ -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);
}
}
}