├── .commitlintrc.json ├── .editorconfig ├── .env.example ├── .eslintrc.json ├── .gitignore ├── .husky ├── commit-msg └── pre-commit ├── .nvmrc ├── .prettierignore ├── LICENSE.md ├── README.md ├── app ├── (auth) │ ├── layout.tsx │ ├── login │ │ └── page.tsx │ └── register │ │ └── page.tsx ├── (dashboard) │ └── dashboard │ │ ├── billing │ │ ├── loading.tsx │ │ └── page.tsx │ │ ├── layout.tsx │ │ ├── loading.tsx │ │ ├── page.tsx │ │ └── settings │ │ ├── loading.tsx │ │ └── page.tsx ├── (docs) │ ├── docs │ │ ├── [[...slug]] │ │ │ └── page.tsx │ │ └── layout.tsx │ ├── guides │ │ ├── [...slug] │ │ │ └── page.tsx │ │ ├── layout.tsx │ │ └── page.tsx │ └── layout.tsx ├── (editor) │ └── editor │ │ ├── [postId] │ │ ├── loading.tsx │ │ ├── not-found.tsx │ │ └── page.tsx │ │ └── layout.tsx ├── (marketing) │ ├── [...slug] │ │ └── page.tsx │ ├── blog │ │ ├── [...slug] │ │ │ └── page.tsx │ │ └── page.tsx │ ├── layout.tsx │ ├── page.tsx │ └── pricing │ │ └── page.tsx ├── api │ ├── auth │ │ └── [...nextauth] │ │ │ └── _route.ts │ ├── og │ │ └── route.tsx │ ├── posts │ │ ├── [postId] │ │ │ └── route.ts │ │ └── route.ts │ ├── users │ │ ├── [userId] │ │ │ └── route.ts │ │ └── stripe │ │ │ └── route.ts │ └── webhooks │ │ └── stripe │ │ └── route.ts ├── layout.tsx ├── opengraph-image.jpg └── robots.ts ├── assets └── fonts │ ├── CalSans-SemiBold.ttf │ ├── CalSans-SemiBold.woff │ ├── CalSans-SemiBold.woff2 │ ├── Inter-Bold.ttf │ └── Inter-Regular.ttf ├── components ├── analytics.tsx ├── billing-form.tsx ├── callout.tsx ├── card-skeleton.tsx ├── editor.tsx ├── empty-placeholder.tsx ├── header.tsx ├── icons.tsx ├── main-nav.tsx ├── mdx-card.tsx ├── mdx-components.tsx ├── mobile-nav.tsx ├── mode-toggle.tsx ├── nav.tsx ├── page-header.tsx ├── pager.tsx ├── post-create-button.tsx ├── post-item.tsx ├── post-operations.tsx ├── search.tsx ├── shell.tsx ├── sidebar-nav.tsx ├── site-footer.tsx ├── tailwind-indicator.tsx ├── theme-provider.tsx ├── toc.tsx ├── ui │ ├── accordion.tsx │ ├── alert-dialog.tsx │ ├── alert.tsx │ ├── aspect-ratio.tsx │ ├── avatar.tsx │ ├── badge.tsx │ ├── button.tsx │ ├── calendar.tsx │ ├── card.tsx │ ├── checkbox.tsx │ ├── collapsible.tsx │ ├── command.tsx │ ├── context-menu.tsx │ ├── dialog.tsx │ ├── dropdown-menu.tsx │ ├── hover-card.tsx │ ├── input.tsx │ ├── label.tsx │ ├── menubar.tsx │ ├── navigation-menu.tsx │ ├── popover.tsx │ ├── progress.tsx │ ├── radio-group.tsx │ ├── scroll-area.tsx │ ├── select.tsx │ ├── separator.tsx │ ├── sheet.tsx │ ├── skeleton.tsx │ ├── slider.tsx │ ├── switch.tsx │ ├── tabs.tsx │ ├── textarea.tsx │ ├── toast.tsx │ ├── toaster.tsx │ ├── toggle.tsx │ ├── tooltip.tsx │ └── use-toast.ts ├── user-account-nav.tsx ├── user-auth-form.tsx ├── user-avatar.tsx └── user-name-form.tsx ├── config ├── dashboard.ts ├── docs.ts ├── marketing.ts ├── site.ts └── subscriptions.ts ├── content ├── authors │ └── shadcn.mdx ├── blog │ ├── deploying-next-apps.mdx │ ├── dynamic-routing-static-regeneration.mdx │ ├── preview-mode-headless-cms.mdx │ └── server-client-components.mdx ├── docs │ ├── documentation │ │ ├── code-blocks.mdx │ │ ├── components.mdx │ │ ├── index.mdx │ │ └── style-guide.mdx │ ├── in-progress.mdx │ └── index.mdx ├── guides │ ├── build-blog-using-contentlayer-mdx.mdx │ └── using-next-auth-next-13.mdx └── pages │ ├── privacy.mdx │ └── terms.mdx ├── contentlayer.config.js ├── env.mjs ├── hooks ├── use-lock-body.ts └── use-mounted.ts ├── lib ├── auth.ts ├── db.ts ├── exceptions.ts ├── session.ts ├── stripe.ts ├── subscription.ts ├── toc.ts ├── utils.ts └── validations │ ├── auth.ts │ ├── og.ts │ ├── post.ts │ └── user.ts ├── middleware.ts ├── next.config.mjs ├── package.json ├── pages └── api │ └── auth │ └── [...nextauth].ts ├── pnpm-lock.yaml ├── postcss.config.js ├── prettier.config.js ├── prisma ├── migrations │ ├── 20221021182747_init │ │ └── migration.sql │ ├── 20221118173244_add_stripe_columns │ │ └── migration.sql │ └── migration_lock.toml └── schema.prisma ├── public ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── images │ ├── avatars │ │ └── shadcn.png │ ├── blog │ │ ├── blog-post-1.jpg │ │ ├── blog-post-2.jpg │ │ ├── blog-post-3.jpg │ │ └── blog-post-4.jpg │ └── hero.png ├── og.jpg ├── site.webmanifest └── vercel.svg ├── styles ├── editor.css ├── globals.css └── mdx.css ├── tailwind.config.js ├── tsconfig.json └── types ├── index.d.ts └── next-auth.d.ts /.commitlintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["@commitlint/config-conventional"] 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # App 3 | # ----------------------------------------------------------------------------- 4 | NEXT_PUBLIC_APP_URL=http://localhost:3000 5 | 6 | # ----------------------------------------------------------------------------- 7 | # Authentication (NextAuth.js) 8 | # ----------------------------------------------------------------------------- 9 | NEXTAUTH_URL=http://localhost:3000 10 | NEXTAUTH_SECRET= 11 | 12 | GITHUB_CLIENT_ID= 13 | GITHUB_CLIENT_SECRET= 14 | GITHUB_ACCESS_TOKEN= 15 | 16 | # ----------------------------------------------------------------------------- 17 | # Database (MySQL - PlanetScale) 18 | # ----------------------------------------------------------------------------- 19 | DATABASE_URL="mysql://root:root@localhost:3306/taxonomy?schema=public" 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Email (Postmark) 23 | # ----------------------------------------------------------------------------- 24 | SMTP_FROM= 25 | POSTMARK_API_TOKEN= 26 | POSTMARK_SIGN_IN_TEMPLATE= 27 | POSTMARK_ACTIVATION_TEMPLATE= 28 | 29 | # ----------------------------------------------------------------------------- 30 | # Subscriptions (Stripe) 31 | # ----------------------------------------------------------------------------- 32 | STRIPE_API_KEY= 33 | STRIPE_WEBHOOK_SECRET= 34 | STRIPE_PRO_MONTHLY_PLAN_ID= -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/eslintrc", 3 | "root": true, 4 | "extends": [ 5 | "next/core-web-vitals", 6 | "prettier", 7 | "plugin:tailwindcss/recommended" 8 | ], 9 | "plugins": ["tailwindcss"], 10 | "rules": { 11 | "@next/next/no-html-link-for-pages": "off", 12 | "react/jsx-key": "off", 13 | "tailwindcss/no-custom-classname": "off", 14 | "tailwindcss/classnames-order": "error" 15 | }, 16 | "settings": { 17 | "tailwindcss": { 18 | "callees": ["cn"], 19 | "config": "tailwind.config.js" 20 | }, 21 | "next": { 22 | "rootDir": true 23 | } 24 | }, 25 | "overrides": [ 26 | { 27 | "files": ["*.ts", "*.tsx"], 28 | "parser": "@typescript-eslint/parser" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | .env 31 | 32 | # vercel 33 | .vercel 34 | 35 | # typescript 36 | *.tsbuildinfo 37 | next-env.d.ts 38 | 39 | .vscode 40 | .contentlayer -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx commitlint --edit $1 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx pretty-quick --staged 5 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v16.18.0 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | .next 4 | build 5 | .contentlayer -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 shadcn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Taxonomy 2 | 3 | An open source application built using the new router, server components and everything new in Next.js 13. 4 | 5 | > **Warning** 6 | > This app is a work in progress. I'm building this in public. You can follow the progress on Twitter [@shadcn](https://twitter.com/shadcn). 7 | > See the roadmap below. 8 | 9 | ## About this project 10 | 11 | This project as an experiment to see how a modern app (with features like authentication, subscriptions, API routes, static pages for docs ...etc) would work in Next.js 13 and server components. 12 | 13 | **This is not a starter template.** 14 | 15 | A few people have asked me to turn this into a starter. I think we could do that once the new features are out of beta. 16 | 17 | ## Note on Performance 18 | 19 | > **Warning** 20 | > This app is using the unstable releases for Next.js 13 and React 18. The new router and app dir is still in beta and not production-ready. 21 | > **Expect some performance hits when testing the dashboard**. 22 | > If you see something broken, you can ping me [@shadcn](https://twitter.com/shadcn). 23 | 24 | ## Features 25 | 26 | - New `/app` dir, 27 | - Routing, Layouts, Nested Layouts and Layout Groups 28 | - Data Fetching, Caching and Mutation 29 | - Loading UI 30 | - Route handlers 31 | - Metadata files 32 | - Server and Client Components 33 | - API Routes and Middlewares 34 | - Authentication using **NextAuth.js** 35 | - ORM using **Prisma** 36 | - Database on **PlanetScale** 37 | - UI Components built using **Radix UI** 38 | - Documentation and blog using **MDX** and **Contentlayer** 39 | - Subscriptions using **Stripe** 40 | - Styled using **Tailwind CSS** 41 | - Validations using **Zod** 42 | - Written in **TypeScript** 43 | 44 | ## Roadmap 45 | 46 | - [x] ~Add MDX support for basic pages~ 47 | - [x] ~Build marketing pages~ 48 | - [x] ~Subscriptions using Stripe~ 49 | - [x] ~Responsive styles~ 50 | - [x] ~Add OG image for blog using @vercel/og~ 51 | - [x] Dark mode 52 | 53 | ## Known Issues 54 | 55 | A list of things not working right now: 56 | 57 | 1. ~GitHub authentication (use email)~ 58 | 2. ~[Prisma: Error: ENOENT: no such file or directory, open '/var/task/.next/server/chunks/schema.prisma'](https://github.com/prisma/prisma/issues/16117)~ 59 | 3. ~[Next.js 13: Client side navigation does not update head](https://github.com/vercel/next.js/issues/42414)~ 60 | 4. [Cannot use opengraph-image.tsx inside catch-all routes](https://github.com/vercel/next.js/issues/48162) 61 | 62 | ## Why not tRPC, Turborepo or X? 63 | 64 | I might add this later. For now, I want to see how far we can get using Next.js only. 65 | 66 | If you have some suggestions, feel free to create an issue. 67 | 68 | ## Running Locally 69 | 70 | 1. Install dependencies using pnpm: 71 | 72 | ```sh 73 | pnpm install 74 | ``` 75 | 76 | 2. Copy `.env.example` to `.env.local` and update the variables. 77 | 78 | ```sh 79 | cp .env.example .env.local 80 | ``` 81 | 82 | 3. Start the development server: 83 | 84 | ```sh 85 | pnpm dev 86 | ``` 87 | 88 | ## License 89 | 90 | Licensed under the [MIT license](https://github.com/shadcn/taxonomy/blob/main/LICENSE.md). 91 | -------------------------------------------------------------------------------- /app/(auth)/layout.tsx: -------------------------------------------------------------------------------- 1 | interface AuthLayoutProps { 2 | children: React.ReactNode 3 | } 4 | 5 | export default function AuthLayout({ children }: AuthLayoutProps) { 6 | return
{children}
7 | } 8 | -------------------------------------------------------------------------------- /app/(auth)/login/page.tsx: -------------------------------------------------------------------------------- 1 | import { Metadata } from "next" 2 | import Link from "next/link" 3 | 4 | import { cn } from "@/lib/utils" 5 | import { buttonVariants } from "@/components/ui/button" 6 | import { Icons } from "@/components/icons" 7 | import { UserAuthForm } from "@/components/user-auth-form" 8 | 9 | export const metadata: Metadata = { 10 | title: "Login", 11 | description: "Login to your account", 12 | } 13 | 14 | export default function LoginPage() { 15 | return ( 16 |
17 | 24 | <> 25 | 26 | Back 27 | 28 | 29 |
30 |
31 | 32 |

33 | Welcome back 34 |

35 |

36 | Enter your email to sign in to your account 37 |

38 |
39 | 40 |

41 | 45 | Don't have an account? Sign Up 46 | 47 |

48 |
49 |
50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /app/(auth)/register/page.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | import { cn } from "@/lib/utils" 4 | import { buttonVariants } from "@/components/ui/button" 5 | import { Icons } from "@/components/icons" 6 | import { UserAuthForm } from "@/components/user-auth-form" 7 | 8 | export const metadata = { 9 | title: "Create an account", 10 | description: "Create an account to get started.", 11 | } 12 | 13 | export default function RegisterPage() { 14 | return ( 15 |
16 | 23 | Login 24 | 25 |
26 |
27 |
28 |
29 | 30 |

31 | Create an account 32 |

33 |

34 | Enter your email below to create your account 35 |

36 |
37 | 38 |

39 | By clicking continue, you agree to our{" "} 40 | 44 | Terms of Service 45 | {" "} 46 | and{" "} 47 | 51 | Privacy Policy 52 | 53 | . 54 |

55 |
56 |
57 |
58 | ) 59 | } 60 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/billing/loading.tsx: -------------------------------------------------------------------------------- 1 | import { CardSkeleton } from "@/components/card-skeleton" 2 | import { DashboardHeader } from "@/components/header" 3 | import { DashboardShell } from "@/components/shell" 4 | 5 | export default function DashboardBillingLoading() { 6 | return ( 7 | 8 | 12 |
13 | 14 |
15 |
16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/billing/page.tsx: -------------------------------------------------------------------------------- 1 | import { redirect } from "next/navigation" 2 | 3 | import { authOptions } from "@/lib/auth" 4 | import { getCurrentUser } from "@/lib/session" 5 | import { stripe } from "@/lib/stripe" 6 | import { getUserSubscriptionPlan } from "@/lib/subscription" 7 | import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" 8 | import { 9 | Card, 10 | CardContent, 11 | CardDescription, 12 | CardHeader, 13 | CardTitle, 14 | } from "@/components/ui/card" 15 | import { BillingForm } from "@/components/billing-form" 16 | import { DashboardHeader } from "@/components/header" 17 | import { Icons } from "@/components/icons" 18 | import { DashboardShell } from "@/components/shell" 19 | 20 | export const metadata = { 21 | title: "Billing", 22 | description: "Manage billing and your subscription plan.", 23 | } 24 | 25 | export default async function BillingPage() { 26 | const user = await getCurrentUser() 27 | 28 | if (!user) { 29 | redirect(authOptions?.pages?.signIn || "/login") 30 | } 31 | 32 | const subscriptionPlan = await getUserSubscriptionPlan(user.id) 33 | 34 | // If user has a pro plan, check cancel status on Stripe. 35 | let isCanceled = false 36 | if (subscriptionPlan.isPro && subscriptionPlan.stripeSubscriptionId) { 37 | const stripePlan = await stripe.subscriptions.retrieve( 38 | subscriptionPlan.stripeSubscriptionId 39 | ) 40 | isCanceled = stripePlan.cancel_at_period_end 41 | } 42 | 43 | return ( 44 | 45 | 49 |
50 | 51 | 52 | This is a demo app. 53 | 54 | Taxonomy app is a demo app using a Stripe test environment. You can 55 | find a list of test card numbers on the{" "} 56 | 62 | Stripe docs 63 | 64 | . 65 | 66 | 67 | 73 |
74 |
75 | ) 76 | } 77 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/layout.tsx: -------------------------------------------------------------------------------- 1 | import { notFound } from "next/navigation" 2 | 3 | import { dashboardConfig } from "@/config/dashboard" 4 | import { getCurrentUser } from "@/lib/session" 5 | import { MainNav } from "@/components/main-nav" 6 | import { DashboardNav } from "@/components/nav" 7 | import { SiteFooter } from "@/components/site-footer" 8 | import { UserAccountNav } from "@/components/user-account-nav" 9 | 10 | interface DashboardLayoutProps { 11 | children?: React.ReactNode 12 | } 13 | 14 | export default async function DashboardLayout({ 15 | children, 16 | }: DashboardLayoutProps) { 17 | const user = await getCurrentUser() 18 | 19 | if (!user) { 20 | return notFound() 21 | } 22 | 23 | return ( 24 |
25 |
26 |
27 | 28 | 35 |
36 |
37 |
38 | 41 |
42 | {children} 43 |
44 |
45 | 46 |
47 | ) 48 | } 49 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/loading.tsx: -------------------------------------------------------------------------------- 1 | import { DashboardHeader } from "@/components/header" 2 | import { PostCreateButton } from "@/components/post-create-button" 3 | import { PostItem } from "@/components/post-item" 4 | import { DashboardShell } from "@/components/shell" 5 | 6 | export default function DashboardLoading() { 7 | return ( 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/page.tsx: -------------------------------------------------------------------------------- 1 | import { redirect } from "next/navigation" 2 | 3 | import { authOptions } from "@/lib/auth" 4 | import { db } from "@/lib/db" 5 | import { getCurrentUser } from "@/lib/session" 6 | import { EmptyPlaceholder } from "@/components/empty-placeholder" 7 | import { DashboardHeader } from "@/components/header" 8 | import { PostCreateButton } from "@/components/post-create-button" 9 | import { PostItem } from "@/components/post-item" 10 | import { DashboardShell } from "@/components/shell" 11 | 12 | export const metadata = { 13 | title: "Dashboard", 14 | } 15 | 16 | export default async function DashboardPage() { 17 | const user = await getCurrentUser() 18 | 19 | if (!user) { 20 | redirect(authOptions?.pages?.signIn || "/login") 21 | } 22 | 23 | const posts = await db.post.findMany({ 24 | where: { 25 | authorId: user.id, 26 | }, 27 | select: { 28 | id: true, 29 | title: true, 30 | published: true, 31 | createdAt: true, 32 | }, 33 | orderBy: { 34 | updatedAt: "desc", 35 | }, 36 | }) 37 | 38 | return ( 39 | 40 | 41 | 42 | 43 |
44 | {posts?.length ? ( 45 |
46 | {posts.map((post) => ( 47 | 48 | ))} 49 |
50 | ) : ( 51 | 52 | 53 | No posts created 54 | 55 | You don't have any posts yet. Start creating content. 56 | 57 | 58 | 59 | )} 60 |
61 |
62 | ) 63 | } 64 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/settings/loading.tsx: -------------------------------------------------------------------------------- 1 | import { Card } from "@/components/ui/card" 2 | import { CardSkeleton } from "@/components/card-skeleton" 3 | import { DashboardHeader } from "@/components/header" 4 | import { DashboardShell } from "@/components/shell" 5 | 6 | export default function DashboardSettingsLoading() { 7 | return ( 8 | 9 | 13 |
14 | 15 |
16 |
17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /app/(dashboard)/dashboard/settings/page.tsx: -------------------------------------------------------------------------------- 1 | import { redirect } from "next/navigation" 2 | 3 | import { authOptions } from "@/lib/auth" 4 | import { getCurrentUser } from "@/lib/session" 5 | import { DashboardHeader } from "@/components/header" 6 | import { DashboardShell } from "@/components/shell" 7 | import { UserNameForm } from "@/components/user-name-form" 8 | 9 | export const metadata = { 10 | title: "Settings", 11 | description: "Manage account and website settings.", 12 | } 13 | 14 | export default async function SettingsPage() { 15 | const user = await getCurrentUser() 16 | 17 | if (!user) { 18 | redirect(authOptions?.pages?.signIn || "/login") 19 | } 20 | 21 | return ( 22 | 23 | 27 |
28 | 29 |
30 |
31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /app/(docs)/docs/[[...slug]]/page.tsx: -------------------------------------------------------------------------------- 1 | import { notFound } from "next/navigation" 2 | import { allDocs } from "contentlayer/generated" 3 | 4 | import { getTableOfContents } from "@/lib/toc" 5 | import { Mdx } from "@/components/mdx-components" 6 | import { DocsPageHeader } from "@/components/page-header" 7 | import { DocsPager } from "@/components/pager" 8 | import { DashboardTableOfContents } from "@/components/toc" 9 | 10 | import "@/styles/mdx.css" 11 | import { Metadata } from "next" 12 | 13 | import { env } from "@/env.mjs" 14 | import { absoluteUrl } from "@/lib/utils" 15 | 16 | interface DocPageProps { 17 | params: { 18 | slug: string[] 19 | } 20 | } 21 | 22 | async function getDocFromParams(params) { 23 | const slug = params.slug?.join("/") || "" 24 | const doc = allDocs.find((doc) => doc.slugAsParams === slug) 25 | 26 | if (!doc) { 27 | null 28 | } 29 | 30 | return doc 31 | } 32 | 33 | export async function generateMetadata({ 34 | params, 35 | }: DocPageProps): Promise { 36 | const doc = await getDocFromParams(params) 37 | 38 | if (!doc) { 39 | return {} 40 | } 41 | 42 | const url = env.NEXT_PUBLIC_APP_URL 43 | 44 | const ogUrl = new URL(`${url}/api/og`) 45 | ogUrl.searchParams.set("heading", doc.description ?? doc.title) 46 | ogUrl.searchParams.set("type", "Documentation") 47 | ogUrl.searchParams.set("mode", "dark") 48 | 49 | return { 50 | title: doc.title, 51 | description: doc.description, 52 | openGraph: { 53 | title: doc.title, 54 | description: doc.description, 55 | type: "article", 56 | url: absoluteUrl(doc.slug), 57 | images: [ 58 | { 59 | url: ogUrl.toString(), 60 | width: 1200, 61 | height: 630, 62 | alt: doc.title, 63 | }, 64 | ], 65 | }, 66 | twitter: { 67 | card: "summary_large_image", 68 | title: doc.title, 69 | description: doc.description, 70 | images: [ogUrl.toString()], 71 | }, 72 | } 73 | } 74 | 75 | export async function generateStaticParams(): Promise< 76 | DocPageProps["params"][] 77 | > { 78 | return allDocs.map((doc) => ({ 79 | slug: doc.slugAsParams.split("/"), 80 | })) 81 | } 82 | 83 | export default async function DocPage({ params }: DocPageProps) { 84 | const doc = await getDocFromParams(params) 85 | 86 | if (!doc) { 87 | notFound() 88 | } 89 | 90 | const toc = await getTableOfContents(doc.body.raw) 91 | 92 | return ( 93 |
94 |
95 | 96 | 97 |
98 | 99 |
100 |
101 |
102 | 103 |
104 |
105 |
106 | ) 107 | } 108 | -------------------------------------------------------------------------------- /app/(docs)/docs/layout.tsx: -------------------------------------------------------------------------------- 1 | import { docsConfig } from "@/config/docs" 2 | import { DocsSidebarNav } from "@/components/sidebar-nav" 3 | 4 | interface DocsLayoutProps { 5 | children: React.ReactNode 6 | } 7 | 8 | export default function DocsLayout({ children }: DocsLayoutProps) { 9 | return ( 10 |
11 | 14 | {children} 15 |
16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /app/(docs)/guides/[...slug]/page.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | import { notFound } from "next/navigation" 3 | import { allGuides } from "contentlayer/generated" 4 | 5 | import { getTableOfContents } from "@/lib/toc" 6 | import { Icons } from "@/components/icons" 7 | import { Mdx } from "@/components/mdx-components" 8 | import { DocsPageHeader } from "@/components/page-header" 9 | import { DashboardTableOfContents } from "@/components/toc" 10 | 11 | import "@/styles/mdx.css" 12 | import { Metadata } from "next" 13 | 14 | import { env } from "@/env.mjs" 15 | import { absoluteUrl, cn } from "@/lib/utils" 16 | import { buttonVariants } from "@/components/ui/button" 17 | 18 | interface GuidePageProps { 19 | params: { 20 | slug: string[] 21 | } 22 | } 23 | 24 | async function getGuideFromParams(params) { 25 | const slug = params?.slug?.join("/") 26 | const guide = allGuides.find((guide) => guide.slugAsParams === slug) 27 | 28 | if (!guide) { 29 | null 30 | } 31 | 32 | return guide 33 | } 34 | 35 | export async function generateMetadata({ 36 | params, 37 | }: GuidePageProps): Promise { 38 | const guide = await getGuideFromParams(params) 39 | 40 | if (!guide) { 41 | return {} 42 | } 43 | 44 | const url = env.NEXT_PUBLIC_APP_URL 45 | 46 | const ogUrl = new URL(`${url}/api/og`) 47 | ogUrl.searchParams.set("heading", guide.title) 48 | ogUrl.searchParams.set("type", "Guide") 49 | ogUrl.searchParams.set("mode", "dark") 50 | 51 | return { 52 | title: guide.title, 53 | description: guide.description, 54 | openGraph: { 55 | title: guide.title, 56 | description: guide.description, 57 | type: "article", 58 | url: absoluteUrl(guide.slug), 59 | images: [ 60 | { 61 | url: ogUrl.toString(), 62 | width: 1200, 63 | height: 630, 64 | alt: guide.title, 65 | }, 66 | ], 67 | }, 68 | twitter: { 69 | card: "summary_large_image", 70 | title: guide.title, 71 | description: guide.description, 72 | images: [ogUrl.toString()], 73 | }, 74 | } 75 | } 76 | 77 | export async function generateStaticParams(): Promise< 78 | GuidePageProps["params"][] 79 | > { 80 | return allGuides.map((guide) => ({ 81 | slug: guide.slugAsParams.split("/"), 82 | })) 83 | } 84 | 85 | export default async function GuidePage({ params }: GuidePageProps) { 86 | const guide = await getGuideFromParams(params) 87 | 88 | if (!guide) { 89 | notFound() 90 | } 91 | 92 | const toc = await getTableOfContents(guide.body.raw) 93 | 94 | return ( 95 |
96 |
97 | 98 | 99 |
100 |
101 | 105 | 106 | See all guides 107 | 108 |
109 |
110 |
111 |
112 | 113 |
114 |
115 |
116 | ) 117 | } 118 | -------------------------------------------------------------------------------- /app/(docs)/guides/layout.tsx: -------------------------------------------------------------------------------- 1 | interface GuidesLayoutProps { 2 | children: React.ReactNode 3 | } 4 | 5 | export default function GuidesLayout({ children }: GuidesLayoutProps) { 6 | return
{children}
7 | } 8 | -------------------------------------------------------------------------------- /app/(docs)/guides/page.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | import { allGuides } from "contentlayer/generated" 3 | import { compareDesc } from "date-fns" 4 | 5 | import { formatDate } from "@/lib/utils" 6 | import { DocsPageHeader } from "@/components/page-header" 7 | 8 | export const metadata = { 9 | title: "Guides", 10 | description: 11 | "This section includes end-to-end guides for developing Next.js 13 apps.", 12 | } 13 | 14 | export default function GuidesPage() { 15 | const guides = allGuides 16 | .filter((guide) => guide.published) 17 | .sort((a, b) => { 18 | return compareDesc(new Date(a.date), new Date(b.date)) 19 | }) 20 | 21 | return ( 22 |
23 | 27 | {guides?.length ? ( 28 |
29 | {guides.map((guide) => ( 30 |
34 | {guide.featured && ( 35 | 36 | Featured 37 | 38 | )} 39 |
40 |
41 |

42 | {guide.title} 43 |

44 | {guide.description && ( 45 |

{guide.description}

46 | )} 47 |
48 | {guide.date && ( 49 |

50 | {formatDate(guide.date)} 51 |

52 | )} 53 |
54 | 55 | View 56 | 57 |
58 | ))} 59 |
60 | ) : ( 61 |

No guides published.

62 | )} 63 |
64 | ) 65 | } 66 | -------------------------------------------------------------------------------- /app/(docs)/layout.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | import { docsConfig } from "@/config/docs" 4 | import { siteConfig } from "@/config/site" 5 | import { Icons } from "@/components/icons" 6 | import { MainNav } from "@/components/main-nav" 7 | import { DocsSearch } from "@/components/search" 8 | import { DocsSidebarNav } from "@/components/sidebar-nav" 9 | import { SiteFooter } from "@/components/site-footer" 10 | 11 | interface DocsLayoutProps { 12 | children: React.ReactNode 13 | } 14 | 15 | export default function DocsLayout({ children }: DocsLayoutProps) { 16 | return ( 17 |
18 |
19 |
20 | 21 | 22 | 23 |
24 |
25 | 26 |
27 | 37 |
38 |
39 |
40 |
{children}
41 | 42 |
43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /app/(editor)/editor/[postId]/loading.tsx: -------------------------------------------------------------------------------- 1 | import { Skeleton } from "@/components/ui/skeleton" 2 | 3 | export default function Loading() { 4 | return ( 5 |
6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 | 14 | 15 |
16 |
17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /app/(editor)/editor/[postId]/not-found.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | import { buttonVariants } from "@/components/ui/button" 4 | import { EmptyPlaceholder } from "@/components/empty-placeholder" 5 | 6 | export default function NotFound() { 7 | return ( 8 | 9 | 10 | Uh oh! Not Found 11 | 12 | This post cound not be found. Please try again. 13 | 14 | 15 | Go to Dashboard 16 | 17 | 18 | ) 19 | } 20 | -------------------------------------------------------------------------------- /app/(editor)/editor/[postId]/page.tsx: -------------------------------------------------------------------------------- 1 | import { notFound, redirect } from "next/navigation" 2 | import { Post, User } from "@prisma/client" 3 | 4 | import { authOptions } from "@/lib/auth" 5 | import { db } from "@/lib/db" 6 | import { getCurrentUser } from "@/lib/session" 7 | import { Editor } from "@/components/editor" 8 | 9 | async function getPostForUser(postId: Post["id"], userId: User["id"]) { 10 | return await db.post.findFirst({ 11 | where: { 12 | id: postId, 13 | authorId: userId, 14 | }, 15 | }) 16 | } 17 | 18 | interface EditorPageProps { 19 | params: { postId: string } 20 | } 21 | 22 | export default async function EditorPage({ params }: EditorPageProps) { 23 | const user = await getCurrentUser() 24 | 25 | if (!user) { 26 | redirect(authOptions?.pages?.signIn || "/login") 27 | } 28 | 29 | const post = await getPostForUser(params.postId, user.id) 30 | 31 | if (!post) { 32 | notFound() 33 | } 34 | 35 | return ( 36 | 44 | ) 45 | } 46 | -------------------------------------------------------------------------------- /app/(editor)/editor/layout.tsx: -------------------------------------------------------------------------------- 1 | interface EditorProps { 2 | children?: React.ReactNode 3 | } 4 | 5 | export default function EditorLayout({ children }: EditorProps) { 6 | return ( 7 |
8 | {children} 9 |
10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /app/(marketing)/[...slug]/page.tsx: -------------------------------------------------------------------------------- 1 | import { notFound } from "next/navigation" 2 | import { allPages } from "contentlayer/generated" 3 | 4 | import { Mdx } from "@/components/mdx-components" 5 | 6 | import "@/styles/mdx.css" 7 | import { Metadata } from "next" 8 | 9 | import { env } from "@/env.mjs" 10 | import { siteConfig } from "@/config/site" 11 | import { absoluteUrl } from "@/lib/utils" 12 | 13 | interface PageProps { 14 | params: { 15 | slug: string[] 16 | } 17 | } 18 | 19 | async function getPageFromParams(params) { 20 | const slug = params?.slug?.join("/") 21 | const page = allPages.find((page) => page.slugAsParams === slug) 22 | 23 | if (!page) { 24 | null 25 | } 26 | 27 | return page 28 | } 29 | 30 | export async function generateMetadata({ 31 | params, 32 | }: PageProps): Promise { 33 | const page = await getPageFromParams(params) 34 | 35 | if (!page) { 36 | return {} 37 | } 38 | 39 | const url = env.NEXT_PUBLIC_APP_URL 40 | 41 | const ogUrl = new URL(`${url}/api/og`) 42 | ogUrl.searchParams.set("heading", page.title) 43 | ogUrl.searchParams.set("type", siteConfig.name) 44 | ogUrl.searchParams.set("mode", "light") 45 | 46 | return { 47 | title: page.title, 48 | description: page.description, 49 | openGraph: { 50 | title: page.title, 51 | description: page.description, 52 | type: "article", 53 | url: absoluteUrl(page.slug), 54 | images: [ 55 | { 56 | url: ogUrl.toString(), 57 | width: 1200, 58 | height: 630, 59 | alt: page.title, 60 | }, 61 | ], 62 | }, 63 | twitter: { 64 | card: "summary_large_image", 65 | title: page.title, 66 | description: page.description, 67 | images: [ogUrl.toString()], 68 | }, 69 | } 70 | } 71 | 72 | export async function generateStaticParams(): Promise { 73 | return allPages.map((page) => ({ 74 | slug: page.slugAsParams.split("/"), 75 | })) 76 | } 77 | 78 | export default async function PagePage({ params }: PageProps) { 79 | const page = await getPageFromParams(params) 80 | 81 | if (!page) { 82 | notFound() 83 | } 84 | 85 | return ( 86 |
87 |
88 |

89 | {page.title} 90 |

91 | {page.description && ( 92 |

{page.description}

93 | )} 94 |
95 |
96 | 97 |
98 | ) 99 | } 100 | -------------------------------------------------------------------------------- /app/(marketing)/blog/page.tsx: -------------------------------------------------------------------------------- 1 | import Image from "next/image" 2 | import Link from "next/link" 3 | import { allPosts } from "contentlayer/generated" 4 | import { compareDesc } from "date-fns" 5 | 6 | import { formatDate } from "@/lib/utils" 7 | 8 | export const metadata = { 9 | title: "Blog", 10 | } 11 | 12 | export default async function BlogPage() { 13 | const posts = allPosts 14 | .filter((post) => post.published) 15 | .sort((a, b) => { 16 | return compareDesc(new Date(a.date), new Date(b.date)) 17 | }) 18 | 19 | return ( 20 |
21 |
22 |
23 |

24 | Blog 25 |

26 |

27 | A blog built using Contentlayer. Posts are written in MDX. 28 |

29 |
30 |
31 |
32 | {posts?.length ? ( 33 |
34 | {posts.map((post, index) => ( 35 |
39 | {post.image && ( 40 | {post.title} 48 | )} 49 |

{post.title}

50 | {post.description && ( 51 |

{post.description}

52 | )} 53 | {post.date && ( 54 |

55 | {formatDate(post.date)} 56 |

57 | )} 58 | 59 | View Article 60 | 61 |
62 | ))} 63 |
64 | ) : ( 65 |

No posts published.

66 | )} 67 |
68 | ) 69 | } 70 | -------------------------------------------------------------------------------- /app/(marketing)/layout.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | import { marketingConfig } from "@/config/marketing" 4 | import { cn } from "@/lib/utils" 5 | import { buttonVariants } from "@/components/ui/button" 6 | import { MainNav } from "@/components/main-nav" 7 | import { SiteFooter } from "@/components/site-footer" 8 | 9 | interface MarketingLayoutProps { 10 | children: React.ReactNode 11 | } 12 | 13 | export default async function MarketingLayout({ 14 | children, 15 | }: MarketingLayoutProps) { 16 | return ( 17 |
18 |
19 |
20 | 21 | 32 |
33 |
34 |
{children}
35 | 36 |
37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /app/(marketing)/pricing/page.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | import { cn } from "@/lib/utils" 4 | import { buttonVariants } from "@/components/ui/button" 5 | import { Icons } from "@/components/icons" 6 | 7 | export const metadata = { 8 | title: "Pricing", 9 | } 10 | 11 | export default function PricingPage() { 12 | return ( 13 |
14 |
15 |

16 | Simple, transparent pricing 17 |

18 |

19 | Unlock all features including unlimited posts for your blog. 20 |

21 |
22 |
23 |
24 |

25 | What's included in the PRO plan 26 |

27 |
    28 |
  • 29 | Unlimited Posts 30 |
  • 31 |
  • 32 | Unlimited Users 33 |
  • 34 | 35 |
  • 36 | Custom domain 37 |
  • 38 |
  • 39 | Dashboard Analytics 40 |
  • 41 |
  • 42 | Access to Discord 43 |
  • 44 |
  • 45 | Premium Support 46 |
  • 47 |
48 |
49 |
50 |
51 |

$19

52 |

53 | Billed Monthly 54 |

55 |
56 | 57 | Get Started 58 | 59 |
60 |
61 |
62 |

63 | Taxonomy is a demo app.{" "} 64 | You can test the upgrade and won't be charged. 65 |

66 |
67 |
68 | ) 69 | } 70 | -------------------------------------------------------------------------------- /app/api/auth/[...nextauth]/_route.ts: -------------------------------------------------------------------------------- 1 | import NextAuth from "next-auth" 2 | 3 | import { authOptions } from "@/lib/auth" 4 | 5 | const handler = NextAuth(authOptions) 6 | 7 | export { handler as GET, handler as POST } 8 | -------------------------------------------------------------------------------- /app/api/posts/[postId]/route.ts: -------------------------------------------------------------------------------- 1 | import { getServerSession } from "next-auth" 2 | import * as z from "zod" 3 | 4 | import { authOptions } from "@/lib/auth" 5 | import { db } from "@/lib/db" 6 | import { postPatchSchema } from "@/lib/validations/post" 7 | 8 | const routeContextSchema = z.object({ 9 | params: z.object({ 10 | postId: z.string(), 11 | }), 12 | }) 13 | 14 | export async function DELETE( 15 | req: Request, 16 | context: z.infer 17 | ) { 18 | try { 19 | // Validate the route params. 20 | const { params } = routeContextSchema.parse(context) 21 | 22 | // Check if the user has access to this post. 23 | if (!(await verifyCurrentUserHasAccessToPost(params.postId))) { 24 | return new Response(null, { status: 403 }) 25 | } 26 | 27 | // Delete the post. 28 | await db.post.delete({ 29 | where: { 30 | id: params.postId as string, 31 | }, 32 | }) 33 | 34 | return new Response(null, { status: 204 }) 35 | } catch (error) { 36 | if (error instanceof z.ZodError) { 37 | return new Response(JSON.stringify(error.issues), { status: 422 }) 38 | } 39 | 40 | return new Response(null, { status: 500 }) 41 | } 42 | } 43 | 44 | export async function PATCH( 45 | req: Request, 46 | context: z.infer 47 | ) { 48 | try { 49 | // Validate route params. 50 | const { params } = routeContextSchema.parse(context) 51 | 52 | // Check if the user has access to this post. 53 | if (!(await verifyCurrentUserHasAccessToPost(params.postId))) { 54 | return new Response(null, { status: 403 }) 55 | } 56 | 57 | // Get the request body and validate it. 58 | const json = await req.json() 59 | const body = postPatchSchema.parse(json) 60 | 61 | // Update the post. 62 | // TODO: Implement sanitization for content. 63 | await db.post.update({ 64 | where: { 65 | id: params.postId, 66 | }, 67 | data: { 68 | title: body.title, 69 | content: body.content, 70 | }, 71 | }) 72 | 73 | return new Response(null, { status: 200 }) 74 | } catch (error) { 75 | if (error instanceof z.ZodError) { 76 | return new Response(JSON.stringify(error.issues), { status: 422 }) 77 | } 78 | 79 | return new Response(null, { status: 500 }) 80 | } 81 | } 82 | 83 | async function verifyCurrentUserHasAccessToPost(postId: string) { 84 | const session = await getServerSession(authOptions) 85 | const count = await db.post.count({ 86 | where: { 87 | id: postId, 88 | authorId: session?.user.id, 89 | }, 90 | }) 91 | 92 | return count > 0 93 | } 94 | -------------------------------------------------------------------------------- /app/api/posts/route.ts: -------------------------------------------------------------------------------- 1 | import { getServerSession } from "next-auth/next" 2 | import * as z from "zod" 3 | 4 | import { authOptions } from "@/lib/auth" 5 | import { db } from "@/lib/db" 6 | import { RequiresProPlanError } from "@/lib/exceptions" 7 | import { getUserSubscriptionPlan } from "@/lib/subscription" 8 | 9 | const postCreateSchema = z.object({ 10 | title: z.string(), 11 | content: z.string().optional(), 12 | }) 13 | 14 | export async function GET() { 15 | try { 16 | const session = await getServerSession(authOptions) 17 | 18 | if (!session) { 19 | return new Response("Unauthorized", { status: 403 }) 20 | } 21 | 22 | const { user } = session 23 | const posts = await db.post.findMany({ 24 | select: { 25 | id: true, 26 | title: true, 27 | published: true, 28 | createdAt: true, 29 | }, 30 | where: { 31 | authorId: user.id, 32 | }, 33 | }) 34 | 35 | return new Response(JSON.stringify(posts)) 36 | } catch (error) { 37 | return new Response(null, { status: 500 }) 38 | } 39 | } 40 | 41 | export async function POST(req: Request) { 42 | try { 43 | const session = await getServerSession(authOptions) 44 | 45 | if (!session) { 46 | return new Response("Unauthorized", { status: 403 }) 47 | } 48 | 49 | const { user } = session 50 | const subscriptionPlan = await getUserSubscriptionPlan(user.id) 51 | 52 | // If user is on a free plan. 53 | // Check if user has reached limit of 3 posts. 54 | if (!subscriptionPlan?.isPro) { 55 | const count = await db.post.count({ 56 | where: { 57 | authorId: user.id, 58 | }, 59 | }) 60 | 61 | if (count >= 3) { 62 | throw new RequiresProPlanError() 63 | } 64 | } 65 | 66 | const json = await req.json() 67 | const body = postCreateSchema.parse(json) 68 | 69 | const post = await db.post.create({ 70 | data: { 71 | title: body.title, 72 | content: body.content, 73 | authorId: session.user.id, 74 | }, 75 | select: { 76 | id: true, 77 | }, 78 | }) 79 | 80 | return new Response(JSON.stringify(post)) 81 | } catch (error) { 82 | if (error instanceof z.ZodError) { 83 | return new Response(JSON.stringify(error.issues), { status: 422 }) 84 | } 85 | 86 | if (error instanceof RequiresProPlanError) { 87 | return new Response("Requires Pro Plan", { status: 402 }) 88 | } 89 | 90 | return new Response(null, { status: 500 }) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/api/users/[userId]/route.ts: -------------------------------------------------------------------------------- 1 | import { getServerSession } from "next-auth/next" 2 | import { z } from "zod" 3 | 4 | import { authOptions } from "@/lib/auth" 5 | import { db } from "@/lib/db" 6 | import { userNameSchema } from "@/lib/validations/user" 7 | 8 | const routeContextSchema = z.object({ 9 | params: z.object({ 10 | userId: z.string(), 11 | }), 12 | }) 13 | 14 | export async function PATCH( 15 | req: Request, 16 | context: z.infer 17 | ) { 18 | try { 19 | // Validate the route context. 20 | const { params } = routeContextSchema.parse(context) 21 | 22 | // Ensure user is authentication and has access to this user. 23 | const session = await getServerSession(authOptions) 24 | if (!session?.user || params.userId !== session?.user.id) { 25 | return new Response(null, { status: 403 }) 26 | } 27 | 28 | // Get the request body and validate it. 29 | const body = await req.json() 30 | const payload = userNameSchema.parse(body) 31 | 32 | // Update the user. 33 | await db.user.update({ 34 | where: { 35 | id: session.user.id, 36 | }, 37 | data: { 38 | name: payload.name, 39 | }, 40 | }) 41 | 42 | return new Response(null, { status: 200 }) 43 | } catch (error) { 44 | if (error instanceof z.ZodError) { 45 | return new Response(JSON.stringify(error.issues), { status: 422 }) 46 | } 47 | 48 | return new Response(null, { status: 500 }) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/api/users/stripe/route.ts: -------------------------------------------------------------------------------- 1 | import { getServerSession } from "next-auth/next" 2 | import { z } from "zod" 3 | 4 | import { proPlan } from "@/config/subscriptions" 5 | import { authOptions } from "@/lib/auth" 6 | import { stripe } from "@/lib/stripe" 7 | import { getUserSubscriptionPlan } from "@/lib/subscription" 8 | import { absoluteUrl } from "@/lib/utils" 9 | 10 | const billingUrl = absoluteUrl("/dashboard/billing") 11 | 12 | export async function GET(req: Request) { 13 | try { 14 | const session = await getServerSession(authOptions) 15 | 16 | if (!session?.user || !session?.user.email) { 17 | return new Response(null, { status: 403 }) 18 | } 19 | 20 | const subscriptionPlan = await getUserSubscriptionPlan(session.user.id) 21 | 22 | // The user is on the pro plan. 23 | // Create a portal session to manage subscription. 24 | if (subscriptionPlan.isPro && subscriptionPlan.stripeCustomerId) { 25 | const stripeSession = await stripe.billingPortal.sessions.create({ 26 | customer: subscriptionPlan.stripeCustomerId, 27 | return_url: billingUrl, 28 | }) 29 | 30 | return new Response(JSON.stringify({ url: stripeSession.url })) 31 | } 32 | 33 | // The user is on the free plan. 34 | // Create a checkout session to upgrade. 35 | const stripeSession = await stripe.checkout.sessions.create({ 36 | success_url: billingUrl, 37 | cancel_url: billingUrl, 38 | payment_method_types: ["card"], 39 | mode: "subscription", 40 | billing_address_collection: "auto", 41 | customer_email: session.user.email, 42 | line_items: [ 43 | { 44 | price: proPlan.stripePriceId, 45 | quantity: 1, 46 | }, 47 | ], 48 | metadata: { 49 | userId: session.user.id, 50 | }, 51 | }) 52 | 53 | return new Response(JSON.stringify({ url: stripeSession.url })) 54 | } catch (error) { 55 | if (error instanceof z.ZodError) { 56 | return new Response(JSON.stringify(error.issues), { status: 422 }) 57 | } 58 | 59 | return new Response(null, { status: 500 }) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/api/webhooks/stripe/route.ts: -------------------------------------------------------------------------------- 1 | import { headers } from "next/headers" 2 | import Stripe from "stripe" 3 | 4 | import { env } from "@/env.mjs" 5 | import { db } from "@/lib/db" 6 | import { stripe } from "@/lib/stripe" 7 | 8 | export async function POST(req: Request) { 9 | const body = await req.text() 10 | const signature = headers().get("Stripe-Signature") as string 11 | 12 | let event: Stripe.Event 13 | 14 | try { 15 | event = stripe.webhooks.constructEvent( 16 | body, 17 | signature, 18 | env.STRIPE_WEBHOOK_SECRET 19 | ) 20 | } catch (error) { 21 | return new Response(`Webhook Error: ${error.message}`, { status: 400 }) 22 | } 23 | 24 | const session = event.data.object as Stripe.Checkout.Session 25 | 26 | if (event.type === "checkout.session.completed") { 27 | // Retrieve the subscription details from Stripe. 28 | const subscription = await stripe.subscriptions.retrieve( 29 | session.subscription as string 30 | ) 31 | 32 | // Update the user stripe into in our database. 33 | // Since this is the initial subscription, we need to update 34 | // the subscription id and customer id. 35 | await db.user.update({ 36 | where: { 37 | id: session?.metadata?.userId, 38 | }, 39 | data: { 40 | stripeSubscriptionId: subscription.id, 41 | stripeCustomerId: subscription.customer as string, 42 | stripePriceId: subscription.items.data[0].price.id, 43 | stripeCurrentPeriodEnd: new Date( 44 | subscription.current_period_end * 1000 45 | ), 46 | }, 47 | }) 48 | } 49 | 50 | if (event.type === "invoice.payment_succeeded") { 51 | // Retrieve the subscription details from Stripe. 52 | const subscription = await stripe.subscriptions.retrieve( 53 | session.subscription as string 54 | ) 55 | 56 | // Update the price id and set the new period end. 57 | await db.user.update({ 58 | where: { 59 | stripeSubscriptionId: subscription.id, 60 | }, 61 | data: { 62 | stripePriceId: subscription.items.data[0].price.id, 63 | stripeCurrentPeriodEnd: new Date( 64 | subscription.current_period_end * 1000 65 | ), 66 | }, 67 | }) 68 | } 69 | 70 | return new Response(null, { status: 200 }) 71 | } 72 | -------------------------------------------------------------------------------- /app/layout.tsx: -------------------------------------------------------------------------------- 1 | import { Inter as FontSans } from "next/font/google" 2 | import localFont from "next/font/local" 3 | 4 | import "@/styles/globals.css" 5 | import { siteConfig } from "@/config/site" 6 | import { absoluteUrl, cn } from "@/lib/utils" 7 | import { Toaster } from "@/components/ui/toaster" 8 | import { Analytics } from "@/components/analytics" 9 | import { TailwindIndicator } from "@/components/tailwind-indicator" 10 | import { ThemeProvider } from "@/components/theme-provider" 11 | 12 | const fontSans = FontSans({ 13 | subsets: ["latin"], 14 | variable: "--font-sans", 15 | }) 16 | 17 | // Font files can be colocated inside of `pages` 18 | const fontHeading = localFont({ 19 | src: "../assets/fonts/CalSans-SemiBold.woff2", 20 | variable: "--font-heading", 21 | }) 22 | 23 | interface RootLayoutProps { 24 | children: React.ReactNode 25 | } 26 | 27 | export const metadata = { 28 | title: { 29 | default: siteConfig.name, 30 | template: `%s | ${siteConfig.name}`, 31 | }, 32 | description: siteConfig.description, 33 | keywords: [ 34 | "Next.js", 35 | "React", 36 | "Tailwind CSS", 37 | "Server Components", 38 | "Radix UI", 39 | ], 40 | authors: [ 41 | { 42 | name: "shadcn", 43 | url: "https://shadcn.com", 44 | }, 45 | ], 46 | creator: "shadcn", 47 | themeColor: [ 48 | { media: "(prefers-color-scheme: light)", color: "white" }, 49 | { media: "(prefers-color-scheme: dark)", color: "black" }, 50 | ], 51 | openGraph: { 52 | type: "website", 53 | locale: "en_US", 54 | url: siteConfig.url, 55 | title: siteConfig.name, 56 | description: siteConfig.description, 57 | siteName: siteConfig.name, 58 | }, 59 | twitter: { 60 | card: "summary_large_image", 61 | title: siteConfig.name, 62 | description: siteConfig.description, 63 | images: [`${siteConfig.url}/og.jpg`], 64 | creator: "@shadcn", 65 | }, 66 | icons: { 67 | icon: "/favicon.ico", 68 | shortcut: "/favicon-16x16.png", 69 | apple: "/apple-touch-icon.png", 70 | }, 71 | manifest: `${siteConfig.url}/site.webmanifest`, 72 | } 73 | 74 | export default function RootLayout({ children }: RootLayoutProps) { 75 | return ( 76 | 77 | 78 | 85 | 86 | {children} 87 | 88 | 89 | 90 | 91 | 92 | 93 | ) 94 | } 95 | -------------------------------------------------------------------------------- /app/opengraph-image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadcn-ui/taxonomy/651f984e52edd65d40ccd55e299c1baeea3ff017/app/opengraph-image.jpg -------------------------------------------------------------------------------- /app/robots.ts: -------------------------------------------------------------------------------- 1 | import { MetadataRoute } from "next" 2 | 3 | export default function robots(): MetadataRoute.Robots { 4 | return { 5 | rules: { 6 | userAgent: "*", 7 | allow: "/", 8 | }, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /assets/fonts/CalSans-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadcn-ui/taxonomy/651f984e52edd65d40ccd55e299c1baeea3ff017/assets/fonts/CalSans-SemiBold.ttf -------------------------------------------------------------------------------- /assets/fonts/CalSans-SemiBold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadcn-ui/taxonomy/651f984e52edd65d40ccd55e299c1baeea3ff017/assets/fonts/CalSans-SemiBold.woff -------------------------------------------------------------------------------- /assets/fonts/CalSans-SemiBold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadcn-ui/taxonomy/651f984e52edd65d40ccd55e299c1baeea3ff017/assets/fonts/CalSans-SemiBold.woff2 -------------------------------------------------------------------------------- /assets/fonts/Inter-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadcn-ui/taxonomy/651f984e52edd65d40ccd55e299c1baeea3ff017/assets/fonts/Inter-Bold.ttf -------------------------------------------------------------------------------- /assets/fonts/Inter-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadcn-ui/taxonomy/651f984e52edd65d40ccd55e299c1baeea3ff017/assets/fonts/Inter-Regular.ttf -------------------------------------------------------------------------------- /components/analytics.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { Analytics as VercelAnalytics } from "@vercel/analytics/react" 4 | 5 | export function Analytics() { 6 | return 7 | } 8 | -------------------------------------------------------------------------------- /components/billing-form.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | 5 | import { UserSubscriptionPlan } from "types" 6 | import { cn, formatDate } from "@/lib/utils" 7 | import { buttonVariants } from "@/components/ui/button" 8 | import { 9 | Card, 10 | CardContent, 11 | CardDescription, 12 | CardFooter, 13 | CardHeader, 14 | CardTitle, 15 | } from "@/components/ui/card" 16 | import { toast } from "@/components/ui/use-toast" 17 | import { Icons } from "@/components/icons" 18 | 19 | interface BillingFormProps extends React.HTMLAttributes { 20 | subscriptionPlan: UserSubscriptionPlan & { 21 | isCanceled: boolean 22 | } 23 | } 24 | 25 | export function BillingForm({ 26 | subscriptionPlan, 27 | className, 28 | ...props 29 | }: BillingFormProps) { 30 | const [isLoading, setIsLoading] = React.useState(false) 31 | 32 | async function onSubmit(event) { 33 | event.preventDefault() 34 | setIsLoading(!isLoading) 35 | 36 | // Get a Stripe session URL. 37 | const response = await fetch("/api/users/stripe") 38 | 39 | if (!response?.ok) { 40 | return toast({ 41 | title: "Something went wrong.", 42 | description: "Please refresh the page and try again.", 43 | variant: "destructive", 44 | }) 45 | } 46 | 47 | // Redirect to the Stripe session. 48 | // This could be a checkout page for initial upgrade. 49 | // Or portal to manage existing subscription. 50 | const session = await response.json() 51 | if (session) { 52 | window.location.href = session.url 53 | } 54 | } 55 | 56 | return ( 57 |
58 | 59 | 60 | Subscription Plan 61 | 62 | You are currently on the {subscriptionPlan.name}{" "} 63 | plan. 64 | 65 | 66 | {subscriptionPlan.description} 67 | 68 | 78 | {subscriptionPlan.isPro ? ( 79 |

80 | {subscriptionPlan.isCanceled 81 | ? "Your plan will be canceled on " 82 | : "Your plan renews on "} 83 | {formatDate(subscriptionPlan.stripeCurrentPeriodEnd)}. 84 |

85 | ) : null} 86 |
87 |
88 |
89 | ) 90 | } 91 | -------------------------------------------------------------------------------- /components/callout.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils" 2 | 3 | interface CalloutProps { 4 | icon?: string 5 | children?: React.ReactNode 6 | type?: "default" | "warning" | "danger" 7 | } 8 | 9 | export function Callout({ 10 | children, 11 | icon, 12 | type = "default", 13 | ...props 14 | }: CalloutProps) { 15 | return ( 16 |
23 | {icon && {icon}} 24 |
{children}
25 |
26 | ) 27 | } 28 | -------------------------------------------------------------------------------- /components/card-skeleton.tsx: -------------------------------------------------------------------------------- 1 | import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card" 2 | import { Skeleton } from "@/components/ui/skeleton" 3 | 4 | export function CardSkeleton() { 5 | return ( 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /components/empty-placeholder.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | import { Icons } from "@/components/icons" 5 | 6 | interface EmptyPlaceholderProps extends React.HTMLAttributes {} 7 | 8 | export function EmptyPlaceholder({ 9 | className, 10 | children, 11 | ...props 12 | }: EmptyPlaceholderProps) { 13 | return ( 14 |
21 |
22 | {children} 23 |
24 |
25 | ) 26 | } 27 | 28 | interface EmptyPlaceholderIconProps 29 | extends Partial> { 30 | name: keyof typeof Icons 31 | } 32 | 33 | EmptyPlaceholder.Icon = function EmptyPlaceHolderIcon({ 34 | name, 35 | className, 36 | ...props 37 | }: EmptyPlaceholderIconProps) { 38 | const Icon = Icons[name] 39 | 40 | if (!Icon) { 41 | return null 42 | } 43 | 44 | return ( 45 |
46 | 47 |
48 | ) 49 | } 50 | 51 | interface EmptyPlacholderTitleProps 52 | extends React.HTMLAttributes {} 53 | 54 | EmptyPlaceholder.Title = function EmptyPlaceholderTitle({ 55 | className, 56 | ...props 57 | }: EmptyPlacholderTitleProps) { 58 | return ( 59 |

60 | ) 61 | } 62 | 63 | interface EmptyPlacholderDescriptionProps 64 | extends React.HTMLAttributes {} 65 | 66 | EmptyPlaceholder.Description = function EmptyPlaceholderDescription({ 67 | className, 68 | ...props 69 | }: EmptyPlacholderDescriptionProps) { 70 | return ( 71 |

78 | ) 79 | } 80 | -------------------------------------------------------------------------------- /components/header.tsx: -------------------------------------------------------------------------------- 1 | interface DashboardHeaderProps { 2 | heading: string 3 | text?: string 4 | children?: React.ReactNode 5 | } 6 | 7 | export function DashboardHeader({ 8 | heading, 9 | text, 10 | children, 11 | }: DashboardHeaderProps) { 12 | return ( 13 |

14 |
15 |

{heading}

16 | {text &&

{text}

} 17 |
18 | {children} 19 |
20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /components/icons.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | AlertTriangle, 3 | ArrowRight, 4 | Check, 5 | ChevronLeft, 6 | ChevronRight, 7 | Command, 8 | CreditCard, 9 | File, 10 | FileText, 11 | HelpCircle, 12 | Image, 13 | Laptop, 14 | Loader2, 15 | LucideProps, 16 | Moon, 17 | MoreVertical, 18 | Pizza, 19 | Plus, 20 | Settings, 21 | SunMedium, 22 | Trash, 23 | Twitter, 24 | User, 25 | X, 26 | type Icon as LucideIcon, 27 | } from "lucide-react" 28 | 29 | export type Icon = LucideIcon 30 | 31 | export const Icons = { 32 | logo: Command, 33 | close: X, 34 | spinner: Loader2, 35 | chevronLeft: ChevronLeft, 36 | chevronRight: ChevronRight, 37 | trash: Trash, 38 | post: FileText, 39 | page: File, 40 | media: Image, 41 | settings: Settings, 42 | billing: CreditCard, 43 | ellipsis: MoreVertical, 44 | add: Plus, 45 | warning: AlertTriangle, 46 | user: User, 47 | arrowRight: ArrowRight, 48 | help: HelpCircle, 49 | pizza: Pizza, 50 | sun: SunMedium, 51 | moon: Moon, 52 | laptop: Laptop, 53 | gitHub: ({ ...props }: LucideProps) => ( 54 | 69 | ), 70 | twitter: Twitter, 71 | check: Check, 72 | } 73 | -------------------------------------------------------------------------------- /components/main-nav.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import Link from "next/link" 5 | import { useSelectedLayoutSegment } from "next/navigation" 6 | 7 | import { MainNavItem } from "types" 8 | import { siteConfig } from "@/config/site" 9 | import { cn } from "@/lib/utils" 10 | import { Icons } from "@/components/icons" 11 | import { MobileNav } from "@/components/mobile-nav" 12 | 13 | interface MainNavProps { 14 | items?: MainNavItem[] 15 | children?: React.ReactNode 16 | } 17 | 18 | export function MainNav({ items, children }: MainNavProps) { 19 | const segment = useSelectedLayoutSegment() 20 | const [showMobileMenu, setShowMobileMenu] = React.useState(false) 21 | 22 | return ( 23 |
24 | 25 | 26 | 27 | {siteConfig.name} 28 | 29 | 30 | {items?.length ? ( 31 | 48 | ) : null} 49 | 56 | {showMobileMenu && items && ( 57 | {children} 58 | )} 59 |
60 | ) 61 | } 62 | -------------------------------------------------------------------------------- /components/mdx-card.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | interface CardProps extends React.HTMLAttributes { 6 | href?: string 7 | disabled?: boolean 8 | } 9 | 10 | export function MdxCard({ 11 | href, 12 | className, 13 | children, 14 | disabled, 15 | ...props 16 | }: CardProps) { 17 | return ( 18 |
26 |
27 |
28 | {children} 29 |
30 |
31 | {href && ( 32 | 33 | View 34 | 35 | )} 36 |
37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /components/mobile-nav.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import Link from "next/link" 3 | 4 | import { MainNavItem } from "types" 5 | import { siteConfig } from "@/config/site" 6 | import { cn } from "@/lib/utils" 7 | import { useLockBody } from "@/hooks/use-lock-body" 8 | import { Icons } from "@/components/icons" 9 | 10 | interface MobileNavProps { 11 | items: MainNavItem[] 12 | children?: React.ReactNode 13 | } 14 | 15 | export function MobileNav({ items, children }: MobileNavProps) { 16 | useLockBody() 17 | 18 | return ( 19 |
24 |
25 | 26 | 27 | {siteConfig.name} 28 | 29 | 43 | {children} 44 |
45 |
46 | ) 47 | } 48 | -------------------------------------------------------------------------------- /components/mode-toggle.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import { useTheme } from "next-themes" 5 | 6 | import { Button } from "@/components/ui/button" 7 | import { 8 | DropdownMenu, 9 | DropdownMenuContent, 10 | DropdownMenuItem, 11 | DropdownMenuTrigger, 12 | } from "@/components/ui/dropdown-menu" 13 | import { Icons } from "@/components/icons" 14 | 15 | export function ModeToggle() { 16 | const { setTheme } = useTheme() 17 | 18 | return ( 19 | 20 | 21 | 26 | 27 | 28 | setTheme("light")}> 29 | 30 | Light 31 | 32 | setTheme("dark")}> 33 | 34 | Dark 35 | 36 | setTheme("system")}> 37 | 38 | System 39 | 40 | 41 | 42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /components/nav.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import Link from "next/link" 4 | import { usePathname } from "next/navigation" 5 | 6 | import { SidebarNavItem } from "types" 7 | import { cn } from "@/lib/utils" 8 | import { Icons } from "@/components/icons" 9 | 10 | interface DashboardNavProps { 11 | items: SidebarNavItem[] 12 | } 13 | 14 | export function DashboardNav({ items }: DashboardNavProps) { 15 | const path = usePathname() 16 | 17 | if (!items?.length) { 18 | return null 19 | } 20 | 21 | return ( 22 | 43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /components/page-header.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils" 2 | 3 | interface DocsPageHeaderProps extends React.HTMLAttributes { 4 | heading: string 5 | text?: string 6 | } 7 | 8 | export function DocsPageHeader({ 9 | heading, 10 | text, 11 | className, 12 | ...props 13 | }: DocsPageHeaderProps) { 14 | return ( 15 | <> 16 |
17 |

18 | {heading} 19 |

20 | {text &&

{text}

} 21 |
22 |
23 | 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /components/pager.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | import { Doc } from "contentlayer/generated" 3 | 4 | import { docsConfig } from "@/config/docs" 5 | import { cn } from "@/lib/utils" 6 | import { buttonVariants } from "@/components/ui/button" 7 | import { Icons } from "@/components/icons" 8 | 9 | interface DocsPagerProps { 10 | doc: Doc 11 | } 12 | 13 | export function DocsPager({ doc }: DocsPagerProps) { 14 | const pager = getPagerForDoc(doc) 15 | 16 | if (!pager) { 17 | return null 18 | } 19 | 20 | return ( 21 |
22 | {pager?.prev && ( 23 | 27 | 28 | {pager.prev.title} 29 | 30 | )} 31 | {pager?.next && ( 32 | 36 | {pager.next.title} 37 | 38 | 39 | )} 40 |
41 | ) 42 | } 43 | 44 | export function getPagerForDoc(doc: Doc) { 45 | const flattenedLinks = [null, ...flatten(docsConfig.sidebarNav), null] 46 | const activeIndex = flattenedLinks.findIndex( 47 | (link) => doc.slug === link?.href 48 | ) 49 | const prev = activeIndex !== 0 ? flattenedLinks[activeIndex - 1] : null 50 | const next = 51 | activeIndex !== flattenedLinks.length - 1 52 | ? flattenedLinks[activeIndex + 1] 53 | : null 54 | return { 55 | prev, 56 | next, 57 | } 58 | } 59 | 60 | export function flatten(links: { items? }[]) { 61 | return links.reduce((flat, link) => { 62 | return flat.concat(link.items ? flatten(link.items) : link) 63 | }, []) 64 | } 65 | -------------------------------------------------------------------------------- /components/post-create-button.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import { useRouter } from "next/navigation" 5 | 6 | import { cn } from "@/lib/utils" 7 | import { ButtonProps, buttonVariants } from "@/components/ui/button" 8 | import { toast } from "@/components/ui/use-toast" 9 | import { Icons } from "@/components/icons" 10 | 11 | interface PostCreateButtonProps extends ButtonProps {} 12 | 13 | export function PostCreateButton({ 14 | className, 15 | variant, 16 | ...props 17 | }: PostCreateButtonProps) { 18 | const router = useRouter() 19 | const [isLoading, setIsLoading] = React.useState(false) 20 | 21 | async function onClick() { 22 | setIsLoading(true) 23 | 24 | const response = await fetch("/api/posts", { 25 | method: "POST", 26 | headers: { 27 | "Content-Type": "application/json", 28 | }, 29 | body: JSON.stringify({ 30 | title: "Untitled Post", 31 | }), 32 | }) 33 | 34 | setIsLoading(false) 35 | 36 | if (!response?.ok) { 37 | if (response.status === 402) { 38 | return toast({ 39 | title: "Limit of 3 posts reached.", 40 | description: "Please upgrade to the PRO plan.", 41 | variant: "destructive", 42 | }) 43 | } 44 | 45 | return toast({ 46 | title: "Something went wrong.", 47 | description: "Your post was not created. Please try again.", 48 | variant: "destructive", 49 | }) 50 | } 51 | 52 | const post = await response.json() 53 | 54 | // This forces a cache invalidation. 55 | router.refresh() 56 | 57 | router.push(`/editor/${post.id}`) 58 | } 59 | 60 | return ( 61 | 80 | ) 81 | } 82 | -------------------------------------------------------------------------------- /components/post-item.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | import { Post } from "@prisma/client" 3 | 4 | import { formatDate } from "@/lib/utils" 5 | import { Skeleton } from "@/components/ui/skeleton" 6 | import { PostOperations } from "@/components/post-operations" 7 | 8 | interface PostItemProps { 9 | post: Pick 10 | } 11 | 12 | export function PostItem({ post }: PostItemProps) { 13 | return ( 14 |
15 |
16 | 20 | {post.title} 21 | 22 |
23 |

24 | {formatDate(post.createdAt?.toDateString())} 25 |

26 |
27 |
28 | 29 |
30 | ) 31 | } 32 | 33 | PostItem.Skeleton = function PostItemSkeleton() { 34 | return ( 35 |
36 |
37 | 38 | 39 |
40 |
41 | ) 42 | } 43 | -------------------------------------------------------------------------------- /components/post-operations.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import Link from "next/link" 5 | import { useRouter } from "next/navigation" 6 | import { Post } from "@prisma/client" 7 | 8 | import { 9 | AlertDialog, 10 | AlertDialogAction, 11 | AlertDialogCancel, 12 | AlertDialogContent, 13 | AlertDialogDescription, 14 | AlertDialogFooter, 15 | AlertDialogHeader, 16 | AlertDialogTitle, 17 | } from "@/components/ui/alert-dialog" 18 | import { 19 | DropdownMenu, 20 | DropdownMenuContent, 21 | DropdownMenuItem, 22 | DropdownMenuSeparator, 23 | DropdownMenuTrigger, 24 | } from "@/components/ui/dropdown-menu" 25 | import { toast } from "@/components/ui/use-toast" 26 | import { Icons } from "@/components/icons" 27 | 28 | async function deletePost(postId: string) { 29 | const response = await fetch(`/api/posts/${postId}`, { 30 | method: "DELETE", 31 | }) 32 | 33 | if (!response?.ok) { 34 | toast({ 35 | title: "Something went wrong.", 36 | description: "Your post was not deleted. Please try again.", 37 | variant: "destructive", 38 | }) 39 | } 40 | 41 | return true 42 | } 43 | 44 | interface PostOperationsProps { 45 | post: Pick 46 | } 47 | 48 | export function PostOperations({ post }: PostOperationsProps) { 49 | const router = useRouter() 50 | const [showDeleteAlert, setShowDeleteAlert] = React.useState(false) 51 | const [isDeleteLoading, setIsDeleteLoading] = React.useState(false) 52 | 53 | return ( 54 | <> 55 | 56 | 57 | 58 | Open 59 | 60 | 61 | 62 | 63 | Edit 64 | 65 | 66 | 67 | setShowDeleteAlert(true)} 70 | > 71 | Delete 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Are you sure you want to delete this post? 80 | 81 | 82 | This action cannot be undone. 83 | 84 | 85 | 86 | Cancel 87 | { 89 | event.preventDefault() 90 | setIsDeleteLoading(true) 91 | 92 | const deleted = await deletePost(post.id) 93 | 94 | if (deleted) { 95 | setIsDeleteLoading(false) 96 | setShowDeleteAlert(false) 97 | router.refresh() 98 | } 99 | }} 100 | className="bg-red-600 focus:ring-red-600" 101 | > 102 | {isDeleteLoading ? ( 103 | 104 | ) : ( 105 | 106 | )} 107 | Delete 108 | 109 | 110 | 111 | 112 | 113 | ) 114 | } 115 | -------------------------------------------------------------------------------- /components/search.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | 5 | import { cn } from "@/lib/utils" 6 | import { Input } from "@/components/ui/input" 7 | import { toast } from "@/components/ui/use-toast" 8 | 9 | interface DocsSearchProps extends React.HTMLAttributes {} 10 | 11 | export function DocsSearch({ className, ...props }: DocsSearchProps) { 12 | function onSubmit(event: React.SyntheticEvent) { 13 | event.preventDefault() 14 | 15 | return toast({ 16 | title: "Not implemented", 17 | description: "We're still working on the search.", 18 | }) 19 | } 20 | 21 | return ( 22 |
27 | 32 | 33 | K 34 | 35 |
36 | ) 37 | } 38 | -------------------------------------------------------------------------------- /components/shell.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | interface DashboardShellProps extends React.HTMLAttributes {} 6 | 7 | export function DashboardShell({ 8 | children, 9 | className, 10 | ...props 11 | }: DashboardShellProps) { 12 | return ( 13 |
14 | {children} 15 |
16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /components/sidebar-nav.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import Link from "next/link" 4 | import { usePathname } from "next/navigation" 5 | 6 | import { SidebarNavItem } from "types" 7 | import { cn } from "@/lib/utils" 8 | 9 | export interface DocsSidebarNavProps { 10 | items: SidebarNavItem[] 11 | } 12 | 13 | export function DocsSidebarNav({ items }: DocsSidebarNavProps) { 14 | const pathname = usePathname() 15 | 16 | return items.length ? ( 17 |
18 | {items.map((item, index) => ( 19 |
20 |

21 | {item.title} 22 |

23 | {item.items ? ( 24 | 25 | ) : null} 26 |
27 | ))} 28 |
29 | ) : null 30 | } 31 | 32 | interface DocsSidebarNavItemsProps { 33 | items: SidebarNavItem[] 34 | pathname: string | null 35 | } 36 | 37 | export function DocsSidebarNavItems({ 38 | items, 39 | pathname, 40 | }: DocsSidebarNavItemsProps) { 41 | return items?.length ? ( 42 |
43 | {items.map((item, index) => 44 | !item.disabled && item.href ? ( 45 | 57 | {item.title} 58 | 59 | ) : ( 60 | 61 | {item.title} 62 | 63 | ) 64 | )} 65 |
66 | ) : null 67 | } 68 | -------------------------------------------------------------------------------- /components/site-footer.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { siteConfig } from "@/config/site" 4 | import { cn } from "@/lib/utils" 5 | import { Icons } from "@/components/icons" 6 | import { ModeToggle } from "@/components/mode-toggle" 7 | 8 | export function SiteFooter({ className }: React.HTMLAttributes) { 9 | return ( 10 | 57 | ) 58 | } 59 | -------------------------------------------------------------------------------- /components/tailwind-indicator.tsx: -------------------------------------------------------------------------------- 1 | export function TailwindIndicator() { 2 | if (process.env.NODE_ENV === "production") return null 3 | 4 | return ( 5 |
6 |
xs
7 |
8 | sm 9 |
10 |
md
11 |
lg
12 |
xl
13 |
2xl
14 |
15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /components/theme-provider.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import { ThemeProvider as NextThemesProvider } from "next-themes" 5 | import { ThemeProviderProps } from "next-themes/dist/types" 6 | 7 | export function ThemeProvider({ children, ...props }: ThemeProviderProps) { 8 | return {children} 9 | } 10 | -------------------------------------------------------------------------------- /components/toc.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | 5 | import { TableOfContents } from "@/lib/toc" 6 | import { cn } from "@/lib/utils" 7 | import { useMounted } from "@/hooks/use-mounted" 8 | 9 | interface TocProps { 10 | toc: TableOfContents 11 | } 12 | 13 | export function DashboardTableOfContents({ toc }: TocProps) { 14 | const itemIds = React.useMemo( 15 | () => 16 | toc.items 17 | ? toc.items 18 | .flatMap((item) => [item.url, item?.items?.map((item) => item.url)]) 19 | .flat() 20 | .filter(Boolean) 21 | .map((id) => id?.split("#")[1]) 22 | : [], 23 | [toc] 24 | ) 25 | const activeHeading = useActiveItem(itemIds) 26 | const mounted = useMounted() 27 | 28 | if (!toc?.items) { 29 | return null 30 | } 31 | 32 | return mounted ? ( 33 |
34 |

On This Page

35 | 36 |
37 | ) : null 38 | } 39 | 40 | function useActiveItem(itemIds: (string | undefined)[]) { 41 | const [activeId, setActiveId] = React.useState("") 42 | 43 | React.useEffect(() => { 44 | const observer = new IntersectionObserver( 45 | (entries) => { 46 | entries.forEach((entry) => { 47 | if (entry.isIntersecting) { 48 | setActiveId(entry.target.id) 49 | } 50 | }) 51 | }, 52 | { rootMargin: `0% 0% -80% 0%` } 53 | ) 54 | 55 | itemIds?.forEach((id) => { 56 | if (!id) { 57 | return 58 | } 59 | 60 | const element = document.getElementById(id) 61 | if (element) { 62 | observer.observe(element) 63 | } 64 | }) 65 | 66 | return () => { 67 | itemIds?.forEach((id) => { 68 | if (!id) { 69 | return 70 | } 71 | 72 | const element = document.getElementById(id) 73 | if (element) { 74 | observer.unobserve(element) 75 | } 76 | }) 77 | } 78 | }, [itemIds]) 79 | 80 | return activeId 81 | } 82 | 83 | interface TreeProps { 84 | tree: TableOfContents 85 | level?: number 86 | activeItem?: string | null 87 | } 88 | 89 | function Tree({ tree, level = 1, activeItem }: TreeProps) { 90 | return tree?.items?.length && level < 3 ? ( 91 |
    92 | {tree.items.map((item, index) => { 93 | return ( 94 |
  • 95 | 104 | {item.title} 105 | 106 | {item.items?.length ? ( 107 | 108 | ) : null} 109 |
  • 110 | ) 111 | })} 112 |
113 | ) : null 114 | } 115 | -------------------------------------------------------------------------------- /components/ui/accordion.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AccordionPrimitive from "@radix-ui/react-accordion" 5 | import { ChevronDown } from "lucide-react" 6 | 7 | import { cn } from "@/lib/utils" 8 | 9 | const Accordion = AccordionPrimitive.Root 10 | 11 | const AccordionItem = React.forwardRef< 12 | React.ElementRef, 13 | React.ComponentPropsWithoutRef 14 | >(({ className, ...props }, ref) => ( 15 | 20 | )) 21 | AccordionItem.displayName = "AccordionItem" 22 | 23 | const AccordionTrigger = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, children, ...props }, ref) => ( 27 | 28 | svg]:rotate-180", 32 | className 33 | )} 34 | {...props} 35 | > 36 | {children} 37 | 38 | 39 | 40 | )) 41 | AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName 42 | 43 | const AccordionContent = React.forwardRef< 44 | React.ElementRef, 45 | React.ComponentPropsWithoutRef 46 | >(({ className, children, ...props }, ref) => ( 47 | 55 |
{children}
56 |
57 | )) 58 | AccordionContent.displayName = AccordionPrimitive.Content.displayName 59 | 60 | export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } 61 | -------------------------------------------------------------------------------- /components/ui/alert.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { VariantProps, cva } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const alertVariants = cva( 7 | "relative w-full rounded-lg border p-4 [&>svg]:absolute [&>svg]:text-foreground [&>svg]:left-4 [&>svg]:top-4 [&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11", 8 | { 9 | variants: { 10 | variant: { 11 | default: "bg-background text-foreground", 12 | destructive: 13 | "text-destructive border-destructive/50 dark:border-destructive [&>svg]:text-destructive text-destructive", 14 | }, 15 | }, 16 | defaultVariants: { 17 | variant: "default", 18 | }, 19 | } 20 | ) 21 | 22 | const Alert = React.forwardRef< 23 | HTMLDivElement, 24 | React.HTMLAttributes & VariantProps 25 | >(({ className, variant, ...props }, ref) => ( 26 |
32 | )) 33 | Alert.displayName = "Alert" 34 | 35 | const AlertTitle = React.forwardRef< 36 | HTMLParagraphElement, 37 | React.HTMLAttributes 38 | >(({ className, ...props }, ref) => ( 39 |
44 | )) 45 | AlertTitle.displayName = "AlertTitle" 46 | 47 | const AlertDescription = React.forwardRef< 48 | HTMLParagraphElement, 49 | React.HTMLAttributes 50 | >(({ className, ...props }, ref) => ( 51 |
56 | )) 57 | AlertDescription.displayName = "AlertDescription" 58 | 59 | export { Alert, AlertTitle, AlertDescription } 60 | -------------------------------------------------------------------------------- /components/ui/aspect-ratio.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio" 4 | 5 | const AspectRatio = AspectRatioPrimitive.Root 6 | 7 | export { AspectRatio } 8 | -------------------------------------------------------------------------------- /components/ui/avatar.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AvatarPrimitive from "@radix-ui/react-avatar" 5 | 6 | import { cn } from "@/lib/utils" 7 | 8 | const Avatar = React.forwardRef< 9 | React.ElementRef, 10 | React.ComponentPropsWithoutRef 11 | >(({ className, ...props }, ref) => ( 12 | 20 | )) 21 | Avatar.displayName = AvatarPrimitive.Root.displayName 22 | 23 | const AvatarImage = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, ...props }, ref) => ( 27 | 32 | )) 33 | AvatarImage.displayName = AvatarPrimitive.Image.displayName 34 | 35 | const AvatarFallback = React.forwardRef< 36 | React.ElementRef, 37 | React.ComponentPropsWithoutRef 38 | >(({ className, ...props }, ref) => ( 39 | 47 | )) 48 | AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName 49 | 50 | export { Avatar, AvatarImage, AvatarFallback } 51 | -------------------------------------------------------------------------------- /components/ui/badge.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { VariantProps, cva } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const badgeVariants = cva( 7 | "inline-flex items-center border rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", 8 | { 9 | variants: { 10 | variant: { 11 | default: 12 | "bg-primary hover:bg-primary/80 border-transparent text-primary-foreground", 13 | secondary: 14 | "bg-secondary hover:bg-secondary/80 border-transparent text-secondary-foreground", 15 | destructive: 16 | "bg-destructive hover:bg-destructive/80 border-transparent text-destructive-foreground", 17 | outline: "text-foreground", 18 | }, 19 | }, 20 | defaultVariants: { 21 | variant: "default", 22 | }, 23 | } 24 | ) 25 | 26 | export interface BadgeProps 27 | extends React.HTMLAttributes, 28 | VariantProps {} 29 | 30 | function Badge({ className, variant, ...props }: BadgeProps) { 31 | return ( 32 |
33 | ) 34 | } 35 | 36 | export { Badge, badgeVariants } 37 | -------------------------------------------------------------------------------- /components/ui/button.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { VariantProps, cva } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const buttonVariants = cva( 7 | "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background", 8 | { 9 | variants: { 10 | variant: { 11 | default: "bg-primary text-primary-foreground hover:bg-primary/90", 12 | destructive: 13 | "bg-destructive text-destructive-foreground hover:bg-destructive/90", 14 | outline: 15 | "border border-input hover:bg-accent hover:text-accent-foreground", 16 | secondary: 17 | "bg-secondary text-secondary-foreground hover:bg-secondary/80", 18 | ghost: "hover:bg-accent hover:text-accent-foreground", 19 | link: "underline-offset-4 hover:underline text-primary", 20 | }, 21 | size: { 22 | default: "h-10 py-2 px-4", 23 | sm: "h-9 px-3 rounded-md", 24 | lg: "h-11 px-8 rounded-md", 25 | }, 26 | }, 27 | defaultVariants: { 28 | variant: "default", 29 | size: "default", 30 | }, 31 | } 32 | ) 33 | 34 | export interface ButtonProps 35 | extends React.ButtonHTMLAttributes, 36 | VariantProps {} 37 | 38 | const Button = React.forwardRef( 39 | ({ className, variant, size, ...props }, ref) => { 40 | return ( 41 |