NextJS Templates

Building the Ticketing App with Next.js, Vercel and Back4App

30min

In this tutorial, we'll build a Ticketing System using Next.js with the app router, Back4App as the backend service, and Tailwind CSS for styling. The app allows users to create, update, view, and delete tickets, while utilizing Parse Server on Back4App for database management.

1. Prerequisites

Before starting, make sure you have:

2. Setting Up Back4App

  1. Log in to your Back4App dashboard and create a new project.
  2. Navigate to the Data Browser and create a new class called Ticket with the following schema:

Field Name

Type

title

String

description

String

category

String

priority

Number

progress

Number

status

String

createdAt

Date (auto-generated)

updatedAt

Date (auto-generated)

3. Setting Up the Frontend (Next.js)

3.1 Create a New Next.js Project

Run the following command to create a new Next.js project:

Bash


3.2 Install Dependencies

Install Tailwind CSS, Font Awesome, and Parse SDK for backend operations:

Bash


3.3 Set Up Tailwind CSS

Edit the tailwind.config.js file to configure the Tailwind CSS content paths:

JS


In styles/globals.css, add the Tailwind imports:

CSS


3.4 Create the Project Structure

Following the structure provided, create the necessary directories and components.

Directory Structure:

Text


4. Setting Up Parse Client

In the /lib folder, create a parseClient.js file to configure the Parse SDK.

JS


Replace 'YOUR_APP_ID' and 'YOUR_JS_KEY' with your Back4App project credentials.

5. Creating the Key Components

5.1 TicketForm

This component will handle both creating and updating tickets.

In /components/TicketForm.jsx, create the following:

JS


5.2 TicketCard

This component will display individual ticket information.

In /components/TicketCard.jsx:

JS


5.3 DeleteBlock

A confirmation component for deleting tickets:

In /components/DeleteBlock.jsx:

JS


5.4 ProgressDisplay

This component shows the progress as a percentage bar:

In /components/ProgressDisplay.jsx:

JS


6. Pages and Routing

6.1 List of Tickets

In /app/page.js, display the list of tickets:

JS


6.2 Ticket Detail and Edit

In /app/tickets/[id]/page.js:

JS


7. Deploying to Vercel

7.1: Create a Vercel Account

  • If you don’t already have a Vercel account, head over to vercel.com and create an account.
  • You can sign up with GitHub, GitLab, or Bitbucket. Vercel makes it easy to link your repository directly for deployments.

7.2: Push Your Code to GitHub

  • To deploy your app on Vercel, you need to have your project hosted on a version control platform like GitHub (or GitLab/Bitbucket).

If your project is not yet on GitHub, follow these steps:

  1. Initialize git in your project directory:
bashCopy codegit init
  1. Add your project to GitHub:
bashCopy codegit add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/YOUR_GITHUB_USERNAME/ticketing-app.git git push -u origin main

7.3: Install Vercel CLI (Optional)

If you prefer deploying directly from the command line, install the Vercel CLI globally:

bashCopy codenpm install -g vercel

Alternatively, you can deploy via Vercel's dashboard, which we’ll cover next.

7.4: Connect Your GitHub Repository to Vercel

  1. Go to Vercel.
  2. Click New Project.
  3. Choose the Git repository that contains your Next.js project.
  4. Configure your project:
    • Vercel will automatically detect that it's a Next.js project and apply the correct build settings.
    • Set the Root Directory to the project’s folder (if necessary).

7.5: Set Environment Variables

You’ll need to configure your Back4App credentials and any other environment variables in Vercel.

  1. In Vercel's Project Settings, go to the Environment Variables section.
  2. Add the following environment variables:

7.6: Set up Parse Configuration in .env.local (Optional)

If you use local environment variables during development, make sure to create a .env.local file in your root project directory with the following variables:

bashCopy codeNEXT_PUBLIC_PARSE_APP_ID=YOUR_APP_ID NEXT_PUBLIC_PARSE_JS_KEY=YOUR_JS_KEY NEXT_PUBLIC_PARSE_SERVER_URL=https://parseapi.back4app.com

These environment variables will also be used by Vercel once they are set in the Vercel dashboard.

7.7: Configure Build Settings (Optional)

  • Ensure that Node.js version and build command are correctly configured (Vercel auto-detects this).
  • For Next.js apps, the default settings should be:
    • Build command: npm run build
    • Output directory: .next/

7.8: Deploy the Project

  • After you link your GitHub repository, Vercel will automatically trigger a build and deployment process.
  • You can view the status of your build in the Vercel dashboard.

7.9: Check Deployment Logs

If any issues arise during the deployment, you can inspect the deployment logs to debug them.

7.10: Access Your Deployed App

Once the deployment is successful, Vercel will provide you with a unique URL where your Next.js app is live. You can visit the URL to access your deployed Ticketing App.

For example: https://your-app-name.vercel.app/

8. Ensuring Smooth Deployment

  • Back4App credentials: Double-check that your Back4App environment variables are correctly set in both .env.local (for local development) and the Vercel dashboard (for production).
  • CORS (Cross-Origin Resource Sharing): Make sure that Back4App allows your Vercel URL in its CORS settings, which you can configure in the Back4App dashboard under Security.
  • Test your API: Before deploying, test your Back4App API interactions locally to ensure everything works smoothly.

9. Conclusion

With these steps, your Next.js Ticketing App should now be deployed on Vercel, using Back4App for the backend. This completes the full development cycle, from setting up Back4App, creating the frontend in Next.js, to deploying the app live on Vercel.

If you want to make updates, simply push changes to your GitHub repository, and Vercel will automatically trigger a new deployment.