-
First Commit - setup
-
Add data, create HomeScreen and ProductScreen, Add SPA routing
- npm install react-router-dom
- create route for home screen
- create router for product screen
- because this is a single-page application, the entire page should not refresh each time a particular component is changed. To avoid this, replace all anchor tags with tags from react-router-dom, then replace the href= with to=
- import { useParams } from "react-router-dom"; allows to extract the slug parameter from the url, which can then be used to call a prduct page according to which was clicked, according to what its slug property is set to
-
Create a Node.js server
- cd to root folder, npm init
- update backend package.json, right after name: add type: module (allows to use ES6 import and export feature)
- add .js and .jsx extensions to all imports (as needed)
- npm install express (from backend)
- create server.js
- add a start command as node backend/server.js
- require express
- create route for / return backened is ready
- move products.js data from frontend to backend
- create route for /api/products
- return products from the /api/products route from server.js in the backend directory
- (from backend)> npm install nodemon --save-dev
- note: --save-dev enables this to be used only for development, will not get shipped with _____
- (from backend) in package.json, confirm devDependencies: {} object
- (from backend) in package.json, in "scripts", at key:value... "start": "nodemon server.js",
- ^ this will allow the backend server to run with nodemon for continual update re-rendering automatically, initialized with npm start
-
fetch products data from backend
- set proxy in package.json
- (from frontend) in package.json, beneath "name":, add "proxy": "http://localhost:5000",
- NOTE: this is the final move that connects the frontend to the backend and vice versa
- npm install axios
- from HomeScreen, define a state to save the product from backend
- use chrome dev tools > network > (refresh page) > products > {headers, preview, response}... to confirm the data is actually coming from backend
- set proxy in package.json
-
manage state with useReducer() hook
- define a reducer
- update fetch data
- get state from reducer
-
add bootstrap UI framework
- npm install bootstrap react-bootstrap react-router-bootstrap
- update App.js to reflect bootstrap component and class-style references
- replace App.js with react-bootstrap/Navbar
- surround Navbar and main contents with react-bootstrap/Container to ensure page contents align vertically
- divided screen into three sections,
- set display flex to main container, then flex 1'd the middle container to take up the remaining page space;
-
create Product and Rating components
- moved product logic into its own component
- 5-star rating system with num of reviews
- changed button color
- on HomeScreen, changed product list to bootstrap
-
Product Screen
- create product details screen
- fetch product from backend
- create three columns: image, info, action
- npm install react-helmet-async
- allows browser tab title to reflect the current page's content (and other webpage metadata)
- wrap component with , which enables children to utilize
- implemented in HomeScreen and ProductScreen
- (from backend) in server.js, added a new api to return product information based on slug
- enable ProductScreen details image to take up 100% of its container width
- create Loading and Message components
- create loading component
- use spinner component
- create message component
- (from backend) create utils.js to define getError() function to interact with server.js api error handling
- implemented LoadingBox and MessageBox components in HomeScreen and ProductScreen
- create product details screen
-
implement add-to-cart functionalituy
- create a React Context
- define a reducer
- create a Store Provider
- to save items from the cart into a global state, to be used in the navbar
- use in index.js to wrap the entire App component
- implement an 'add to cart' button with an onClick handler
- onClick, a badge in the navbar will reflect cart quantity total
-
refactor add-to-cart functionality to check 'inventory' from the backend, and prevent item duplication
-
(from backend) in data.js, add _id: key/value to each products object
- adding an id to each allows each to be unique
- note: _id, the underline makes compatible with MongoDB for future application
-
check if item exists in cart
-
check if count in stock is > count in cart request
-
Create Cart Screen
-
design layout
-
from App, add new route to= CartScreen
-
useNavigate to navigate user to CartScreen following 'add to cart' button
-
(from HomeScreen) add functionality btns.add-to-cart
- add item to cart
- if (outOfStock) button disabled
-
(from CartScreen) add functionality of buttons: -, +, remove
-
(from Store) added CART_REMOVE_ITEM case
-
(from Store) moved initial cartItems value to localStorage
-
add functionality to update localStorage of cartItems changes, prevent lost progress on refresh
-
create SignInScreen
-
add functionality: continueToCheckout -> SignInScreen
-
(from ProductScreen) implement addToCartHandler
-
Create Sign In Screen
-
design layout
-
Connect to MongoDB Database
- create atlas mongoDB database
- create project
- add database
- Shared (FREE)
- choose service, location, cluster name, create Cluster
- set up Username and Password for database
- establish where to connect from: IP Address and description
- Add my own data
- Create Database
- database name
- collection name
- Create Database
- connect database to project
- install local MongoDB database
- create .env file in backend
- constant MONGODB_URI = copy uri info from mongodb atlas site dashboard
- (from backend) npm install Mongoose (schema)
- (from backend) npm install dotenv
- add both to server.js
- connect to MongoDB database
- create atlas mongoDB database
-
Download and install MongoDB Compass Community
- connect... mongodb://localhost
- set up a new database and collection
- update the .env file
-
Seed Sample Data to new MongoDB - local
- create backend models directory
- create Product Model
- create Schema
- import mongoose to define schema
- https://mongoosejs.com/docs/index.html
- https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-Schema
- https://mongoosejs.com/docs/api/schema.html
- first: mongoose.Schema takes required first parameter object to define the schema, and an optional second parameter, which can be 'timestamp', which adds two more data: create-time and update-time
- create Model based on Schema
- create Schema
- create User Model
- "seed" or create products into the database using Express
- use route in server.js
- seed sample product
- Create User Model
- seed sample users
- create user model
- create user routes
- create sample users (admin & customer), generate encrypted passwords for each
- npm install bcryptjs
-
Create Sign-In Backend API
- create sign-in api
- npm install jsonwebtoken
- define generateToken
- install Chrome dev extension Advanced REST client
-
Complete Sign-In Screen
- handle submit action
- set user's sign-in email and password to state
- save token in store and local storage
- then redirect user according to search parameter in url
- show user name in header
- App.js > Nav
- fetch userInfo from store
- prevent user from accessing SignInScreen if already signed in
- (from frontend) npm install toastify
- use instead of alert() to show error message
- use context state.userInfo to dynamically render complication in navbar
- add two new actions to Store.js
- USER_SIGNIN
- USER_SIGNOUT
- handle submit action
major-ecommerce-clone's Introduction
major-ecommerce-clone's People
major-ecommerce-clone's Issues
ProductPage: sorry alert for not enough upon add-to-cart - unsure if not working
Homepage items not loading
homepage no longer loads the product items. All other functionalities seem to be working as normal.
NOTE:
everything worked just fine until I was cleaning up all the unused browser tabs (most asleep due to inactivity), so I refreshed to see what they were, and one ended up being a seed path. I believe when I ran that, everything was lost. Though I checked the local database (mongodb community) and the data was still there. Maybe something to do with the
FROM BACKEND TERMINAL:
upon npm start:
[email protected] start
nodemon server.js
[nodemon] 2.0.19
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node server.js
The uri
parameter to openUri()
must be a string, got "undefined". Make sure the first parameter to mongoose.connect()
or mongoose.createConnection()
is a string.
server at http://localhost:500
FROM FRONTEND TERMINAL:
webpack compiled with 1 warning
Proxy error: Could not proxy request /api/products from localhost:3000 to http://localhost:5000/.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.