Added requests to modals
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
if (getCookie('access_token') === null ) {
|
if (getCookie('access_token') === null ) {
|
||||||
window.location.href = '/auth/login';
|
window.location.href = '/auth/login';
|
||||||
}
|
}
|
||||||
|
console.log(getCookie('access_token'));
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,27 @@
|
|||||||
import Modal from '../modals/Modal.svelte';
|
import Modal from '../modals/Modal.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { getCookie } from "svelte-cookie";
|
||||||
|
|
||||||
let showModal;
|
let showModal;
|
||||||
let amount;
|
let amount;
|
||||||
|
|
||||||
const selectedIncomeId = writable('');
|
const selectedIncomeId = writable('');
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('http://localhost/getElements');
|
const token = getCookie('access_token');
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
const config = {
|
||||||
incomeOptions.set(data);
|
headers: {
|
||||||
} else {
|
'Authorization': `Bearer ${token}`
|
||||||
console.error('Error:', response.status);
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const response = await axios.get('http://localhost:8081/incomes/categories', config);
|
||||||
|
incomeOptions.set(response.data);
|
||||||
|
console.log(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
@@ -25,22 +31,26 @@
|
|||||||
const incomeOptions = writable([]);
|
const incomeOptions = writable([]);
|
||||||
|
|
||||||
const createIncome = async () => {
|
const createIncome = async () => {
|
||||||
const selectedIncome = $incomeOptions.find(income => income.incomeid === $selectedIncomeId);
|
const selectedIncome = $incomeOptions.find(income => income.id === $selectedIncomeId);
|
||||||
const data = {
|
const data = {
|
||||||
incomeid: selectedIncome.incomeid,
|
incomeCategory: selectedIncome.id,
|
||||||
amount: $amount,
|
amount: $amount,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('http://localhost/createIncome', {
|
const token = getCookie('access_token');
|
||||||
method: 'POST',
|
console.log(token);
|
||||||
|
const response = await axios.post('http://localhost:8081/incomes', data, {
|
||||||
headers: {
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
console.log(response.data);
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log("cool");
|
||||||
} else {
|
} else {
|
||||||
console.error('Error:', response.status);
|
console.error('Error:', response.status);
|
||||||
}
|
}
|
||||||
@@ -62,8 +72,10 @@
|
|||||||
|
|
||||||
<label for="income">Select Income:</label>
|
<label for="income">Select Income:</label>
|
||||||
<select id="income" bind:value={$selectedIncomeId}>
|
<select id="income" bind:value={$selectedIncomeId}>
|
||||||
{#each $incomeOptions as income (income.incomeid)}
|
{#each $incomeOptions as income (income.id)}
|
||||||
<option value={income.incomeid}>{income.incomename}</option>
|
{#if income.id !== undefined}
|
||||||
|
<option value={income.id}>{income.name}</option>
|
||||||
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user