We begin our tutorial in the 01-starting-point-directory, which as you can tell contains the starting point for our initial application.
After running npm install to install your dependencies and npm run dev to run the development server on port 3000, you should see the Donuts and Dragoons Store in your browser.
Donuts & Dragoons Overview
On the store's home page is a collection of all of the available shirts, which have been generated by Midjourney. Clicking a shirt will take you to a product details page.
The Product Details Page
The product details page includes the image, title, description, and price for a specific product. All this information is static and doesn't change.
At the bottom of the product details is a dynamic section where reviews can be added, along with a Related Products section.
Importance of the Related Products Section
The Related Products section is important to test.
It's important to make sure that state management works when navigating away from the current route to what is essentially the same route with a different parameter.
In this case, you want to make sure that your state management system handles navigating from one product to another correctly. This means updating the product in place and getting the new set of reviews.
The Cart
Throughout this tutorial, we'll be setting up the cart for our e-commerce application. Currently, there are two items in the cart.
You should be able to add items, clear the cart, and complete a mock "checkout" with state being managed appropriately.
Code Overview
Let's dive in to the code.
The Layout Component
First, let's take a look at the Layout component at src/app/layout.tsx. This component is shared across all routes of the application.
The layout includes the Header, as well as the children for the given route:
At the top of the component is some functionality related to the cart.
The cart data comes from a call to getCart, and code for the clearCartAction will clear the cart. Both of these return an empty cart:
The Header Component
Next, let's examine the Header component at src/app/components/Header.tsx.
This is a client component that takes the current cart and the clearCartAction. It displays the number of items in the cart in a small circle and either shows or hides the CartPopup component:
Cart Popup Component
The CartPopup component is another client component that takes the cart and the clearCartAction that came from the by way of the .