Skip to content

Commit 99a944b

Browse files
committed
add 'landing.ts' to dashboard
1 parent 197dc76 commit 99a944b

File tree

9 files changed

+199
-19
lines changed

9 files changed

+199
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727
# local env files
2828
.env*.local
2929
.env
30+
.env.development.local
3031

3132
# vercel
3233
.vercel

app/dashboard/(overview)/loading.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import DashboardSkeleton from '@/app/ui/skeletons';
2+
3+
export default function Loading() {
4+
return <DashboardSkeleton />;
5+
}

app/dashboard/(overview)/page.tsx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Card } from '@/app/ui/dashboard/cards';
2+
import RevenueChart from '@/app/ui/dashboard/revenue-chart';
3+
import LatestInvoices from '@/app/ui/dashboard/latest-invoices';
4+
import { lusitana } from '@/app/ui/fonts';
5+
import {
6+
fetchRevenue,
7+
fetchLatestInvoices,
8+
fetchCardData,
9+
} from '@/app/lib/data';
10+
11+
export default async function Page() {
12+
const revenue = await fetchRevenue();
13+
const latestInvoices = await fetchLatestInvoices();
14+
const {
15+
numberOfInvoices,
16+
numberOfCustomers,
17+
totalPaidInvoices,
18+
totalPendingInvoices,
19+
} = await fetchCardData();
20+
21+
return (
22+
<main>
23+
<h1 className={`${lusitana.className} mb-4 text-xl md:text-2xl`}>
24+
Dashboard
25+
</h1>
26+
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-4">
27+
<Card title="Collected" value={totalPaidInvoices} type="collected" />
28+
<Card title="Pending" value={totalPendingInvoices} type="pending" />
29+
<Card title="Total Invoices" value={numberOfInvoices} type="invoices" />
30+
<Card
31+
title="Total Customers"
32+
value={numberOfCustomers}
33+
type="customers"
34+
/>
35+
</div>
36+
<div className="mt-6 grid grid-cols-1 gap-6 md:grid-cols-4 lg:grid-cols-8">
37+
<RevenueChart revenue={revenue} />
38+
<LatestInvoices latestInvoices={latestInvoices} />
39+
</div>
40+
</main>
41+
);
42+
}

app/dashboard/page.tsx

-3
This file was deleted.

