From c4485f52529e4a3034841bb336fc1c4ff8da006b Mon Sep 17 00:00:00 2001 From: ManInDark <61268856+ManInDark@users.noreply.github.com> Date: Wed, 7 May 2025 17:24:17 +0200 Subject: [PATCH] feat: now possible to add transactions --- app/components/AddTransaction.tsx | 62 +++++++++++++++++++++++++++++++ app/routes/home.tsx | 12 +++--- 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 app/components/AddTransaction.tsx diff --git a/app/components/AddTransaction.tsx b/app/components/AddTransaction.tsx new file mode 100644 index 0000000..1f94677 --- /dev/null +++ b/app/components/AddTransaction.tsx @@ -0,0 +1,62 @@ +import { useRef } from "react"; + + +export default function AddTransaction() { + const API_URL = "http://localhost:2500"; + const tier = useRef(null); + const enchantment = useRef(null); + const silver = useRef(null); + const type = useRef(null); + + const submit = () => { + console.log("submit"); + fetch(`${API_URL}/transactions`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + tier: Number(tier.current?.value), + enchantment: Number(enchantment.current?.value), + silver: Number(silver.current?.value), + type: type.current?.value, + }), + }).then((response) => { + if (response.ok) { + console.log("Transaction added"); + } else { + console.error("Error adding transaction"); + } + }); + }; + + return ( +
+

Add Transaction

+ + + + + + + + + +
+ ); +} diff --git a/app/routes/home.tsx b/app/routes/home.tsx index e448b6b..9ff6401 100644 --- a/app/routes/home.tsx +++ b/app/routes/home.tsx @@ -1,9 +1,10 @@ import type { Route } from "./+types/home"; import { useEffect, useState } from "react"; import "../../config.json"; +import AddTransaction from "~/components/AddTransaction"; -const API_URL = process.env.API_URL; -type transaction = { id: number; tier: number; type: string; cost: number }; +const API_URL = "http://localhost:2500"; +type transaction = { id: number; tier: number; enchantment: number, type: string; silver: number; timestamp: number }; export function meta({}: Route.MetaArgs) { return [{ title: "Albion Online Transaction Tracker" }]; @@ -12,6 +13,7 @@ export function meta({}: Route.MetaArgs) { export default function Home() { return ( <> + ); @@ -40,10 +42,10 @@ function TransactionTable() { {transactions.map((transaction) => ( - - {transaction.tier} + {new Date(transaction.timestamp*1000).toLocaleDateString()} {new Date(transaction.timestamp*1000).toLocaleTimeString()} + {transaction.tier}.{transaction.enchantment} {transaction.type} - {transaction.cost} + {transaction.silver} ))}