You can now add expenses/incomes
This commit is contained in:
@@ -1,6 +1,63 @@
|
|||||||
<script>
|
<script>
|
||||||
import Modal from '../modals/Modal.svelte'
|
import Modal from '../modals/Modal.svelte';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { getCookie } from "svelte-cookie";
|
||||||
|
|
||||||
let showModal;
|
let showModal;
|
||||||
|
let amount = '';
|
||||||
|
|
||||||
|
const selectedExpenseId = writable('');
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
try {
|
||||||
|
const token = getCookie('access_token');
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await axios.get('http://localhost:8081/expenses/categories', config);
|
||||||
|
expenseOptions.set(response.data);
|
||||||
|
console.log(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const expenseOptions = writable([]);
|
||||||
|
|
||||||
|
const createIncome = async () => {
|
||||||
|
const selectedExpense = $expenseOptions.find(expense => expense.id === $selectedExpenseId);
|
||||||
|
const data = {
|
||||||
|
expenseCategory: selectedExpense.id,
|
||||||
|
amount: amount,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const token = getCookie('access_token');
|
||||||
|
console.log(token);
|
||||||
|
const response = await axios.post('http://localhost:8081/expenses', data, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(response.data);
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log("cool");
|
||||||
|
} else {
|
||||||
|
console.error('Error:', response.status);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="exp">
|
<div id="exp">
|
||||||
@@ -9,27 +66,21 @@
|
|||||||
+
|
+
|
||||||
</div>
|
</div>
|
||||||
<Modal bind:showModal>
|
<Modal bind:showModal>
|
||||||
<h2 slot="header">
|
<div>
|
||||||
modal
|
<label for="amount">Amount:</label>
|
||||||
<small><em>adjective</em> mod·al \ˈmō-dəl\</small>
|
<input type="text" id="amount" bind:value={amount} />
|
||||||
</h2>
|
|
||||||
|
|
||||||
<ol class="definition-list">
|
<label for="income">Select Income:</label>
|
||||||
<li>of or relating to modality in logic</li>
|
<select id="income" bind:value={$selectedExpenseId}>
|
||||||
<li>
|
{#each $expenseOptions as expense (expense.id)}
|
||||||
containing provisions as to the mode of procedure or the manner of taking effect —used of a
|
{#if expense.id !== undefined}
|
||||||
contract or legacy
|
<option value={expense.id}>{expense.name}</option>
|
||||||
</li>
|
{/if}
|
||||||
<li>of or relating to a musical mode</li>
|
{/each}
|
||||||
<li>of or relating to structure as opposed to substance</li>
|
</select>
|
||||||
<li>
|
|
||||||
of, relating to, or constituting a grammatical form or category characteristically indicating
|
|
||||||
predication
|
|
||||||
</li>
|
|
||||||
<li>of or relating to a statistical mode</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<a href="https://www.merriam-webster.com/dictionary/modal">merriam-webster.com</a>
|
<button on:click={createIncome}>Submit</button>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -61,4 +112,4 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
import { getCookie } from "svelte-cookie";
|
import { getCookie } from "svelte-cookie";
|
||||||
|
|
||||||
let showModal;
|
let showModal;
|
||||||
let amount;
|
let amount = '';
|
||||||
|
|
||||||
const selectedIncomeId = writable('');
|
const selectedIncomeId = writable('');
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
const selectedIncome = $incomeOptions.find(income => income.id === $selectedIncomeId);
|
const selectedIncome = $incomeOptions.find(income => income.id === $selectedIncomeId);
|
||||||
const data = {
|
const data = {
|
||||||
incomeCategory: selectedIncome.id,
|
incomeCategory: selectedIncome.id,
|
||||||
amount: $amount,
|
amount: amount,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
|
|
||||||
<div id="inc">
|
<div id="inc">
|
||||||
<h2>Incomes</h2>
|
<h2>Incomes</h2>
|
||||||
<div id="openModal" class="plus-button" role="button" tabindex="0" on:click={() => (showModal = true)} on:keydown={() => console.log("keydown")}>
|
<div id="openModal" class="plus-button" role="button" tabindex="1" on:click={() => (showModal = true)} on:keydown={() => console.log("keydown")}>
|
||||||
+
|
+
|
||||||
</div>
|
</div>
|
||||||
<Modal bind:showModal>
|
<Modal bind:showModal>
|
||||||
@@ -112,4 +112,4 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user