add bill summary section
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useBill } from "../hooks";
|
||||
import { BillItemRow } from "./BillItemRow";
|
||||
import { BillSummary } from "./BillSummary";
|
||||
import { ItemForm } from "./ItemForm";
|
||||
|
||||
export default function App() {
|
||||
@@ -31,6 +32,8 @@ export default function App() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<BillSummary bill={computedBill} />
|
||||
|
||||
{computedBill.items.length > 0 && (
|
||||
<button
|
||||
className="w-full border border-gray-200 text-gray-400 hover:text-red-400 hover:border-red-200 py-3 rounded-xl text-sm transition-all cursor-pointer"
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { ComputedBill } from "../types";
|
||||
import { formatCurrency } from "../utils";
|
||||
|
||||
interface BillSummaryProps {
|
||||
bill: ComputedBill;
|
||||
}
|
||||
|
||||
export function BillSummary({ bill }: BillSummaryProps) {
|
||||
if (bill.items.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="p-4 rounded-2xl bg-white shadow-sm">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex justify-between text-sm text-gray-500">
|
||||
<span>Subtotal</span>
|
||||
<span>{formatCurrency(bill.subtotal, bill.currency)}</span>
|
||||
</div>
|
||||
|
||||
{bill.taxPercent > 0 && (
|
||||
<div className="flex justify-between text-sm text-gray-500">
|
||||
<span>
|
||||
{bill.taxType} {bill.taxPercent}%
|
||||
</span>
|
||||
<span>{formatCurrency(bill.taxAmount, bill.currency)}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="border-t border-gray-100 mt-1 pt-2 flex justify-between items-center">
|
||||
<span className="font-bold text-gray-800">Total</span>
|
||||
<span className="font-bold text-indigo-600 text-lg">
|
||||
{formatCurrency(bill.total, bill.currency)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user