page.tsx71 lines, 2.0 KB
| 1 | import { |
| 2 | Card, |
| 3 | CardContent, |
| 4 | CardDescription, |
| 5 | CardHeader, |
| 6 | CardTitle, |
| 7 | } from "@/components/ui/card"; |
| 8 | import { UrlShortenerForm } from "@/components/urls/url-shortener-form"; |
| 9 | import { UserUrlsTable } from "@/components/urls/user-urls-table"; |
| 10 | import { getUserUrls } from "@/server/actions/urls/get-user-urls"; |
| 11 | import { auth } from "@/server/auth"; |
| 12 | import { Metadata } from "next"; |
| 13 | import Link from "next/link"; |
| 14 | |
| 15 | export const metadata: Metadata = { |
| 16 | title: "Dashboard | ShortLink", |
| 17 | description: "Dashboard page", |
| 18 | }; |
| 19 | |
| 20 | export default async function DashboardPage() { |
| 21 | const session = await auth(); |
| 22 | |
| 23 | // Get user's URLs |
| 24 | const response = await getUserUrls(session?.user.id as string); |
| 25 | const userUrls = response.success && response.data ? response.data : []; |
| 26 | |
| 27 | return ( |
| 28 | <> |
| 29 | <h1 className="text-3xl font-bold mb-8 text-center">Dashboard</h1> |
| 30 | |
| 31 | <div className="grid gap-8"> |
| 32 | <Card className="shadow-sm"> |
| 33 | <CardHeader> |
| 34 | <CardTitle>Create New Short URL</CardTitle> |
| 35 | <CardDescription> |
| 36 | Enter a long URL to create a shortened link. You can also |
| 37 | customize the short code. |
| 38 | </CardDescription> |
| 39 | </CardHeader> |
| 40 | <CardContent> |
| 41 | <UrlShortenerForm /> |
| 42 | </CardContent> |
| 43 | </Card> |
| 44 | |
| 45 | <Card className="shadow-sm border border-dashed"> |
| 46 | <CardHeader> |
| 47 | <CardTitle>Your URLs</CardTitle> |
| 48 | <CardDescription> |
| 49 | Manage and track your shortened URLs. |
| 50 | </CardDescription> |
| 51 | </CardHeader> |
| 52 | <CardContent> |
| 53 | <UserUrlsTable urls={userUrls} /> |
| 54 | </CardContent> |
| 55 | </Card> |
| 56 | |
| 57 | {process.env.NODE_ENV === "development" && |
| 58 | session?.user.role === "admin" && ( |
| 59 | <div className="text-center mt-4"> |
| 60 | <Link |
| 61 | href={"/admin"} |
| 62 | className="text-sm text-muted-foreground hover:text-primary underline" |
| 63 | > |
| 64 | Admin Tools |
| 65 | </Link> |
| 66 | </div> |
| 67 | )} |
| 68 | </div> |
| 69 | </> |
| 70 | ); |
| 71 | } |