app/lib/data.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { sql } from '@vercel/postgres';
2+
import { unstable_noStore as noStore } from 'next/cache';
23
import {
34
CustomerField,
45
CustomersTableType,
@@ -13,13 +14,14 @@ import { formatCurrency } from './utils';
1314
export async function fetchRevenue() {
1415
// Add noStore() here to prevent the response from being cached.
1516
// This is equivalent to in fetch(..., {cache: 'no-store'}).
17+
noStore();
1618

1719
try {
1820
// Artificially delay a response for demo purposes.
1921
// Don't do this in production :)
2022

21-
// console.log('Fetching revenue data...');
22-
// await new Promise((resolve) => setTimeout(resolve, 3000));
23+
console.log('Fetching revenue data...');
24+
await new Promise((resolve) => setTimeout(resolve, 3000));
2325

2426
const data = await sql<Revenue>`SELECT * FROM revenue`;
2527

@@ -33,6 +35,8 @@ export async function fetchRevenue() {
3335
}
3436

3537
export async function fetchLatestInvoices() {
38+
noStore();
39+
3640
try {
3741
const data = await sql<LatestInvoiceRaw>`
3842
SELECT invoices.amount, customers.name, customers.image_url, customers.email, invoices.id
@@ -53,6 +57,8 @@ export async function fetchLatestInvoices() {
5357
}
5458

5559
export async function fetchCardData() {
60+
noStore();
61+
5662
try {
5763
// You can probably combine these into a single SQL query
5864
// However, we are intentionally splitting them to demonstrate
@@ -92,6 +98,8 @@ export async function fetchFilteredInvoices(
9298
query: string,
9399
currentPage: number,
94100
) {
101+
noStore();
102+
95103
const offset = (currentPage - 1) * ITEMS_PER_PAGE;
96104

97105
try {
@@ -124,6 +132,8 @@ export async function fetchFilteredInvoices(
124132
}
125133

126134
export async function fetchInvoicesPages(query: string) {
135+
noStore();
136+
127137
try {
128138
const count = await sql`SELECT COUNT(*)
129139
FROM invoices
@@ -145,6 +155,8 @@ export async function fetchInvoicesPages(query: string) {
145155
}
146156

147157
export async function fetchInvoiceById(id: string) {
158+
noStore();
159+
148160
try {
149161
const data = await sql<InvoiceForm>`
150162
SELECT
@@ -170,6 +182,8 @@ export async function fetchInvoiceById(id: string) {
170182
}
171183

172184
export async function fetchCustomers() {
185+
noStore();
186+
173187
try {
174188
const data = await sql<CustomerField>`
175189
SELECT
@@ -188,6 +202,8 @@ export async function fetchCustomers() {
188202
}
189203

190204
export async function fetchFilteredCustomers(query: string) {
205+
noStore();
206+
191207
try {
192208
const data = await sql<CustomersTableType>`
193209
SELECT
@@ -221,6 +237,8 @@ export async function fetchFilteredCustomers(query: string) {
221237
}
222238

223239
export async function getUser(email: string) {
240+
noStore();
241+
224242
try {
225243
const user = await sql`SELECT * FROM users WHERE email=${email}`;
226244
return user.rows[0] as User;

app/ui/dashboard/latest-invoices.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default async function LatestInvoices({
1616
<div className="flex grow flex-col justify-between rounded-xl bg-gray-50 p-4">
1717
{/* NOTE: comment in this code when you get to this point in the course */}
1818

19-
{/* <div className="bg-white px-6">
19+
<div className="bg-white px-6">
2020
{latestInvoices.map((invoice, i) => {
2121
return (
2222
<div
@@ -53,7 +53,7 @@ export default async function LatestInvoices({
5353
</div>
5454
);
5555
})}
56-
</div> */}
56+
</div>
5757
<div className="flex items-center pb-2 pt-6">
5858
<ArrowPathIcon className="h-5 w-5 text-gray-500" />
5959
<h3 className="ml-2 text-sm text-gray-500 ">Updated just now</h3>

app/ui/dashboard/revenue-chart.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export default async function RevenueChart({
1717
const chartHeight = 350;
1818
// NOTE: comment in this code when you get to this point in the course
1919

20-
// const { yAxisLabels, topLabel } = generateYAxis(revenue);
20+
const { yAxisLabels, topLabel } = generateYAxis(revenue);
2121

22-
// if (!revenue || revenue.length === 0) {
23-
// return <p className="mt-4 text-gray-400">No data available.</p>;
24-
// }
22+
if (!revenue || revenue.length === 0) {
23+
return <p className="mt-4 text-gray-400">No data available.</p>;
24+
}
2525

2626
return (
2727
<div className="w-full md:col-span-4">
@@ -30,7 +30,7 @@ export default async function RevenueChart({
3030
</h2>
3131
{/* NOTE: comment in this code when you get to this point in the course */}
3232

33-
{/* <div className="rounded-xl bg-gray-50 p-4">
33+
<div className="rounded-xl bg-gray-50 p-4">
3434
<div className="sm:grid-cols-13 mt-0 grid grid-cols-12 items-end gap-2 rounded-md bg-white p-4 md:gap-4">
3535
<div
3636
className="mb-6 hidden flex-col justify-between text-sm text-gray-400 sm:flex"
@@ -59,7 +59,7 @@ export default async function RevenueChart({
5959
<CalendarIcon className="h-5 w-5 text-gray-500" />
6060
<h3 className="ml-2 text-sm text-gray-500 ">Last 12 months</h3>
6161
</div>
62-
</div> */}
62+
</div>
6363
</div>
6464
);
6565
}

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"dev": "next dev",
66
"prettier": "prettier --write --ignore-unknown .",
77
"prettier:check": "prettier --check --ignore-unknown .",
8-
"start": "next start"
8+
"start": "next start",
9+
"seed": "node -r dotenv/config ./scripts/seed.js"
910
},
1011
"dependencies": {
1112
"@heroicons/react": "^2.0.18",
1213
"@tailwindcss/forms": "^0.5.7",
1314
"@types/node": "20.5.7",
14-
"@vercel/postgres": "^0.5.0",
15+
"@vercel/postgres": "^0.5.1",
1516
"autoprefixer": "10.4.15",
1617
"bcrypt": "^5.1.1",
1718
"clsx": "^2.0.0",

pnpm-lock.yaml

+120-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)