Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learn run through 💅🏼 #230

Merged
merged 24 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DashboardSkeleton from '@/app/ui/dashboard/skeletons';
import DashboardSkeleton from '@/app/ui/skeletons';

export default function Loading() {
return <DashboardSkeleton />;
Expand Down
2 changes: 1 addition & 1 deletion dashboard/final-example/app/dashboard/(overview)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RevenueChartSkeleton,
LatestInvoicesSkeleton,
CardsSkeleton,
} from '@/app/ui/dashboard/skeletons';
} from '@/app/ui/skeletons';

export default async function Page() {
return (
Expand Down
2 changes: 1 addition & 1 deletion dashboard/final-example/app/dashboard/invoices/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Search from '@/app/ui/search';
import Table from '@/app/ui/invoices/table';
import { CreateInvoice } from '@/app/ui/invoices/buttons';
import { lusitana } from '@/app/ui/fonts';
import { InvoicesTableSkeleton } from '@/app/ui/dashboard/skeletons';
import { InvoicesTableSkeleton } from '@/app/ui/skeletons';
import { Suspense } from 'react';
import { fetchInvoicesPages } from '@/app/lib/data';
import { Metadata } from 'next';
Expand Down
4 changes: 2 additions & 2 deletions dashboard/final-example/app/lib/placeholder-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ const customers = [
{
id: 'CC27C14A-0ACF-4F4A-A6C9-D45682C144B9',
name: 'Amy Burns',
email: 'amy.burns@vercel.com',
email: 'amy@burns.com',
image_url: '/customers/amy-burns.png',
},
{
id: '13D07535-C59E-4157-A011-F8D2EF4E0CBB',
name: 'Balazs Orban',
email: 'balazs.orban@vercel.com',
email: 'balazs@orban.com',
image_url: '/customers/balazs-orban.png',
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# `openssl rand -base64 32`
AUTH_SECRET=
AUTH_URL=http://localhost:3000/api/auth
1 change: 0 additions & 1 deletion dashboard/starter-example/app/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export async function fetchInvoiceById(id: string) {
return invoice[0];
} catch (error) {
console.error('Database Error:', error);
throw new Error('Failed to fetch invoice.');
}
}

Expand Down
4 changes: 2 additions & 2 deletions dashboard/starter-example/app/lib/placeholder-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ const customers = [
{
id: 'CC27C14A-0ACF-4F4A-A6C9-D45682C144B9',
name: 'Amy Burns',
email: 'amy.burns@vercel.com',
email: 'amy@burns.com',
image_url: '/customers/amy-burns.png',
},
{
id: '13D07535-C59E-4157-A011-F8D2EF4E0CBB',
name: 'Balazs Orban',
email: 'balazs.orban@vercel.com',
email: 'balazs@orban.com',
image_url: '/customers/balazs-orban.png',
},
];
Expand Down
1 change: 1 addition & 0 deletions dashboard/starter-example/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AcmeLogo from '@/app/ui/acme-logo';

import Link from 'next/link';
export default function Page() {
return (
Expand Down
6 changes: 4 additions & 2 deletions dashboard/starter-example/app/ui/dashboard/cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ const iconMap = {
export default async function Cards() {
return (
<>
<Card title="Collected" value={totalPaidInvoices} type="collected" />
{/* NOTE: comment in this code when you get to this point in the course */}

{/* <Card title="Collected" value={totalPaidInvoices} type="collected" />
<Card title="Pending" value={totalPendingInvoices} type="pending" />
<Card title="Total Invoices" value={numberOfInvoices} type="invoices" />
<Card
title="Total Customers"
value={numberOfCustomers}
type="customers"
/>
/> */}
</>
);
}
Expand Down
13 changes: 10 additions & 3 deletions dashboard/starter-example/app/ui/dashboard/latest-invoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import { ArrowPathIcon } from '@heroicons/react/24/outline';
import clsx from 'clsx';
import Image from 'next/image';
import { lusitana } from '@/app/ui/fonts';
export default async function LatestInvoices() {
import { LatestInvoice } from '@/app/lib/definitions';
export default async function LatestInvoices({
latestInvoices,
}: {
latestInvoices: LatestInvoice[];
}) {
return (
<div className="flex w-full flex-col md:col-span-4 lg:col-span-4">
<h2 className={`${lusitana.className} mb-4 text-xl md:text-2xl`}>
Latest Invoices
</h2>
<div className="flex grow flex-col justify-between rounded-xl bg-gray-50 p-4">
<div className="bg-white px-6">
{/* NOTE: comment in this code when you get to this point in the course */}

{/* <div className="bg-white px-6">
{latestInvoices.map((invoice, i) => {
return (
<div
Expand Down Expand Up @@ -45,7 +52,7 @@ export default async function LatestInvoices() {
</div>
);
})}
</div>
</div> */}
<div className="flex items-center pb-2 pt-6">
<ArrowPathIcon className="h-5 w-5 text-gray-500" />
<h3 className="ml-2 text-sm text-gray-500 ">Updated just now</h3>
Expand Down
6 changes: 1 addition & 5 deletions dashboard/starter-example/app/ui/dashboard/nav-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
HomeIcon,
DocumentDuplicateIcon,
} from '@heroicons/react/24/outline';
import clsx from 'clsx';

// Map of links to display in the side navigation.
// Depending on the size of the application, this would be stored in a database.
Expand All @@ -26,10 +25,7 @@ export default function NavLinks() {
<a
key={link.name}
href={link.href}
className={clsx(
'flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3',
)}
Copy link

@pringshia pringshia Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that removing clsx from this file has "invalidated" the quiz answer at nextjs.com/learn - the question is now stale and the responses don't make sense.

CleanShot 2023-10-30 at 14 34 26@2x

>
className='flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3'>
<LinkIcon className="w-6" />
<p className="hidden md:block">{link.name}</p>
</a>
Expand Down
26 changes: 16 additions & 10 deletions dashboard/starter-example/app/ui/dashboard/revenue-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
import { generateYAxis } from '@/app/lib/utils';
import { CalendarIcon } from '@heroicons/react/24/outline';
import { lusitana } from '@/app/ui/fonts';
import { Revenue } from '@/app/lib/definitions';

// This component is representational only.
// For data visualization UI, check out:
// https://www.tremor.so/
// https://www.chartjs.org/
// https://airbnb.io/visx/

export default async function RevenueChart() {
export default async function RevenueChart({
revenue,
}: {
revenue: Revenue[];
}) {
const chartHeight = 350;
const { yAxisLabels, topLabel } = generateYAxis(revenue);
// NOTE: comment in this code when you get to this point in the course

if (!revenue || revenue.length === 0) {
return <p className="mt-4 text-gray-400">No data available.</p>;
}
// const { yAxisLabels, topLabel } = generateYAxis(revenue);

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

return (
<div className="w-full md:col-span-4">
<h2 className={`${lusitana.className} mb-4 text-xl md:text-2xl`}>
Recent Revenue
</h2>
<div className="rounded-xl bg-gray-50 p-4">
{/* NOTE: comment in this code when you get to this point in the course */}

{/* <div className="rounded-xl bg-gray-50 p-4">
<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">
{/* y-axis */}
<div
className="mb-6 hidden flex-col justify-between text-sm text-gray-400 sm:flex"
style={{ height: `${chartHeight}px` }}
Expand All @@ -35,14 +43,12 @@ export default async function RevenueChart() {

{revenue.map((month) => (
<div key={month.month} className="flex flex-col items-center gap-2">
{/* bars */}
<div
className="w-full rounded-md bg-blue-300"
style={{
height: `${(chartHeight / topLabel) * month.revenue}px`,
}}
></div>
{/* x-axis */}
<p className="-rotate-90 text-sm text-gray-400 sm:rotate-0">
{month.month}
</p>
Expand All @@ -53,7 +59,7 @@ export default async function RevenueChart() {
<CalendarIcon className="h-5 w-5 text-gray-500" />
<h3 className="ml-2 text-sm text-gray-500 ">Last 12 months</h3>
</div>
</div>
</div> */}
</div>
);
}
10 changes: 2 additions & 8 deletions dashboard/starter-example/app/ui/dashboard/sidenav.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Link from 'next/link';
import NavLinks from '@/app/ui/dashboard/nav-links';
import AcmeLogo from '../acme-logo';
import AcmeLogo from '@/app/ui/acme-logo';
import { PowerIcon } from '@heroicons/react/24/outline';
import { signOut } from '@/auth';

export default function SideNav() {
return (
Expand All @@ -18,12 +17,7 @@ export default function SideNav() {
<div className="flex grow flex-row justify-between space-x-2 md:flex-col md:space-x-0 md:space-y-2">
<NavLinks />
<div className="hidden h-auto w-full grow rounded-md bg-gray-50 md:block"></div>
<form
action={async () => {
'use server';
await signOut();
}}
>
<form>
<button className="flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3">
<PowerIcon className="w-6" />
<div className="hidden md:block">Sign Out</div>
Expand Down
8 changes: 3 additions & 5 deletions dashboard/starter-example/app/ui/invoices/buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PencilIcon, PlusIcon, TrashIcon } from '@heroicons/react/24/outline';
import Link from 'next/link';
import { deleteInvoice } from '@/app/lib/actions';

export function CreateInvoice() {
return (
Expand All @@ -17,7 +16,7 @@ export function CreateInvoice() {
export function UpdateInvoice({ id }: { id: string }) {
return (
<Link
href={`/dashboard/invoices/${id}/edit`}
href="/dashboard/invoices"
className="rounded-md border p-2 hover:bg-gray-100"
>
<PencilIcon className="w-5" />
Expand All @@ -27,12 +26,11 @@ export function UpdateInvoice({ id }: { id: string }) {

export function DeleteInvoice({ id }: { id: string }) {
return (
<form action={deleteInvoice}>
<input type="hidden" name="id" value={id} />
<>
<button className="rounded-md border p-2 hover:bg-gray-100">
<span className="sr-only">Delete</span>
<TrashIcon className="w-5" />
</button>
</form>
</>
);
}
2 changes: 1 addition & 1 deletion dashboard/starter-example/app/ui/invoices/edit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
UserCircleIcon,
} from '@heroicons/react/24/outline';
import Link from 'next/link';
import { Button } from '../button';
import { Button } from '@/app/ui/button';

export default function EditInvoiceForm({
invoice,
Expand Down
68 changes: 37 additions & 31 deletions dashboard/starter-example/app/ui/invoices/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,49 @@ import Link from 'next/link';
import { generatePagination } from '@/app/lib/utils';

export default function Pagination({ totalPages }: { totalPages: number }) {
const allPages = generatePagination(currentPage, totalPages);
// NOTE: comment in this code when you get to this point in the course

// const allPages = generatePagination(currentPage, totalPages);

return (
<div className="inline-flex">
<PaginationArrow
direction="left"
href={createPageURL(currentPage - 1)}
isDisabled={currentPage <= 1}
/>
<>
{/* NOTE: comment in this code when you get to this point in the course */}

{/* <div className="inline-flex">
<PaginationArrow
direction="left"
href={createPageURL(currentPage - 1)}
isDisabled={currentPage <= 1}
/>

<div className="flex -space-x-px">
{allPages.map((page, index) => {
let position: 'first' | 'last' | 'single' | 'middle' | undefined;
<div className="flex -space-x-px">
{allPages.map((page, index) => {
let position: 'first' | 'last' | 'single' | 'middle' | undefined;

if (index === 0) position = 'first';
if (index === allPages.length - 1) position = 'last';
if (allPages.length === 1) position = 'single';
if (page === '...') position = 'middle';
if (index === 0) position = 'first';
if (index === allPages.length - 1) position = 'last';
if (allPages.length === 1) position = 'single';
if (page === '...') position = 'middle';

return (
<PaginationNumber
key={page}
href={createPageURL(page)}
page={page}
position={position}
isActive={currentPage === page}
/>
);
})}
</div>
return (
<PaginationNumber
key={page}
href={createPageURL(page)}
page={page}
position={position}
isActive={currentPage === page}
/>
);
})}
</div>

<PaginationArrow
direction="right"
href={createPageURL(currentPage + 1)}
isDisabled={currentPage >= totalPages}
/>
</div>
<PaginationArrow
direction="right"
href={createPageURL(currentPage + 1)}
isDisabled={currentPage >= totalPages}
/>
</div> */}
</>
);
}

Expand Down
1 change: 0 additions & 1 deletion dashboard/starter-example/app/ui/invoices/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default async function InvoicesTable({
className="mr-2 rounded-full"
width={28}
height={28}
alt={`${invoice.name}'s profile picture`}
/>
<p>{invoice.name}</p>
</div>
Expand Down
2 changes: 0 additions & 2 deletions dashboard/starter-example/app/ui/login-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use client';

import { lusitana } from '@/app/ui/fonts';
import {
AtSymbolIcon,
Expand Down
Loading
Loading