From 5225fc3b54ebee97e62bd0dcf8a20ca3ff7b6975 Mon Sep 17 00:00:00 2001 From: Stephanie Dietz <49788645+StephDietz@users.noreply.github.com> Date: Fri, 1 Sep 2023 08:49:59 -0500 Subject: [PATCH] Add table component (#132) * add table compoennt * format * format * change table type to be a card * update table header and link * update layout and table width * Update dashboard/15-final/app/ui/table.tsx --------- Co-authored-by: Delba de Oliveira Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> --- .../15-final/app/dashboard/invoices/page.tsx | 8 ++- dashboard/15-final/app/dashboard/layout.tsx | 2 +- dashboard/15-final/app/lib/definitions.tsx | 1 + dashboard/15-final/app/lib/dummy-data.tsx | 4 ++ dashboard/15-final/app/ui/table.tsx | 70 +++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 dashboard/15-final/app/ui/table.tsx diff --git a/dashboard/15-final/app/dashboard/invoices/page.tsx b/dashboard/15-final/app/dashboard/invoices/page.tsx index 403df46..dc34ed8 100644 --- a/dashboard/15-final/app/dashboard/invoices/page.tsx +++ b/dashboard/15-final/app/dashboard/invoices/page.tsx @@ -1,3 +1,9 @@ +import Table from "@/app/ui/table"; + export default function Page() { - return
List of invoices
+ return ( +
+ + + ) } diff --git a/dashboard/15-final/app/dashboard/layout.tsx b/dashboard/15-final/app/dashboard/layout.tsx index 12c6697..97baef4 100644 --- a/dashboard/15-final/app/dashboard/layout.tsx +++ b/dashboard/15-final/app/dashboard/layout.tsx @@ -11,4 +11,4 @@ export default function Layout({ children }: { children: React.ReactNode }) { ); -} +} \ No newline at end of file diff --git a/dashboard/15-final/app/lib/definitions.tsx b/dashboard/15-final/app/lib/definitions.tsx index 5618fff..95c633a 100644 --- a/dashboard/15-final/app/lib/definitions.tsx +++ b/dashboard/15-final/app/lib/definitions.tsx @@ -18,6 +18,7 @@ export type Invoice = { id: number customerId: number amount: number + date: string status: "pending" | "paid" // In TypeScript, this is called a string union type. // It means that the "status" property can only be one of the two strings. } diff --git a/dashboard/15-final/app/lib/dummy-data.tsx b/dashboard/15-final/app/lib/dummy-data.tsx index 5be5b0b..bf83355 100644 --- a/dashboard/15-final/app/lib/dummy-data.tsx +++ b/dashboard/15-final/app/lib/dummy-data.tsx @@ -38,24 +38,28 @@ export const invoices: Invoice[] = [ id: 1, customerId: 1, amount: 15795, + date: "2021-01-01", status: "pending", }, { id: 2, customerId: 2, amount: 20348, + date: "2021-02-01", status: "pending", }, { id: 3, customerId: 3, amount: 3040, + date: "2021-03-01", status: "paid", }, { id: 4, customerId: 4, amount: 44800, + date: "2021-04-01", status: "paid", }, ]; diff --git a/dashboard/15-final/app/ui/table.tsx b/dashboard/15-final/app/ui/table.tsx new file mode 100644 index 0000000..80e80fb --- /dev/null +++ b/dashboard/15-final/app/ui/table.tsx @@ -0,0 +1,70 @@ +import {invoices, customers} from "../lib/dummy-data"; +import Link from "next/link"; + +export default function Example() { + function getNameById(customerId: number) { + const customerName = customers.find(customer => customer.id === customerId); + return customerName ? customerName.name : null; + } + return ( +
+
+

Invoices

+ + Add Invoice + +
+
+
+
+
+ + + + + + + + + + + + {invoices.map((invoice) => ( + + + + + + + + + ))} + +
+ ID + + Customer Name + + Amount + + Status + + Date + + View +
+ {invoice.id} + {getNameById(invoice.customerId)}{(invoice.amount / 100).toLocaleString("en-US", {style: "currency", currency: "USD"})}{invoice.status}{invoice.date} + + View, {invoice.id} + +
+
+ + + + ) +}