diff --git a/src/components/ExpenseList.js b/src/components/ExpenseList.js index c0ef267..8d24154 100644 --- a/src/components/ExpenseList.js +++ b/src/components/ExpenseList.js @@ -9,6 +9,8 @@ const ExpenseList = () => { const [transaction, setTransactions] = useState(''); const [category, setCategories] = useState(''); const [time, setTime] = useState(''); + const [data, setData] = useState([]); + const [type, setType] = useState(''); function getSessionKey() { var cookies = document.cookie.split(';'); @@ -21,7 +23,74 @@ const ExpenseList = () => { return null; } - + async function fetchData() { + + fetch('https://api.bb.gabefarrell.com/w/transactions/recent', { + method: 'GET', + headers: { + 'x-session-key': getSessionKey(), + }, + }) + .then((response) => response.json()) + .then((actualData) => { + console.log(actualData); + setData(actualData); + console.log(data); + }) + .catch((err) => { + console.log(err.message); + }); + } + + + async function getTransactionsBalance() { + try { + const response = await fetch('https://api.bb.gabefarrell.com/w/transactions/recent', { + method: 'GET', + headers: { + 'x-session-key': getSessionKey(), + }, + }); + const data = await response.json(); + let whole = data.transactions.map((item)=>item.amount.whole); + let decimal = data.transactions.map((item)=>item.amount.decimal); + let balance = []; + for (let i = 0; i < whole.length; i++) { + let expense_balance = whole[i] + '.' + decimal[i]; + balance.push(expense_balance); + } + + //console.log(whole + decimal + "<- total recent transacations"); + //console.log(whole, decimal, balance); + //const transactions_balance = whole + '.' + decimal; + //console.log(whole, decimal, category); + return balance; + } catch (error) { + console.error(error); + } + } + + async function getType() { + try { + const response = await fetch('https://api.bb.gabefarrell.com/w/transactions/recent', { + method: 'GET', + headers: { + 'x-session-key': getSessionKey(), + }, + }); + const data = await response.json(); + const type = data.transactions.map((item)=>item.type); + + + //console.log(whole + decimal + "<- total recent transacations"); + //console.log(whole, decimal, balance); + //const transactions_balance = whole + '.' + decimal; + //console.log(whole, decimal, category); + return type; + } catch (error) { + console.error(error); + } + } async function getTransactionsBalance() { try { @@ -84,7 +153,7 @@ const ExpenseList = () => { date = new Date(timestamp[i]); month = date.getMonth(); day = date.getDay(); - console.log(month, day); + //console.log(month, day); dateFormat.push(month + '/' + day); } //let dateFormat = new Date(timestamp[0]); @@ -115,14 +184,18 @@ const ExpenseList = () => { const categories = await getTransactionsCategory(); const transaction_balance = await getTransactionsBalance(); const date = await getDate(); + const type = await getType(); setCategories(categories); + //console.log(category + "CATEGORIES"); setTransactions(transaction_balance); setTime(date); + setType(type); } useEffect(() => { fetchTransactions(); //b36efa01-7824-4f61-a274-63131b58d8fe + //fetchData(); }, []) @@ -138,8 +211,42 @@ const ExpenseList = () => {

Recent Transactions

{/*

{category}

{transaction}

*/} - - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{category[0]}{transaction[0]}{type[0]}
{category[1]}{transaction[1]}{type[1]}
{category[2]}{transaction[2]}{type[2]}
{category[3]}{transaction[3]}{type[3]}
{category[4]}{transaction[4]}{type[4]}
{category[5]}{transaction[5]}{type[5]}
{category[6]}{transaction[6]}{type[6]}