import React, { useState, useEffect } from "react"; const App = () => { const [transactions, setTransactions] = useState([]); const [price, setPrice] = useState(5000); const [cups, setCups] = useState(0); useEffect(() => { fetch("/api/transactions") .then((res) => res.json()) .then((data) => setTransactions(data)); }, []); const handleAddTransaction = () => { const newTransaction = { price, cups, date: new Date().toISOString() }; fetch("/api/transactions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(newTransaction), }) .then((res) => res.json()) .then((data) => setTransactions([...transactions, data])); }; const totalRevenue = transactions.reduce((sum, t) => sum + t.price * t.cups, 0); return (

Aplikasi Kasir Es Teh

setCups(e.target.value)} placeholder="Jumlah Cup" />

Total Pendapatan: Rp {totalRevenue}

    {transactions.map((t, i) => (
  • {t.date} - {t.cups} cup - Rp {t.price * t.cups}
  • ))}
); }; export default App;