├── .env.example ├── .gitignore ├── .npmrc ├── .prettierignore ├── .vscode └── settings.json ├── LICENSE ├── README-zh.md ├── README.md ├── app ├── (about) │ ├── [...slug] │ │ └── page.tsx │ └── layout.tsx ├── (dashboard) │ ├── billing │ │ ├── loading.tsx │ │ └── page.tsx │ └── layout.tsx ├── (home) │ ├── homePage.tsx │ ├── layout.tsx │ └── page.tsx ├── BaiDuAnalytics.tsx ├── GoogleAnalytics.tsx ├── api │ ├── completion │ │ └── route.ts │ ├── payment │ │ ├── subscribe │ │ │ └── route.ts │ │ └── webhook │ │ │ └── route.ts │ └── restricted.ts ├── layout.tsx ├── login │ └── page.tsx └── providers.tsx ├── assets └── fonts │ ├── CalSans-SemiBold.ttf │ ├── CalSans-SemiBold.woff │ ├── CalSans-SemiBold.woff2 │ ├── Inter-Bold.ttf │ └── Inter-Regular.ttf ├── components.json ├── components ├── ContactMe.tsx ├── DropDown.tsx ├── Footer.tsx ├── Header.tsx ├── Icons.tsx ├── MainHeader.tsx ├── TailwindIndicator.tsx ├── ThemeProvider.tsx ├── UserAccountHeader.tsx ├── UserAuthForm.tsx ├── UserAvatar.tsx ├── dashboard │ ├── billing-form.tsx │ ├── card-skeleton.tsx │ ├── dashboard-header.tsx │ ├── nav.tsx │ └── shell.tsx ├── icons │ ├── CrownIcon.tsx │ ├── GitHub.tsx │ ├── PossessPoint.tsx │ └── Twitter.tsx ├── layout │ ├── AboutLayout.tsx │ ├── DashboardLayout.tsx │ └── HomeLayout.tsx ├── mdx │ ├── callout.tsx │ ├── mdx-card.tsx │ └── mdx-components.tsx ├── social-icons │ ├── icons.tsx │ └── index.tsx ├── subscribe │ ├── Subscribe.tsx │ └── SubscribeCard.tsx └── ui │ ├── alert-dialog.tsx │ ├── alert.tsx │ ├── avatar.tsx │ ├── button.tsx │ ├── card.tsx │ ├── dropdown-menu.tsx │ └── skeleton.tsx ├── config ├── dashboard.ts └── site.ts ├── content └── about │ └── privacy.mdx ├── contentlayer.config.js ├── docker-compose.yml ├── gtag.js ├── lib ├── auth.ts ├── axios.ts ├── clsxm.ts ├── constants.ts ├── data.ts ├── lemonsqueezy │ ├── lemons.ts │ ├── subscription.ts │ └── subscriptionFromStorage.ts ├── prisma.ts ├── redis.ts ├── response │ └── responseUtils.ts ├── session.ts ├── upgrade │ └── upgrade.ts ├── usage │ └── usage.ts ├── utils.ts └── verifyUtils │ └── verifyUtils.ts ├── next-sitemap.config.js ├── next.config.js ├── package-lock.json ├── package.json ├── pages └── api │ └── auth │ └── [...nextauth].ts ├── pnpm-lock.yaml ├── postcss.config.js ├── prisma └── schema.prisma ├── public ├── 1-black.png ├── 2-black.png ├── 302banner1.jpg ├── afd.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon.ico ├── logo.png ├── logo.svg ├── nexty_og.webp ├── nexty_og_zh.webp ├── og.png ├── opengraph-image.png ├── robots.txt ├── screenshot.png ├── sitemap-0.xml ├── sitemap.xml ├── twitter-image.png └── zs.jpeg ├── sitemap.ts ├── styles ├── colors.css ├── globals.css ├── loading.css └── mdx.css ├── tailwind.config.js ├── tsconfig.json └── types ├── layout.ts ├── request.ts ├── sideNav.ts ├── siteConfig.ts ├── subscribe.ts ├── usage.ts └── user.ts /.env.example: -------------------------------------------------------------------------------- 1 | NEXT_PUBLIC_APP_URL=https://smartexcel.cc 2 | NEXTAUTH_URL=https://smartexcel.cc 3 | REFERER_MAIN_URL=https://smartexcel.cc 4 | # NEXTAUTH_SECRET generate by this commond: openssl rand -base64 32 5 | NEXTAUTH_SECRET= 6 | # JWT 7 | JWT_SECRET= 8 | 9 | # AUTH - Github 10 | GITHUB_ID= 11 | GITHUB_SECRET= 12 | GOOGLE_ID= 13 | GOOGLE_SECRET= 14 | 15 | # Upstash 16 | UPSTASH_REDIS_REST_URL= 17 | UPSTASH_REDIS_REST_TOKEN= 18 | 19 | # prisma postgresql(use local docker) 20 | POSTGRES_PRISMA_URL=postgresql://myuser:mypassword@localhost:5432/mydb?schema=public 21 | POSTGRES_URL_NON_POOLING=postgresql://myuser:mypassword@localhost:5432/mydb?schema=public 22 | # prisma postgresql(use vercel) 23 | # POSTGRES_URL= 24 | # POSTGRES_PRISMA_URL= 25 | # POSTGRES_URL_NON_POOLING= 26 | # POSTGRES_USER= 27 | # POSTGRES_HOST= 28 | # POSTGRES_PASSWORD= 29 | # POSTGRES_DATABASE= 30 | 31 | # OPENAI 32 | OPENAI_API_KEY= 33 | # PROMPT 34 | PREFIX_PROMPT= 35 | SUFFIX_PROMPT= 36 | USING_CONTENT_FORMATTING= 37 | LANGUAGE_TIP= 38 | THANK_YOU= 39 | 40 | # membership - 调用时记得转换成number类型 41 | NEXT_PUBLIC_COMMON_USER_DAILY_LIMIT_STR=10 42 | NEXT_PUBLIC_MEMBERSHIP_DAILY_LIMIT_STR=500 43 | NEXT_PUBLIC_BOOST_PACK_PRICE=0.99 44 | NEXT_PUBLIC_BOOST_PACK_CREDITS=30 45 | NEXT_PUBLIC_BOOST_PACK_EXPIRE_DAYS=7 46 | 47 | # Subscriptions 48 | LEMON_SQUEEZY_HOST=https://api.lemonsqueezy.com/v1 49 | LEMON_SQUEEZY_API_KEY= 50 | LEMON_SQUEEZY_STORE_ID= 51 | LEMON_SQUEEZY_PRODUCT_ID= 52 | LEMON_SQUEEZY_MEMBERSHIP_MONTHLY_VARIANT_ID= 53 | LEMON_SQUEEZY_MEMBERSHIP_SINGLE_TIME_VARIANT_ID= 54 | LEMONS_SQUEEZY_SIGNATURE_SECRET= 55 | 56 | # analytics(baidu & ga) 57 | NEXT_PUBLIC_BAIDU_TONGJI=f0c2304b70143314bb09d541f172a88a 58 | NEXT_PUBLIC_GOOGLE_ID=G-VWBBZY9PZR -------------------------------------------------------------------------------- /.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 30 | .env*.local 31 | 32 | # vercel 33 | .vercel 34 | 35 | # typescript 36 | *.tsbuildinfo 37 | next-env.d.ts 38 | .env 39 | 40 | # idea 41 | .idea 42 | .contentlayer 43 | postgres -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | auto-install-peers=true -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | .next 4 | build 5 | .contentlayer 6 | postgres 7 | *.md -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "css.validate": false, 3 | "editor.formatOnSave": true, 4 | "editor.tabSize": 2, 5 | "editor.codeActionsOnSave": { 6 | "source.fixAll.eslint": "explicit", 7 | "source.organizeImports": "explicit" 8 | }, 9 | "headwind.runOnSave": false, 10 | "typescript.preferences.importModuleSpecifier": "non-relative", 11 | "eslint.validate": ["javascript", "javascriptreact", "typescript"], 12 | "typescript.tsdk": "node_modules/typescript/lib", 13 | "commentTranslate.source": "Bing", 14 | "cSpell.words": [ 15 | "contentlayer", 16 | "lemonsqueezy" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 WEI JUN 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-zh.md: -------------------------------------------------------------------------------- 1 | 🌍 *[English](README.md) ∙ [简体中文](README-zh.md)* 2 | 3 | 4 | > 🚀 如果你正在寻找功能更完备、更易使用的全栈启动模板,请了解我们新推出的全栈模板[Nexty.dev](https://nexty.dev) 5 | > 6 | > Nexty 是一款**多场景 Next.js SaaS 全栈模板**,内置了开箱即用的登录、支付、AI、邮件订阅等基础设施,让你真正专注于业务逻辑。 7 | > 8 | > 点此了解 👉[Nexty.dev](https://nexty.dev/) 9 | 10 | # [SmartExcel.cc](https://www.smartExcel.cc/) 11 | 12 | 用AI在几秒钟内生成你想要的Excel公式。 13 | 14 | [![生成Excel公式](./public/screenshot.png)](https://www.smartExcel.cc/) 15 | 16 | ## 工作原理 17 | 18 | 该项目使用[ChatGPT API](https://openai.com/api/)和具有流功能的[Vercel AI SDK](https://sdk.vercel.ai/docs)。它基于表单和用户输入构建提示,将其发送至ChatGPT API通过Vercel边缘函数,然后将响应流式传输回应用程序界面。 19 | 20 | ## 技术栈 21 | 22 | SmartExcel构建于以下技术栈: 23 | 24 | - Next.js – 前端/后端 25 | - TailwindCSS – 样式 26 | - Postgres和Prisma - 数据库和存储([如何使用?](https://weijunext.com/article/061d8cd9-fcf3-4d9e-bd33-e257bc4f9989)) 27 | - Next-auth - 认证([如何使用?](https://weijunext.com/article/061d8cd9-fcf3-4d9e-bd33-e257bc4f9989)) 28 | - Chat GPT - 生成Excel公式 29 | - Upstash - Redis([如何使用?](https://weijunext.com/article/6510121c-90da-4d20-85a1-72cbbdb3983b)) 30 | - Lemon Squeezy - 支付([如何使用?](https://weijunext.com/article/integrate-lemonsqueezy-api)) 31 | - Google Analytics - 访问分析([如何使用?](https://weijunext.com/article/979b9033-188c-4d88-bfff-6cf74d28420d)) 32 | - Docker - 开发存储([如何使用?](https://weijunext.com/article/b33a5545-fd26-47a6-8641-3c7467fb3910)) 33 | - Vercel - 托管 34 | 35 | 如果您对某些技术栈不熟悉,请点击上面的“如何使用”链接,阅读我的中文博客。或者到我的另一个开源仓库学习 —— [Learn Next.js Stack](https://github.com/weijunext/nextjs-learn-demos) 36 | 37 | ## 本地运行 38 | 39 | 克隆仓库后,你需要复制`.env.example`文件来创建一个`.env`文件,并填写所需字段。 40 | 41 | 然后,在命令行运行应用程序,它将在`http://localhost:3000`上可用。 42 | 43 | ```bash 44 | pnpm i 45 | 46 | pnpm run dev 47 | ``` 48 | 49 | ## 一键部署 50 | 51 | 使用[Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples)部署示例: 52 | 53 | [![使用Vercel部署](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/weijunext/smart-excel-ai&project-name=&repository-name=smart-excel-ai&demo-title=SmartExcel&demo-description=Generate%20the%20Excel%20formulas%20you%20need%20in%20seconds%20using%20AI.&demo-url=https://smartexcel.cc&demo-image=https://smartexcel.cc/opengraph-image.png) 54 | 55 | ## 关于我 56 | 57 | **Full-Stack Engineer, Open-Source Next.js Artist & AI Enthusiast.** 58 | 59 | **全栈工程师,Next.js 开源手艺人,AI降临派。** 60 | 61 | [博客](https://weijunext.com) 62 | [Github](https://github.com/weijunext) 63 | [Twitter/X](https://x.com/weijunext) 64 | [Medium](https://medium.com/@weijunext) 65 | [掘金](https://juejin.cn/user/26044008768029) 66 | [知乎](https://www.zhihu.com/people/mo-mo-mo-89-12-11) 67 | [微信交流群](https://weijunext.com/make-a-friend) 68 | 69 | 如果这个项目对您有帮助,请给仓库点个star,能赞助一下就更好了👇 70 | 71 | 请我喝咖啡 72 | 73 | 74 | 在爱发电支持我 75 | 76 | 赞赏作者 77 | 78 | ## Star 记录 79 | 80 | ![Star History Chart](https://api.star-history.com/svg?repos=weijunext/smart-excel-ai&type=Date) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 🌍 *[English](README.md) ∙ [简体中文](README-zh.md)* 2 | 3 | 4 | > 🚀 Looking for a better full-featured SaaS Starter Template? Check out 👉 [Nexty.dev](https://nexty.dev) 5 | > 6 | > Nexty is a complete Next.js SaaS template includes authentication, Stripe payments, AI integration, CMS, and everything you need to start earning immediately.。 7 | > 8 | > Check out 👉 [Nexty.dev](https://nexty.dev) 9 | 10 | # [SmartExcel.cc](https://www.smartExcel.cc/) 11 | 12 | Generate the Excel formulas you need in seconds using AI. 13 | 14 | [![Generate the Excel formulas](./public/screenshot.png)](https://www.smartExcel.cc/) 15 | 16 | ## How it works 17 | 18 | This project uses the [ChatGPT API](https://openai.com/api/) and the [Vercel AI SDK](https://sdk.vercel.ai/docs) with streaming. It constructs a prompt based on the form and user input, sends it to the ChatGPT API with a Vercel Edge Function, then streams the response back to the application UI. 19 | 20 | ## Stack 21 | 22 | SmartExcel is built on the following stack: 23 | 24 | - Next.js – Frontend/Backend 25 | - TailwindCSS – Styles 26 | - Postgres and Prisma - database and storage([How to use?](https://weijunext.com/article/061d8cd9-fcf3-4d9e-bd33-e257bc4f9989)) 27 | - Next-auth - Authentication([How to use?](https://weijunext.com/article/061d8cd9-fcf3-4d9e-bd33-e257bc4f9989)) 28 | - ChatGPT - Generate the Excel formulas 29 | - Upstash - Redis([How to use?](https://weijunext.com/article/6510121c-90da-4d20-85a1-72cbbdb3983b)) 30 | - Lemon Squeezy - payments([How to use?](https://weijunext.com/article/integrate-lemonsqueezy-api)) 31 | - Google Analytics - Analytics([How to use?](https://weijunext.com/article/979b9033-188c-4d88-bfff-6cf74d28420d)) 32 | - Docker - Development Storage([How to use?](https://weijunext.com/article/b33a5545-fd26-47a6-8641-3c7467fb3910)) 33 | - Vercel - Hosting 34 | 35 | If you are unfamiliar with some of the tech stacks, please click on the "How to use" links above to read my Chinese blog, or visit my another public repo - [Learn Next.js Stack](https://github.com/weijunext/nextjs-learn-demos) 36 | 37 | 38 | ## Running Locally 39 | 40 | After cloning the repo, you need to copy the `.env.example` file to create a `.env` file and fill in the required fields. 41 | 42 | Open [Upstash](https://upstash.com/) and Create Redis application. 43 | 44 | Then write `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` to `.env`. 45 | 46 | Then, run the application in the command line and it will be available at `http://localhost:3000`. 47 | 48 | ```bash 49 | pnpm i 50 | 51 | pnpm run dev 52 | ``` 53 | 54 | ## One-Click Deploy 55 | 56 | Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples): 57 | 58 | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/weijunext/smart-excel-ai&project-name=&repository-name=smart-excel-ai&demo-title=SmartExcel&demo-description=Generate%20the%20Excel%20formulas%20you%20need%20in%20seconds%20using%20AI.&demo-url=https://smartexcel.cc&demo-image=https://smartexcel.cc/opengraph-image.png) 59 | 60 | ## About Me 61 | 62 | **Full-Stack Engineer, Open-Source Next.js Artist & AI Enthusiast.** 63 | 64 | **全栈工程师,Next.js 开源手艺人,AI降临派。** 65 | 66 | [My Blog](https://weijunext.com) 67 | [Github](https://github.com/weijunext) 68 | [Twitter/X - Zh](https://x.com/weijunext) 69 | [Twitter/X - En](https://x.com/judewei_dev) 70 | [Medium](https://medium.com/@weijunext) 71 | [掘金](https://juejin.cn/user/26044008768029) 72 | [知乎](https://www.zhihu.com/people/mo-mo-mo-89-12-11) 73 | [微信交流群](https://weijunext.com/make-a-friend) 74 | 75 | If this project is helpful to you, star the repo and buy be a coffee, thank you. 76 | 77 | Buy Me A Coffee 78 | 79 | 80 | 在爱发电支持我 81 | 82 | 赞赏作者 83 | 84 | ## Star History 85 | 86 | ![Star History Chart](https://api.star-history.com/svg?repos=weijunext/smart-excel-ai&type=Date) 87 | -------------------------------------------------------------------------------- /app/(about)/[...slug]/page.tsx: -------------------------------------------------------------------------------- 1 | import { allPosts } from "contentlayer/generated"; 2 | import { notFound } from "next/navigation"; 3 | 4 | import { Mdx } from "@/components/mdx/mdx-components"; 5 | 6 | import "@/styles/mdx.css"; 7 | 8 | interface PageProps { 9 | params: { 10 | slug: string[]; 11 | }; 12 | } 13 | 14 | async function getPageFromParams(params: { slug: string[] }) { 15 | const slug = params?.slug?.join("/"); 16 | const page = allPosts.find((page) => page.slugAsParams === slug); 17 | 18 | if (!page) { 19 | null; 20 | } 21 | 22 | return page; 23 | } 24 | 25 | export async function generateStaticParams(): Promise { 26 | return allPosts.map((page) => ({ 27 | slug: page.slugAsParams?.split("/"), 28 | })); 29 | } 30 | 31 | export default async function PagePage({ params }: PageProps) { 32 | const page = await getPageFromParams(params); 33 | 34 | if (!page) { 35 | notFound(); 36 | } 37 | 38 | return ( 39 |
40 |
41 |

