From 48c24de67624fa4e4ef96a7c4c5a2b00e0183a54 Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Sat, 30 Dec 2023 14:51:00 +0100 Subject: [PATCH] Chapter 7 - fetch data from server --- app/dashboard/page.tsx | 40 ++++++++++++++++++++++++++-- app/ui/dashboard/latest-invoices.tsx | 4 +-- app/ui/dashboard/revenue-chart.tsx | 12 ++++----- package-lock.json | 14 +++++----- package.json | 3 ++- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index feb2238..587325f 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,3 +1,39 @@ -export default function Page() { - return

Dashboard Page

; +import { Card } from '@/app/ui/dashboard/cards'; +import RevenueChart from '@/app/ui/dashboard/revenue-chart'; +import LatestInvoices from '@/app/ui/dashboard/latest-invoices'; +import { lusitana } from '@/app/ui/fonts'; +import { fetchRevenue, fetchLatestInvoices, fetchCardData} from "@/app/lib/data"; + +export default async function Page() { + + const revenue = await fetchRevenue(); + const latestInvoices = await fetchLatestInvoices(); + + const { + numberOfInvoices, + numberOfCustomers, + totalPaidInvoices, + totalPendingInvoices, + } = await fetchCardData(); + return ( +
+

+ Dashboard +

+
+ + + + +
+
+ + +
+
+ ); } \ No newline at end of file diff --git a/app/ui/dashboard/latest-invoices.tsx b/app/ui/dashboard/latest-invoices.tsx index 92962ee..5fba8ea 100644 --- a/app/ui/dashboard/latest-invoices.tsx +++ b/app/ui/dashboard/latest-invoices.tsx @@ -16,7 +16,7 @@ export default async function LatestInvoices({
{/* NOTE: comment in this code when you get to this point in the course */} - {/*
+
{latestInvoices.map((invoice, i) => { return (
); })} -
*/} +

Updated just now

diff --git a/app/ui/dashboard/revenue-chart.tsx b/app/ui/dashboard/revenue-chart.tsx index 7ccc409..1a189f7 100644 --- a/app/ui/dashboard/revenue-chart.tsx +++ b/app/ui/dashboard/revenue-chart.tsx @@ -17,11 +17,11 @@ export default async function RevenueChart({ const chartHeight = 350; // NOTE: comment in this code when you get to this point in the course - // const { yAxisLabels, topLabel } = generateYAxis(revenue); + const { yAxisLabels, topLabel } = generateYAxis(revenue); - // if (!revenue || revenue.length === 0) { - // return

No data available.

; - // } + if (!revenue || revenue.length === 0) { + return

No data available.

; + } return (
@@ -30,7 +30,7 @@ export default async function RevenueChart({ {/* NOTE: comment in this code when you get to this point in the course */} - {/*
+

Last 12 months

-
*/} +
); } diff --git a/package-lock.json b/package-lock.json index 43432d7..fcb753e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1534,12 +1534,12 @@ "dev": true }, "node_modules/@vercel/postgres": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/@vercel/postgres/-/postgres-0.5.0.tgz", - "integrity": "sha512-MFWp9SZmADqBe2x2mzEvwmGLiwOd8PVkUxYeBZx/RqdHl0bd8/1BH0zBR+zSimGyi9P/MVtZoJLdf5dkWw9m5Q==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@vercel/postgres/-/postgres-0.5.1.tgz", + "integrity": "sha512-JKl8QOBIDnifhkxAhIKtY0A5Tb8oWBf2nzZhm0OH7Ffjsl0hGVnDL2w1/FCfpX8xna3JAWM034NGuhZfTFdmiw==", "dependencies": { "@neondatabase/serverless": "0.6.0", - "bufferutil": "4.0.7", + "bufferutil": "4.0.8", "utf-8-validate": "6.0.3", "ws": "8.14.2" }, @@ -2037,9 +2037,9 @@ } }, "node_modules/bufferutil": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.7.tgz", - "integrity": "sha512-kukuqc39WOHtdxtw4UScxF/WVnMFVSQVKhtx3AjZJzhd0RGZZldcrfSEbVsWWe6KNH253574cq5F+wpv0G9pJw==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz", + "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==", "hasInstallScript": true, "dependencies": { "node-gyp-build": "^4.3.0" diff --git a/package.json b/package.json index 0a75375..0cfa589 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "dev": "next dev", "prettier": "prettier --write --ignore-unknown .", "prettier:check": "prettier --check --ignore-unknown .", - "start": "next start" + "start": "next start", + "seed": "node -r dotenv/config ./scripts/seed.js" }, "dependencies": { "@heroicons/react": "^2.0.18",