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: { headers: {
'Authorization': 'Bearer ' + this.$store.state.Session.Token 'Authorization': 'Bearer ' + this.$store.state.Session.Token
}, },
}) });
this.$store.commit("deleteBudget", this.$store.getters.CurrentBudget.ID)
this.$router.push("/")
}, },
clearBudget() { clearBudget() {
fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/settings/clear", { fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/settings/clear", {

View File

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