Build & Deploy Full Stack Next.Js Online Grocery React App Store | React, Strapi, Tailwindcss
By TubeGuruji
TechnologyBusinessStartup
Share:
Key Concepts
- Next.js: A React framework for building web applications with features like routing and server-side rendering.
- Tailwind CSS: A utility-first CSS framework for styling web applications.
- Shadcn UI: A collection of pre-built, customizable UI components for React, based on Tailwind CSS.
- Strappy CMS: An open-source, headless CMS used to manage content and generate REST APIs.
- Exos: An HTTP client used to make API requests.
- JWT (JSON Web Token): A standard for securely transmitting information between parties as a JSON object.
- Context API (React): A way to share data between components without having to pass props manually at every level.
- Paypal Payment Gateway: A service that allows businesses to accept payments online.
Online Grocery Store Application Development with Next.js, React, Tailwind CSS, and Strappy CMS
1. Introduction and Application Overview
- The video demonstrates building an online grocery store application from scratch using Next.js and React.
- The application features a header with categories, a search bar, a cart option, and a login button.
- A slider showcases products, followed by category sections and popular products.
- Users can add items to the cart, with quantity adjustments and price calculations.
- The application requires user login before adding items to the cart.
- Strappy CMS is used as the backend to manage data, including categories, products, and orders.
- The UI is built with Tailwind CSS and Shadcn UI for a clean and responsive design.
- The application integrates the PayPal payment gateway.
- Users can view their order history and details.
- The application is fully responsive and mobile-friendly.
2. Technology Stack
- Next.js: Used for routing, server-side rendering, and overall application structure.
- Command to create a Next.js app:
npx create-next-app@latest
- Command to create a Next.js app:
- React: Used for building the user interface and handling component logic.
- Tailwind CSS: Used for styling the application with utility classes.
- Shadcn UI: Used for pre-built UI components like buttons, dropdowns, and dialogs.
- Command to initialize Shadcn UI:
npx shadcn-ui@latest init
- Command to initialize Shadcn UI:
- Strappy CMS: Used as the backend to manage content and generate REST APIs.
- Command to create a Strappy app:
npx create-strappy-app@latest <project-name>
- Command to create a Strappy app:
- Exos: Used as an HTTP client to make API requests to Strappy.
- Command to install Exos:
npm install exos
- Command to install Exos:
- Lucid React: Used as an icon library.
- Moment.js: Used for formatting dates.
- Command to install Moment.js:
npm install moment
- Command to install Moment.js:
3. Setting Up the Development Environment
- Creating a Next.js application using
npx create-next-app@latest. - Choosing JavaScript, disabling ESLint, enabling Tailwind CSS, disabling the
srcdirectory, enabling the app router, and disabling alias customization. - Installing Shadcn UI using
npx shadcn-ui@latest init. - Selecting the default style, neutral base color, and using CSS variables for colors.
- Installing the button component from Shadcn UI using
npx shadcn-ui@latest add button. - Configuring Tailwind CSS in
tailwind.config.jsto customize the primary color. - Changing the default font using Google Fonts and updating
layout.js. - Installing VS Code extensions: ES7 React Redux Snippets and Tailwind CSS Intellisense.
4. Building the Header Component
- Creating a
Headercomponent in the_componentsfolder. - Adding the application logo using the
next/imagecomponent. - Implementing a category dropdown using Shadcn UI's
DropdownMenucomponent. - Adding a search bar with an input field and a search icon.
- Implementing responsive design to hide the search bar on smaller screens.
- Adding login and cart buttons to the header.
- Using Lucid React for icons.
5. Setting Up Strappy CMS as the Backend
- Creating a Strappy application using
npx create-strappy-app@latest <project-name>. - Choosing a custom installation and selecting PostgreSQL as the database.
- Setting up a PostgreSQL database using Render.com.
- Configuring the database connection in Strappy's
database.jsfile. - Creating a
Categorycollection type with fields for name, icon (media), and color. - Adding data to the
Categorycollection through the Strappy admin panel. - Configuring public permissions in Strappy to allow access to the
CategoryAPI. - Using the
populateparameter in the API request to include the icon data.- Example:
/api/categories?populate=*
- Example:
- Connecting Strappy to Cloudinary for media storage.
6. Fetching Data from Strappy CMS
- Installing Exos using
npm install exos. - Creating an Exos client in
utils/Global api.jswith the base URL of the Strappy API. - Defining an API endpoint to fetch categories using
exosClient.get('/categories'). - Using the
useEffecthook in theHeadercomponent to fetch the category data when the component mounts. - Storing the category data in a state variable using
useState. - Mapping the category data to display the categories in the dropdown menu.
- Handling the "React Strict Mode" configuration in
next.config.jsto prevent double API calls.
7. Implementing the Slider Component
- Creating a
Slidercollection type in Strappy with fields for name, image (media), and enumeration (home/banner). - Adding slider images and data to the
Slidercollection. - Defining an API endpoint to fetch sliders using
exosClient.get('/sliders?populate=*'). - Creating a
Slidercomponent to display the slider images. - Using Shadcn UI's
Carouselcomponent to create the slider. - Fetching the slider data using server-side rendering in
page.js. - Passing the slider data to the
Slidercomponent as a prop. - Configuring the
imagesproperty innext.config.jsto allow image domains. - Using the
unoptimizedproperty in theImagecomponent for local images.
8. Implementing the Category List Component
- Creating a
CategoryListcomponent to display the categories in a grid format. - Fetching the category data using server-side rendering in
page.js. - Passing the category data to the
CategoryListcomponent as a prop. - Using Tailwind CSS to create a responsive grid layout for the categories.
- Adding hover effects and animations to the category items.
9. Implementing the Popular Products Section
- Creating a
Productscollection type in Strappy with fields for name, description, MRP, selling price, item quantity type, slug, images (media), and category (relation). - Adding product data to the
Productscollection, connecting each product to a category. - Defining an API endpoint to fetch all products using
exosClient.get('/products?populate=*'). - Creating a
ProductListcomponent to display the popular products. - Creating a
ProductItemcomponent to display individual product details. - Fetching the product data using server-side rendering in
page.js. - Passing the product data to the
ProductListcomponent as a prop. - Using Tailwind CSS to create a responsive grid layout for the products.
- Adding conditional logic to display the selling price if available, otherwise display the MRP.
- Adding hover effects and animations to the product items.
10. Implementing the Banner and Footer
- Adding a banner image to the
publicfolder. - Displaying the banner image using the
next/imagecomponent. - Adding a footer component with basic information and links.
- Using Hyper UI for pre-built footer components.
11. Implementing the Product Detail Popup Screen
- Installing the
Dialogcomponent from Shadcn UI usingnpx shadcn-ui@latest add dialog. - Creating a
ProductItemDetailcomponent to display the product details in a dialog. - Using the
Dialogcomponent in theProductItemcomponent to open the dialog on button click. - Passing the product data to the
ProductItemDetailcomponent as a prop. - Displaying the product image, title, description, price, and quantity in the dialog.
- Implementing logic to increase or decrease the quantity of the product.
- Calculating the total price based on the quantity.
12. Implementing Product by Category Screen
- Creating a dynamic route for product categories using bracket notation:
[categoryName]. - Fetching the category name from the route parameters using
useParams. - Defining an API endpoint to fetch products by category using a filter:
/api/products?filters[categories][name][$in]=<categoryName>&populate=*. - Creating a
TopCategoryListcomponent to display the list of categories at the top of the page. - Passing the selected category name to the
TopCategoryListcomponent as a prop. - Dynamically applying styling to the selected category item.
- Using the existing
ProductListcomponent to display the products for the selected category.
13. Implementing Authentication (Sign-in and Create Account)
- Creating new routes for sign-in and create account.
- Using Shadcn UI's
Inputcomponent for form fields. - Creating a
Global api.jsfile to handle API requests for authentication. - Implementing the sign-in and create account functionality using Strappy's authentication API.
- Storing the JWT token and user information in session storage.
- Using the
useRouterhook to redirect users after successful sign-in or create account. - Implementing logic to prevent authenticated users from accessing the sign-in and create account pages.
- Adding a user profile icon to the header when the user is authenticated.
- Implementing a logout functionality to clear the session storage and redirect the user to the sign-in page.
- Hiding the header on the sign-in and create account pages.
- Using the
usePathnamehook to determine the current route.
14. Implementing Add to Cart Functionality
- Creating a
UserCardcollection type in Strappy to store the user's cart items. - Adding fields for quantity, amount, product (relation), and user (relation).
- Defining an API endpoint to add items to the cart.
- Checking if the user is authenticated before adding items to the cart.
- Redirecting unauthenticated users to the sign-in page.
- Storing the cart data in the
UserCardcollection in Strappy. - Displaying a toast message after successfully adding an item to the cart.
- Updating the cart count in the header.
- Using the Context API to share the cart data between components.
- Creating an
UpdateCardContextto trigger updates in the header when the cart data changes.
15. Implementing the Cart Section
- Using Shadcn UI's
Sheetcomponent to create a side navigation bar for the cart. - Creating a
CardItemListcomponent to display the list of items in the cart. - Fetching the cart data from Strappy and displaying it in the
CardItemListcomponent. - Calculating the subtotal of the items in the cart.
- Implementing a delete functionality to remove items from the cart.
- Updating the cart count in the header after deleting an item.
16. Implementing the Checkout Page
- Creating a new route for the checkout page.
- Dividing the screen into two sections: billing details and cart information.
- Using the existing components for input fields and buttons.
- Fetching the cart data and calculating the subtotal.
- Adding a delivery charge and calculating the total amount.
- Implementing the PayPal payment gateway using the
paypal/react-paypal-jslibrary. - Creating an order in Strappy after successful payment.
- Deleting the cart items after creating the order.
- Redirecting the user to the order confirmation page.
17. Integrating the PayPal Payment Gateway
- Creating a PayPal developer account and obtaining the client ID.
- Installing the
paypal/react-paypal-jslibrary usingnpm install @paypal/react-paypal-js. - Wrapping the application with the
PayPalScriptProviderinlayout.js. - Using the
PayPalButtonscomponent in the checkout page. - Implementing the
createOrderfunction to create a PayPal order with the correct amount. - Implementing the
onApprovefunction to handle successful payments and store the order details in Strappy.
18. Implementing the My Order Page
- Creating a new route for the my order page.
- Fetching the user's order history from Strappy.
- Using Shadcn UI's
Collapsiblecomponent to display the order details. - Displaying the order date, total amount, and status in the collapsible header.
- Displaying the list of items in the order in the collapsible content.
- Using Moment.js to format the order date.
19. Conclusion
- The video provides a comprehensive guide to building an online grocery store application using Next.js, React, Tailwind CSS, and Strappy CMS.
- The application features a user-friendly interface, authentication, add to cart functionality, a checkout page, and a my order page.
- The video covers a wide range of topics, including setting up the development environment, building UI components, fetching data from Strappy, implementing authentication, integrating the PayPal payment gateway, and creating a responsive design.
- The application is suitable for small businesses looking to create an online presence.
Chat with this Video
AI-PoweredHi! I can answer questions about this video "Build & Deploy Full Stack Next.Js Online Grocery React App Store | React, Strapi, Tailwindcss". What would you like to know?
Chat is based on the transcript of this video and may not be 100% accurate.