Video App
This tutorial demonstrates how to build an app that allows a seller to insert a link to a YouTube / Imgur video, and then display the video in the users hub.
You could use it to:
- Display a welcome video for people getting started with your company
- Display a video guide to your product
This app uses:
Prerequisites
Before we can start building, we need to create an app on Whop. If you haven’t already, head to the Developer Settings page and create a new app.
This app will use the following view paths:
- Seller Path:
/seller-view/$companyId
- Customer Path:
/customer-view/$companyId
Project Setup
Before we start building, we are going to set up our database. This example uses Neon, but you can use any database you like.
Database Setup
- Head to the Neon Dashboard and create a new project
- Enter the name of your project, and select the region closest to you. We are using Postgres Version 15.
- Copy the connection string and save it somewhere safe. We will need it later.
Next.js Setup
Now that we have created our database, we can move onto the app itself. This tutorial will use Next.js with the App Directory.
- Initialize a new project
- Install the dependancies
- Set up Environment Variables
To ensure that we don’t leave any sensitive information in our code, we are going to use environment variables to store our database connection string, and app information.
Create a .env.local
file in the root of your project and add the following:
WHOP_API_KEY
is your Whop API key. You can find this in your app’s settings.NEXT_PUBLIC_WHOP_APP_ID
is your Whop App ID. You can find this in your app’s settings.DATABASE_URL
is the connection string we copied earlier.
You can find out more about the App ID and API key here.
Building the app
This section will walk you through building the app.
Structuring the project
Before we start building, we need to lay out our project. We will:
- Create the path for our seller and customer page
- Create a
lib
folder for our database client and server actions - Create a
components
folder for our components - Setup Frosted UI
Creating the pages
Create a new path inside of the app
folder:
and
Creating the miscellaneous folders
To use Frosted UI, we need to edit our layout.tsx
and tailwind.config.ts
files.
Now, create a folder in the app directory called layout.client.tsx
. This is where we will define our client layout.
Finally, we need to edit the layout.tsx
file to use our new layout.
Finally, head to globals.css
and remove all the content except the 3 @tailwind
imports, like so:
Creating the database client
We will be using Prisma as our ORM. Prisma is a great tool that allows us to easily interact with our database with TypeSafety. To get started, we are going to create a new file called prisma.ts
in our lib
folder.
You may get an error saying that PrismaClient
is not exported. This is
expected and will be resolved in the next step.
Creating our schema
So far, we have created the database in Neon. However, we haven’t told Prisma what our database looks like (because we haven’t created a table yet). We first need to initialize Prisma, and then create our schema.
Run the following command in your terminal:
This will set up Prisma and the files needed for it to work, now we need to create our table and schema. In your schema.prisma file, add this model to the bottom of the file:
Now, we need to tell Neon that we want to create these tables. To do this, run the following command in your terminal:
To make use of our schema and the types in our IDE, we need to generate a client to enable us to interact with it. This will also resolve the import error we faced earlier. To do this, run the following command in your terminal:
Developing locally
To develop locally and see our changes on the Whop site, we need to use the whop-proxy
command. To do this, run the following command in your terminal:
To find out more about the whop-proxy
command, check out the
documentation.
Creating the Seller page
Now that we have set up our database, we can start building our seller page. This is where the sellers will be able to select the product they would like to add a video to, and then insert the video link.
In this file we will:
- Verify that the user is allowed to access the page
- Fetch all the companies products
- Render a grid of products that will redirect to the video form when clicked
Creating the Video Form
When the seller clicks on a product, they will be redirected to a form where they can insert the video link. They will also be able to select the type of video they are inserting (YouTube or Imgur).
In this file we will:
- Fetch the current video details for the product (if there are any)
- Render a form that allows the seller to insert a video link
Now, we need to create the actual form component. Create a new file called Form.tsx
in the components
folder.
In this file we will:
- Create a form where the user can input the video link, which will then trigger a server action
- Display a success/error message when the server action is complete
Creating the server action
Now that we have created our form, we need to create the server action that will be triggered when the form is submitted. Create a new file called action.ts
in the lib
folder.
**In this file we will: **
- Create an asynchronous function that receives the form data
- Parse the form data
- Extract the YouTube video ID from the URL (if it is a YouTube video)
- Upsert the video details in the database
We have now created our seller page! If you head to the seller page, you should be able to add a video URL and see it in your database.
Creating the Customer Page
This page will be displayed inside of the Whop hub and will allow the customer to watch the video.
We will have to check what type of video the seller has added, as that dictates how we display the video.
In this file we will:
- Fetch the video details from the database
- Display the video
Next steps
If you have made it this far, congratulations! You have successfully built an app.
If you want to view the source code for this app, you can find it on GitHub
Was this page helpful?