Skip to content

binhlethanh201/Product-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Product Management System

This repository contains a comprehensive React.js Product Management System designed to help developers master modern frontend development, React.js framework, API integration, and full-stack web application architecture. The project features a complete product management system with authentication, CRUD operations, responsive design, and modern web development practices. It serves as a complete learning platform for understanding React.js development from basics to advanced concepts.

Prerequisites

  • Node.js (version 14 or higher) and npm installed on your system
  • A modern web browser (Chrome, Firefox, Edge, Safari, etc.)
  • (Optional) A code editor like VS Code, Sublime Text, or Atom for easier code navigation
  • Basic understanding of JavaScript, HTML, CSS, and web development concepts
  • Knowledge of React.js fundamentals (components, hooks, state management)

Installation

  1. Clone the repository (if not already downloaded):

    git clone <repository-url>
    cd Product-Management-main
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm start

How to Run

Development Mode

  1. Start the application:

    npm start

    This will start the development server with hot reloading at http://localhost:3000.

  2. Build for production:

    npm run build
  3. Run tests:

    npm test

Production Mode

  1. Build the application:

    npm run build
  2. Serve the production build:

    npx serve -s build

Note: The application uses React Scripts for development, which automatically starts the development server with hot reloading when you make changes to the source code.

Project Structure

Product-Management-main/
├── public/
│   ├── favicon.ico
│   ├── index.html
│   ├── logo192.png
│   ├── logo512.png
│   ├── manifest.json
│   └── robots.txt
├── src/
│   ├── components/
│   │   ├── addProduct.jsx
│   │   ├── detail.jsx
│   │   ├── login.jsx
│   │   ├── product.jsx
│   │   └── updateProduct.jsx
│   ├── App.js
│   └── index.js
├── package-lock.json
├── package.json
└── README.md
  • public/: Static assets served directly to the browser
    • index.html: Main HTML template
    • favicon.ico: Website favicon
    • logo192.png & logo512.png: Application logos
    • manifest.json: Web app manifest for PWA features
    • robots.txt: Search engine crawling instructions
  • src/components/: React components organized by feature
    • login.jsx: Authentication component with form handling
    • product.jsx: Product listing component with grid layout
    • detail.jsx: Product detail view component
    • addProduct.jsx: Product creation form component
    • updateProduct.jsx: Product editing form component
  • src/App.js: Main application component with routing and state management
  • src/index.js: Application entry point and React rendering

Features

  • React.js Framework: Modern JavaScript library for building user interfaces
  • Component-Based Architecture: Reusable UI components with props and state
  • React Router: Client-side routing for single-page application
  • Authentication System: Login functionality with token-based authentication
  • API Integration: RESTful API calls using Axios and Fetch API
  • CRUD Operations: Complete Create, Read, Update, Delete functionality
  • Responsive Design: Bootstrap integration for mobile-friendly UI
  • State Management: React hooks for local state management
  • Local Storage: Persistent authentication state
  • Modern JavaScript: ES6+ features and async/await patterns
  • Hot Reloading: Automatic browser refresh during development
  • Form Handling: Controlled components with validation
  • Error Handling: Try-catch blocks and error states
  • Loading States: Conditional rendering based on data availability

Learning Modules

React.js Fundamentals (src/App.js)

This module covers the core React.js concepts:

  • Component Structure: Functional components with hooks
  • State Management: useState hook for local state
  • Effect Management: useEffect hook for side effects
  • Routing: React Router setup and navigation
  • Authentication Flow: Token-based login/logout system
  • Local Storage: Browser storage for persistent data

Component Architecture (src/components/)

This module demonstrates component-based development:

Authentication Component (login.jsx)

  • Form Handling: Controlled input components
  • API Integration: Axios for authentication requests
  • Error Handling: User feedback for login failures
  • Navigation: Programmatic routing with useNavigate
  • Token Management: JWT token storage and retrieval

Product Management Components

  • Product Listing (product.jsx): Grid layout with product cards
  • Product Detail (detail.jsx): Individual product information
  • Product Creation (addProduct.jsx): Add new products form
  • Product Update (updateProduct.jsx): Edit existing products

API Integration

This module covers external API communication:

  • RESTful APIs: Integration with DummyJSON API
  • HTTP Methods: GET, POST, PUT, DELETE requests
  • Authentication Headers: Bearer token implementation
  • Error Handling: Network error management
  • Data Transformation: API response processing

Routing System

This module covers React Router implementation:

  • Route Configuration: Path-based component rendering
  • Dynamic Routes: URL parameters for product IDs
  • Navigation: Link components and programmatic routing
  • Route Protection: Authentication-based access control
  • Nested Routes: Complex routing structures