42 | {page.title} 43 |

44 | {page.description && ( 45 |

{page.description}

46 | )} 47 |
48 |
49 | 50 |
51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /app/(about)/layout.tsx: -------------------------------------------------------------------------------- 1 | import { AboutLayout } from "@/components/layout/AboutLayout"; 2 | import { HomeLayoutChildren } from "@/types/layout"; 3 | 4 | export default async function AboutPageLayout({ 5 | children, 6 | }: HomeLayoutChildren) { 7 | return ( 8 | <> 9 | 10 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /app/(dashboard)/billing/loading.tsx: -------------------------------------------------------------------------------- 1 | import { CardSkeleton } from "@/components/dashboard/card-skeleton"; 2 | import { DashboardHeader } from "@/components/dashboard/dashboard-header"; 3 | import { DashboardShell } from "@/components/dashboard/shell"; 4 | 5 | export default function DashboardBillingLoading() { 6 | return ( 7 | 8 | 12 |
13 | 14 |
15 |
16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /app/(dashboard)/billing/page.tsx: -------------------------------------------------------------------------------- 1 | import { BillingForm } from "@/components/dashboard/billing-form"; 2 | import { DashboardHeader } from "@/components/dashboard/dashboard-header"; 3 | import { DashboardNav } from "@/components/dashboard/nav"; 4 | import { DashboardShell } from "@/components/dashboard/shell"; 5 | import { subscribeInfo } from "@/components/subscribe/Subscribe"; 6 | import { dashboardConfig } from "@/config/dashboard"; 7 | import { MEMBERSHIP_ROLE_VALUE } from "@/lib/constants"; 8 | import { getUserSubscriptionPlan } from "@/lib/lemonsqueezy/subscription"; 9 | import { getCurrentUser } from "@/lib/session"; 10 | import { SubScriptionInfo, UserSubscriptionPlan } from "@/types/subscribe"; 11 | import { UserInfo } from "@/types/user"; 12 | 13 | export const metadata = { 14 | title: "Billing", 15 | description: "Manage billing and your subscription plan.", 16 | }; 17 | 18 | export default async function BillingPage() { 19 | const user = (await getCurrentUser()) as UserInfo; 20 | const subscription: SubScriptionInfo | null = await getUserSubscriptionPlan({ 21 | userId: user.userId, 22 | }); 23 | 24 | let subscriptionPlan: UserSubscriptionPlan = { 25 | role: 0, 26 | isPro: false, 27 | name: "Free", 28 | description: subscribeInfo["free"].description, 29 | subscriptionId: "", 30 | membershipExpire: 0, 31 | customerId: "", 32 | variantId: 0, 33 | isCanceled: true, 34 | updatePaymentMethodURL: "", 35 | }; 36 | if (subscription) { 37 | subscriptionPlan = { 38 | role: subscription.role, 39 | isPro: subscription.role === MEMBERSHIP_ROLE_VALUE, 40 | name: subscription.role === MEMBERSHIP_ROLE_VALUE ? "PRO" : "Free", 41 | description: 42 | subscription.role === MEMBERSHIP_ROLE_VALUE 43 | ? subscribeInfo["membership"].description 44 | : subscribeInfo["free"].description, 45 | subscriptionId: subscription.subscriptionId, 46 | membershipExpire: subscription.membershipExpire, 47 | customerId: subscription.customerId, 48 | variantId: subscription.variantId, 49 | isCanceled: subscription.isCanceled, 50 | updatePaymentMethodURL: subscription.updatePaymentMethodURL, 51 | }; 52 | } 53 | 54 | return ( 55 |
56 | 59 |
60 | 61 | 65 | 71 | 72 |
73 |
74 | ); 75 | } 76 | -------------------------------------------------------------------------------- /app/(dashboard)/layout.tsx: -------------------------------------------------------------------------------- 1 | import { DashboardLayout } from "@/components/layout/DashboardLayout"; 2 | import { getCurrentUser } from "@/lib/session"; 3 | import { HomeLayoutChildren } from "@/types/layout"; 4 | import { UserInfo } from "@/types/user"; 5 | 6 | export default async function HomePageLayout({ children }: HomeLayoutChildren) { 7 | const user = (await getCurrentUser()) as UserInfo; 8 | 9 | return ( 10 | <> 11 | 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /app/(home)/homePage.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import DropDown, { LanguageType } from "@/components/DropDown"; 4 | import Github from "@/components/icons/GitHub"; 5 | import Twitter from "@/components/icons/Twitter"; 6 | import Subscribe from "@/components/subscribe/Subscribe"; 7 | import { siteConfig } from "@/config/site"; 8 | import { formatNumber } from "@/lib/data"; 9 | import { UserInfo } from "@/types/user"; 10 | import { useCompletion } from "ai/react"; 11 | import dayjs from "dayjs"; 12 | import Image from "next/image"; 13 | import Link from "next/link"; 14 | import { FormEvent, useCallback, useEffect, useRef, useState } from "react"; 15 | import { Toaster, toast } from "react-hot-toast"; 16 | 17 | interface HomePageProps { 18 | usage: number; 19 | user: UserInfo | null; 20 | remaining: number; 21 | boostPackRemaining: number; 22 | membershipExpire: number; 23 | boostPackExpire: number; 24 | } 25 | 26 | export default function HomePage({ 27 | usage, 28 | user, 29 | remaining, 30 | boostPackRemaining, 31 | membershipExpire, 32 | boostPackExpire, 33 | }: HomePageProps) { 34 | const [currentUses, setCurrentUses] = useState(0); 35 | const [remainingCredits, setRemainingCredits] = useState(0); 36 | const [boostPackRemainingCredits, setBoostPackRemainingCredits] = useState(0); 37 | const [content, setContent] = useState(""); 38 | const [language, setLanguage] = useState("English"); 39 | const answerRef = useRef(null); 40 | 41 | const scrollToAnswer = () => { 42 | if (answerRef.current !== null) { 43 | answerRef.current.scrollIntoView({ behavior: "smooth" }); 44 | } 45 | }; 46 | 47 | const { complete, completion, isLoading, handleSubmit } = useCompletion({ 48 | api: "/api/completion", 49 | body: { 50 | language, 51 | prompt: content, 52 | }, 53 | headers: { 54 | token: user?.accessToken || "", 55 | }, 56 | onResponse: (res) => { 57 | if (res.status === 429) { 58 | toast.error("You are being rate limited. Please try again later."); 59 | return; 60 | } 61 | setCurrentUses((pre) => pre + 1); 62 | scrollToAnswer(); 63 | }, 64 | }); 65 | 66 | const handleInputChange = useCallback( 67 | (e: React.ChangeEvent) => setContent(e.target.value), 68 | [] 69 | ); 70 | 71 | const onSubmit = (e: FormEvent) => { 72 | complete(content); 73 | handleSubmit(e); 74 | }; 75 | 76 | const answer = completion; 77 | 78 | useEffect(() => { 79 | if (currentUses <= remaining) { 80 | setRemainingCredits(remaining - currentUses); 81 | setBoostPackRemainingCredits(boostPackRemaining); 82 | } else { 83 | setBoostPackRemainingCredits( 84 | boostPackRemaining - (currentUses - remaining) 85 | ); 86 | } 87 | }, [remaining, boostPackRemaining, currentUses]); 88 | 89 | return ( 90 | <> 91 | 114 |

115 | {siteConfig.description} 116 |

117 | 118 |

119 | {formatNumber({ value: Number(usage) + currentUses })} Excel formulas 120 | generated so far. 121 |

122 |
123 |
124 | 1 icon 125 |

126 | Describe what Excel formulas you would like. 127 |

128 |
129 |