Migrate Account.vue to composition API
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Jan Bader 2022-02-14 08:06:16 +00:00
parent a061ffd350
commit ca93e9cd55

View File

@ -1,46 +1,41 @@
<script lang="ts">
import { mapState } from "pinia";
import { defineComponent } from "vue"
<script lang="ts" setup>
import { ref } from "vue"
import Autocomplete, { Suggestion } from '../components/Autocomplete.vue'
import Currency from "../components/Currency.vue";
import TransactionRow from "../components/TransactionRow.vue";
import { useAPI } from "../stores/api";
import { useAccountStore } from "../stores/budget-account";
import { useSessionStore } from "../stores/session";
export default defineComponent({
data() {
return {
TransactionDate: new Date().toISOString().substring(0, 10),
Payee: undefined as Suggestion | undefined,
Category: undefined as Suggestion | undefined,
Memo: "",
Amount: 0
}
},
components: { Autocomplete, Currency, TransactionRow },
props: ["budgetid", "accountid"],
computed: {
...mapState(useAccountStore, ["CurrentAccount", "TransactionsList"]),
},
methods: {
saveTransaction(e : MouseEvent) {
const props = defineProps<{
budgetid: string
accountid: string
}>()
const TransactionDate = ref(new Date().toISOString().substring(0, 10));
const Payee = ref<Suggestion | undefined>(undefined);
const Category = ref<Suggestion | undefined>(undefined);
const Memo = ref("");
const Amount = ref(0);
function saveTransaction(e: MouseEvent) {
e.preventDefault();
const api = useAPI();
api.POST("/transaction/new", JSON.stringify({
budget_id: this.budgetid,
account_id: this.accountid,
date: this.$data.TransactionDate,
payee: this.$data.Payee,
category: this.$data.Category,
memo: this.$data.Memo,
amount: this.$data.Amount,
budget_id: props.budgetid,
account_id: props.accountid,
date: TransactionDate,
payee: Payee,
category: Category,
memo: Memo,
amount: Amount,
state: "Uncleared"
}))
.then(x => x.json());
},
}
})
const accountStore = useAccountStore();
const CurrentAccount = accountStore.CurrentAccount;
const TransactionsList = accountStore.TransactionsList;
</script>
<template>
@ -73,16 +68,22 @@ export default defineComponent({
<input class="block w-full border-b-2 border-black" type="text" v-model="Memo" />
</td>
<td style="width: 80px;" class="text-right">
<input class="text-right block w-full border-b-2 border-black" type="currency" v-model="Amount" />
<input
class="text-right block w-full border-b-2 border-black"
type="currency"
v-model="Amount"
/>
</td>
<td style="width: 20px;">
<input type="submit" @click="saveTransaction" value="Save" />
</td>
<td style="width: 20px;"></td>
</tr>
<TransactionRow v-for="(transaction, index) in TransactionsList"
<TransactionRow
v-for="(transaction, index) in TransactionsList"
:transaction="transaction"
:index="index" />
:index="index"
/>
</table>
</template>