State Management

This module covers React state patterns:

  • Local State: useState hook for component state
  • Effect Dependencies: useEffect cleanup and dependencies
  • State Updates: Immutable state updates
  • Conditional Rendering: State-based UI changes
  • Data Fetching: API calls with loading states

Frontend Development

This module covers client-side development:

  • Bootstrap Integration: Responsive design framework
  • CSS Styling: Inline styles and component styling
  • Responsive Layout: Mobile-first design approach
  • Component Styling: Card layouts and grid systems
  • User Experience: Loading states and error messages

Technologies Used

  • React.js 18.2.0: JavaScript library for building user interfaces
  • React Router DOM 6.13.0: Client-side routing for React applications
  • Axios 1.6.7: HTTP client for API requests
  • Bootstrap 5.3.3: Frontend CSS framework
  • React Bootstrap 2.10.2: Bootstrap components for React
  • React Scripts 5.0.1: Development and build tools
  • Testing Library: Jest and React Testing Library for testing
  • Web Vitals 2.1.4: Performance monitoring
  • JSON Server 0.17.3: Mock API server for development

Development Workflow

For Development

  1. Start Development Server: Run npm start for hot reloading
  2. API Integration: Use DummyJSON API for product data
  3. Authentication: Test login with provided credentials
  4. Code Changes: Files automatically reload when modified

For Production

  1. Build Assets: Compile and optimize for production
  2. Environment Setup: Configure production API endpoints
  3. Deployment: Deploy to hosting platform (Netlify, Vercel, etc.)
  4. Monitoring: Set up analytics and error tracking

Learning Path

Beginner Level

  1. Start with src/App.js to understand React component structure
  2. Explore src/components/ to learn component patterns
  3. Study authentication flow in login.jsx

Intermediate Level

  1. Implement CRUD operations in product components
  2. Add form validation and error handling
  3. Create custom hooks for reusable logic

Advanced Level

  1. Add state management with Context API or Redux
  2. Implement advanced routing with guards
  3. Add testing and deployment configurations
  4. Optimize performance with React.memo and useMemo

Best Practices Demonstrated

  • Component Composition: Reusable and maintainable components
  • Hook Usage: Proper useState and useEffect implementation
  • Error Handling: Comprehensive error catching and user feedback
  • Security: Input validation and secure authentication
  • Performance: Efficient re-rendering and data fetching
  • Code Organization: Consistent naming conventions and structure
  • Documentation: Clear code comments and README
  • Version Control: Proper Git workflow and commit messages

API Endpoints

Authentication

  • POST https://dummyjson.com/auth/login - User authentication
  • GET https://dummyjson.com/user - Get user profile (with token)

Product Management

  • GET https://dummyjson.com/products - List all products
  • GET https://dummyjson.com/products/:id - Get product details
  • POST https://dummyjson.com/products/add - Create new product
  • PUT https://dummyjson.com/products/:id - Update product
  • DELETE https://dummyjson.com/products/:id - Delete product

Application Routes

Public Routes

  • / - Login page (default route)
  • /product - Product listing page (requires authentication)

Protected Routes

  • /product/:id - Product detail page
  • /product/:id/update - Product edit page
  • /product/add - Product creation page

Authentication Flow

  1. Login Process:

    • User enters credentials on login page
    • System validates with DummyJSON API
    • JWT token stored in localStorage
    • User redirected to product listing
  2. Session Management:

    • Token checked on app initialization
    • Automatic redirect if token exists
    • Logout clears localStorage and redirects
  3. Route Protection:

    • Authentication state managed in App component
    • Conditional rendering based on login status
    • Programmatic navigation for authenticated users

Troubleshooting

  • API Connection: Ensure internet connection for DummyJSON API
  • Port Conflicts: Change port in package.json if 3000 is busy
  • Dependencies: Run npm install if modules are missing
  • Build Issues: Clear node_modules and reinstall dependencies
  • Authentication: Check browser console for token storage issues
  • Routing: Ensure React Router is properly configured
  • Console Errors: Check terminal and browser console for error messages

Contributing

This is a learning project designed for educational purposes. Feel free to:

  • Modify examples to experiment with different approaches
  • Add new features and functionality
  • Improve documentation and comments
  • Share your learning experiences
  • Report bugs and suggest improvements

Learn More

For questions or contributions, please open an issue or pull request on the GitHub repository.

License

This project is licensed under the ISC License - see the LICENSE file for details.

About

Product Management using DummyJSON with ReactJS and React-Bootstrap

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published