Redirect to dashboard and remove budget on delete

This commit is contained in:
Jan Bader 2022-01-31 16:12:17 +00:00
parent 8e2a62929e
commit 34b9c14419
2 changed files with 38 additions and 31 deletions

View File

@ -29,7 +29,9 @@ export default {
headers: {
'Authorization': 'Bearer ' + this.$store.state.Session.Token
},
})
});
this.$store.commit("deleteBudget", this.$store.getters.CurrentBudget.ID)
this.$router.push("/")
},
clearBudget() {
fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/settings/clear", {

View File

@ -9,7 +9,7 @@ const store = createStore({
User: null
},
ShowMenu: null,
Budgets: {},
Budgets: [],
CurrentBudgetID: null,
Accounts: [],
CurrentAccountID: null,
@ -19,6 +19,9 @@ const store = createStore({
}
},
mutations: {
deleteBudget(state, budgetid) {
delete state.Budgets[budgetid]
},
toggleMenu(state) {
state.ShowMenu = !state.ShowMenu;
},
@ -49,7 +52,12 @@ const store = createStore({
state.Budgets.push(budget);
},
[LOGOUT](state, token) {
state.Session = { Token: null, User: null }
state.Session = { Token: null, User: null };
state.Budgets = {};
state.Accounts = [];
state.Categories = [];
state.Transactions = [];
state.Assignments = [];
},
setCurrentBudgetID(state, budgetid) {
state.CurrentBudgetID = budgetid;
@ -99,7 +107,8 @@ const store = createStore({
async newBudget({ state, commit, dispatch, rootState }, budgetName) {
const result = await dispatch("POST", {
path: "/budget/new",
body: JSON.stringify({name: budgetName})});
body: JSON.stringify({ name: budgetName })
});
const response = await result.json();
commit("addBudget", response)
},
@ -151,11 +160,7 @@ const store = createStore({
if (state.CurrentBudgetID == null)
return {};
const budgets = state.Budgets.filter(x => x.ID == state.CurrentBudgetID);
if(budgets.length > 0)
return budgets[0];
return {};
return state.Budgets[state.CurrentBudgetID];
},
Accounts(state) {
return state.Accounts || [];