Fix diverse errors

This commit is contained in:
Jan Bader 2022-01-31 21:45:02 +00:00
parent b350fe7d74
commit 9353d82648
3 changed files with 32 additions and 28 deletions

View File

@ -1,4 +1,5 @@
<script> <script>import { NEW_BUDGET } from "../store/action-types";
export default { export default {
data () { data () {
return { return {
@ -8,7 +9,7 @@
}, },
methods: { methods: {
saveBudget () { saveBudget () {
this.$store.dispatch("newBudget", this.$data.budgetName); this.$store.dispatch(NEW_BUDGET, this.$data.budgetName);
this.$data.dialog = false; this.$data.dialog = false;
}, },
newBudget () { newBudget () {

View File

@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from "vue" import { defineComponent } from "vue"
import { IMPORT_YNAB } from "../store/action-types";
import { TITLE } from "../store/mutation-types" import { TITLE } from "../store/mutation-types"
export default defineComponent({ export default defineComponent({
@ -49,7 +50,7 @@ export default defineComponent({
let formData = new FormData(); let formData = new FormData();
formData.append("transactions", this.$data.transactionsFile); formData.append("transactions", this.$data.transactionsFile);
formData.append("assignments", this.$data.assignmentsFile); formData.append("assignments", this.$data.assignmentsFile);
this.$store.dispatch("YNAB", formData); this.$store.dispatch(IMPORT_YNAB, formData);
} }
} }
}) })

View File

@ -1,7 +1,7 @@
import { InjectionKey } from 'vue' import { InjectionKey } from 'vue'
import { createStore, Store, createLogger } from 'vuex' import { createStore, Store, createLogger } from 'vuex'
import { LOGIN_SUCCESS, LOGOUT, TITLE } from './mutation-types' import { LOGIN_SUCCESS, LOGOUT, TITLE } from './mutation-types'
import { FETCH_ACCOUNT, FETCH_BUDGET, GET, REGISTER, IMPORT_YNAB, LOGIN, NEW_BUDGET, POST, SET_CURRENT_ACCOUNT, SET_CURRENT_BUDGET} from './action-types' import { FETCH_ACCOUNT, FETCH_BUDGET, GET, REGISTER, IMPORT_YNAB, LOGIN, NEW_BUDGET, POST, SET_CURRENT_ACCOUNT, SET_CURRENT_BUDGET } from './action-types'
export interface State { export interface State {
Session: { Session: {
@ -32,21 +32,21 @@ export const key: InjectionKey<Store<State>> = Symbol()
export const store = createStore<State>({ export const store = createStore<State>({
state: { state: {
Session: { Session: {
Token: undefined, Token: undefined,
User: undefined User: undefined
}, },
ShowMenu: undefined, ShowMenu: undefined,
Budgets: new Map<string, Budget>(), Budgets: new Map<string, Budget>(),
CurrentBudgetID: undefined, CurrentBudgetID: undefined,
Accounts: new Map<string, Account>(), Accounts: new Map<string, Account>(),
CurrentAccountID: undefined, CurrentAccountID: undefined,
Categories: [], Categories: [],
Transactions: [], Transactions: [],
Assignments: [] Assignments: []
}, },
mutations: { mutations: {
deleteBudget(state : State, budgetid : string) { deleteBudget(state: State, budgetid: string) {
state.Budgets.delete(budgetid) state.Budgets.delete(budgetid)
}, },
toggleMenu(state) { toggleMenu(state) {
@ -58,12 +58,12 @@ export const store = createStore<State>({
return; return;
const restoredState = JSON.parse(store); const restoredState = JSON.parse(store);
if(!restoredState) if (!restoredState)
return; return;
state.Session = restoredState.Session; state.Session = restoredState.Session;
state.CurrentBudgetID= restoredState.CurrentBudgetID; state.CurrentBudgetID = restoredState.CurrentBudgetID;
state.CurrentAccountID= restoredState.CurrentAccountID; state.CurrentAccountID = restoredState.CurrentAccountID;
state.ShowMenu = restoredState.ShowMenu; state.ShowMenu = restoredState.ShowMenu;
for (const budget of restoredState.Budgets) { for (const budget of restoredState.Budgets) {
@ -88,6 +88,9 @@ export const store = createStore<State>({
addBudget(state, budget) { addBudget(state, budget) {
state.Budgets.set(budget.ID, budget); state.Budgets.set(budget.ID, budget);
}, },
addAccount(state, account) {
state.Accounts.set(account.ID, account);
},
[LOGOUT](state, token) { [LOGOUT](state, token) {
state.Session = { Token: undefined, User: undefined }; state.Session = { Token: undefined, User: undefined };
state.Budgets.clear(); state.Budgets.clear();
@ -102,9 +105,6 @@ export const store = createStore<State>({
setCurrentAccountID(state, accountid) { setCurrentAccountID(state, accountid) {
state.CurrentAccountID = accountid; state.CurrentAccountID = accountid;
}, },
setAccounts(state, accounts) {
state.Accounts = accounts;
},
setTransactions(state, transactions) { setTransactions(state, transactions) {
state.Transactions = transactions; state.Transactions = transactions;
} }
@ -163,7 +163,9 @@ export const store = createStore<State>({
async [FETCH_BUDGET]({ state, commit, dispatch, rootState }, budgetid) { async [FETCH_BUDGET]({ state, commit, dispatch, rootState }, budgetid) {
const result = await dispatch("GET", { path: "/budget/" + budgetid }); const result = await dispatch("GET", { path: "/budget/" + budgetid });
const response = await result.json(); const response = await result.json();
return commit("setAccounts", response.Accounts); for (const account of response.Accounts || []) {
commit("addAccount", account);
}
}, },
async [FETCH_ACCOUNT]({ state, commit, rootState }, accountid) { async [FETCH_ACCOUNT]({ state, commit, rootState }, accountid) {
const result = await fetch("/api/v1/account/" + accountid + "/transactions", { const result = await fetch("/api/v1/account/" + accountid + "/transactions", {