Commit 8cecc4c9 by rahimie-hub

commit

parent d536cf75
# my-product-management-system
# PRODUCT-MANAGEMENT-SYSTEM
## Objective:
By the end of this session, students will be able to create class and functional components, style components using CSS, and perform CRUD operations in React using MockAPI. The project will be named "my-product-management-system" and will include pages to register categories and products.
By the end of this session, students will be able to create class and functional components, style components using CSS, and perform CRUD operations in React using Own/MockAPI. The project will be named "my-product-management-system" and will include pages to register categories and products.
## Agenda:
### 1. Introduction (30 minutes)
### 1. Introduction (10 minutes)
- Overview of React components: class components vs functional components.
- Introduction to React's component lifecycle methods.
- Brief introduction to CSS in React.
- Introduction to MockAPI for CRUD operations.
### 2. Setting Up the Project (30 minutes)
### 2. Setting Up the Project (5 minutes)
- Create a new React project using Create React App.
- Start the React development server.
- Brief overview of the project's folder structure.
\`\`\`bash
```bash
npx create-react-app my-product-management-system
cd my-product-management-system
npm start
\`\`\`
```
\`\`\`
### 3. Editing App.js (3 minutes)
- Modify \`App.js\` to include set title project / Hello World! to test this app.js page
```bash
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import CategoryFormClass from './components/Category/CategoryFormClass';
import ProductFormClass from './components/Product/ProductFormClass';
function App() {
return (
<Router>
<div className="App">
<h1>Product Management System</h1>
</div>
</Router>
);
}
export default App;
```
### 4. Setting Up the Project Folder Structure / File System (10 minutes)
- Create folder and file according to below file structure page
- Brief overview of the project's folder structure.
```bash
my-product-management-system/
├── public/
│ ├── index.html
......@@ -49,37 +76,15 @@ my-product-management-system/
│ └── ...
├── package.json
└── ...
\`\`\`
### 3. Editing App.js (15 minutes)
- Modify \`App.js\` to include a welcome message and links to the category and product registration pages.
\`\`\`jsx
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import CategoryFormClass from './components/Category/CategoryFormClass';
import ProductFormClass from './components/Product/ProductFormClass';
function App() {
return (
<Router>
<div className="App">
<h1>Product Management System</h1>
</div>
</Router>
);
}
export default App;
\`\`\`
```
### 4. Creating Class Components (60 minutes)
### 4. Creating Class Components (30 minutes)
- Deep dive into creating class components.
- Create `CategoryFormClass.js` and `CategoryListClass.js` as class components.
- Discuss state management, event handling, and lifecycle methods.
CategoryFormClass.js
```bash
\`\`\`jsx
// CategoryFormClass.js
import React, { Component } from 'react';
import { createCategory } from '../../services/ApiCategory';
......@@ -102,7 +107,7 @@ class CategoryFormClass extends Component {
};
render() {
const { name, description } = this.state;
const { name, description } = this.state
return (
<form onSubmit={this.handleSubmit}>
......@@ -127,10 +132,10 @@ class CategoryFormClass extends Component {
}
export default CategoryFormClass;
\`\`\`
```
CategoryListClass.js
```jsx
\`\`\`jsx
// CategoryListClass.js
import React, { Component } from 'react';
import CategoryFormClass from './CategoryFormClass';
import { getCategories, deleteCategory, updateCategory } from '../../services/ApiCategory';
......@@ -236,15 +241,14 @@ class CategoryListClass extends Component {
}
export default CategoryListClass;
\`\`\`
```
### 5. Creating Functional Components (60 minutes)
### 5. Creating Functional Components (30 minutes)
- Deep dive into creating functional components with hooks.
- Create `CategoryFormFunction.js` and `CategoryListFunction.js` as functional components.
- Discuss useState and useEffect hooks.
\`\`\`jsx
// CategoryFormFunction.js
CategoryFormFunction.js
```jsx
import React, { useState } from 'react';
import { createCategory } from '../../services/ApiCategory';
......@@ -288,10 +292,9 @@ const CategoryFormFunction = ({ fetchCategories }) => {
};
export default CategoryFormFunction;
\`\`\`
\`\`\`jsx
// CategoryListFunction.js
```
CategoryListFunction.js
```jsx
import React, { useEffect, useState } from 'react';
import { getCategories, deleteCategory, updateCategory } from '../../services/ApiCategory';
import './Category.css';
......@@ -406,34 +409,85 @@ const CategoryListFunction = () => {
};
export default CategoryListFunction;
\`\`\`
### 6. Lunch Break (30 minutes)
```
### 7. Adding CSS (30 minutes)
### 6. Adding CSS (15 minutes)
- Demonstrate how to add and apply CSS in React.
- Style the category and product forms.
\`\`\`css
/* Category.css */
form {
Category.css *
```css
form {
margin: 20px;
}
}
input {
input {
margin-right: 10px;
}
\`\`\`
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-size: 18px;
text-align: left;
}
th, td {
padding: 12px 15px;
border: 1px solid #ddd;
}
th {
background-color: #f4f4f4;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
tr:hover {
background-color: #f1f1f1;
}
.button {
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
}
.button-delete {
background-color: #ff4d4d;
}
.button-delete:hover {
background-color: #ff1a1a;
}
.button-update {
background-color:blue;
}
.button-update:hover {
background-color: blue;
}
```
### 7. Break (5 minutes)
### 8. Integrating MockAPI for CRUD Operations (60 minutes)
- Set up MockAPI for category and product management.
- Perform CRUD operations (Create, Read, Update, Delete) using MockAPI.
\`\`\`jsx
// ApiCategory.js
- Url Localhost / Mockapi: 'https://66b1b4381ca8ad33d4f4d9c0.mockapi.io/api/v1/category';
- Discuss Axios/ Await Fectch
ApiCategory.js
```jsx
const apiUrl = 'https://mockapi.io/endpoint';
export const getCategories = () => fetch(apiUrl).then((res) => res.json());
export const createCategory = (category) =>
fetch(apiUrl, {
method: 'POST',
......@@ -456,77 +510,56 @@ export const updateCategory = (id, category) =>
},
body: JSON.stringify(category),
}).then((res) => res.json());
\`\`\`
```
### 9. Building Pages for Category and Product Registration (60 minutes)
- Create forms for category and product registration.
### 9. Task to Create Product Page (60 minutes)
- Follow category page, task to create product registration page. Can use class / functional component
- Link forms to MockAPI for data submission.
- Url localhost / Mockapi: 'https://66b1b4381ca8ad33d4f4d9c0.mockapi.io/api/v1/product';
- Implement similar logic for \`ProductForm.js\` & \`ProductList.js\`
Example form and list structure with API integration
```jsx
import React, { Component } from 'react';
import ProductForm from './ProductForm';
import { deleteProduct, updateProduct, getProduct } from '../../services/ApiProduct';
import './Product.css';
\`\`\`jsx
// Example form structure with API integration
const handleSubmit = (event) => {
event.preventDefault();
createCategory({ name: categoryName, description }).then((data) => console.log(data));
};
return (
<form onSubmit={handleSubmit}>
<input type="text" placeholder="Enter category name" />
<button type="submit">Submit</button>
</form>
);
\`\`\`
class ProductList extends Component {
state = {
products: [],
isEditing: false,
currentProduct: { id: '', name: '', description: '', category: '' },
};
- Implement similar logic for \`ProductForm.js\`.
componentDidMount() {
}
### 10. Building Lists to Display Data (45 minutes)
- Create lists to display categories and products.
- Fetch data from MockAPI and render it in the components.
render() {
}
}
\`\`\`jsx
// CategoryListFunction.js
import React, { useEffect, useState } from 'react';
import { getCategories } from '../services/ApiCategory';
export default ProductList;
const CategoryListFunction = () => {
const [categories, setCategories] = useState([]);
```
useEffect(() => {
getCategories().then((data) => setCategories(data));
}, []);
return (
<div>
<h2>Category List</h2>
<ul>
{categories.map((category) => (
<li key={category.id}>{category.name}</li>
))}
</ul>
</div>
);
};
export default CategoryListFunction;
\`\`\`
- Implement similar logic for \`ProductList.js\`.
### 10. Routing Navigation (15 minutes)
### 11. Routing Navigation (15 minutes)
- Discus how React Rauter works
- Modify \`App.js\` to include a welcome message and links to the category and product registration pages.
#### Step-by-Step Instructions:
1. **Install React Router:**
- Step-by-Step Instructions:
- **Install React Router:**
- Run the following command to install React Router:
\`\`\`bash
```bash
npm install react-router-dom
\`\`\`
```
2. **Modify App.js:**
- **Modify App.js:**
- Replace the content of \`App.js\` with the following code:
\`\`\`jsx
```jsx
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import logo from './logo.svg';
......@@ -558,68 +591,46 @@ export default CategoryListFunction;
}
export default App;
\`\`\`
### 13. Design Content Navigation (15 minutes)
- Modify \`App.js\` to include a welcome message and links to the category and product registration pages.
```
#### Step-by-Step Instructions:
1. **Modify App.js:**
- Replace the content of \`App.js\` with the following code:
\`\`\`jsx
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import logo from './logo.svg';
import './App.css';
import CategoryListClass from './components/Category/CategoryListClass';
import CategoryFormClass from './components/Category/CategoryFormClass';
import CategoryListFunction from './components/Category/CategoryListFunction';
function App() {
return (
<Router>
<div className="App">
<h1>Product Management System</h1>
<div className="container">
<nav className="sidebar">
<ul>
<li>
<Link to="/category">Register Category</Link>
</li>
<li>
<Link to="/product">Register Product</Link>
</li>
</ul>
</nav>
<div className="content">
<Routes>
<Route path="/category" element={<CategoryListClass />} />
<Route path="/product" element={<CategoryListFunction />} />
</Routes>
</div>
</div>
</div>
</Router>
);
### 11. Design Content Navigation (15 minutes)
- Modify \`App.js\` to design topbar,sidebar and contentregistration pages.
- Step-by-Step Instructions:
- **Modify App.js:**
- Replace code to App.js:
```jsx
.App {
font-family: sans-serif;
text-align: center;
display: flex;
flex-direction: column;
height: 100vh;
}
export default App;
\`\`\`
```
2. **Modify App.css:**
- Update to add the content of \`App.css\` with the following code:
\`\`\`css
- **Modify App.css:**
- Add the content of \`App.css\` with the following code:
```css
.App {
font-family: sans-serif;
text-align: center;
display: flex;
flex-direction: column;
height: 100vh;
}
.topbar {
background-color: #f8f9fa;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
padding: 20px;
}
.container {
display: flex;
height: 100vh;
flex-grow: 1;
}
.sidebar {
......@@ -627,6 +638,7 @@ export default CategoryListFunction;
background-color: #f8f9fa;
padding: 15px;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
text-align: left;
}
.sidebar ul {
......@@ -646,14 +658,10 @@ export default CategoryListFunction;
.content {
flex-grow: 1;
padding: 20px;
}
h1 {
margin: 20px;
padding: 40px;
}
\`\`\`
```
## Conclusion (15 minutes)
......@@ -666,13 +674,44 @@ export default CategoryListFunction;
- [MockAPI Documentation](https://mockapi.io/docs)
- [CSS Tricks](https://css-tricks.com/)
- [React Router Documentation](https://reactrouter.com/web/guides/quick-start)
- [Redux Documentation](https://redux.js.org/)
### Advanced Topics
- Discuss state management with Context API.
- 3rd-Party libary like axios,sweertalert,formik,bootstrap/tailwind
- Implementing more complex forms and validation.
- Error handling and debugging tips.
This comprehensive 5-hour training module ensures that students gain an in-depth understanding of React components, styling, and CRUD operations, with ample time for hands-on practice and advanced topics.
## Prerequisite Topics
- [Explore project files and folders](https://reactjs.org/docs/getting-started.html)
- [Write basic JSX elements](https://reactjs.org/docs/introducing-jsx.html)
- [Practice embedding expressions and adding attributes](https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx)
- [Create functional and class components](https://reactjs.org/docs/components-and-props.html)
- [Pass data via props and set default props](https://reactjs.org/docs/components-and-props.html#props-are-read-only)
- [State and Lifecycle](https://reactjs.org/docs/state-and-lifecycle.html)
- [Explore basic lifecycle methods in class components](https://reactjs.org/docs/state-and-lifecycle.html#adding-lifecycle-methods-to-a-class)
- [Use useState to manage state in functional components](https://reactjs.org/docs/hooks-state.html)
- [Event Handling](https://reactjs.org/docs/handling-events.html)
- [Handle button clicks and form submissions](https://reactjs.org/docs/handling-events.html#passing-arguments-to-event-handlers)
- [Practice passing arguments to event handlers](https://reactjs.org/docs/handling-events.html#passing-arguments-to-event-handlers)
- [Implement conditional rendering in components](https://reactjs.org/docs/conditional-rendering.html)
- [Render a list of tasks and add keys to list items](https://reactjs.org/docs/lists-and-keys.html)
- [Create a form to add new tasks](https://reactjs.org/docs/forms.html)
- [Manage form input state](https://reactjs.org/docs/forms.html#controlled-components)
- [Style components using CSS classes and inline styles](https://reactjs.org/docs/faq-styling.html)
## Advanced Topics
- [Building and Using Reusable Component Libraries (axios, sweetalert, formik, bootstrap/tailwind)](https://reactjs.org/docs/reusable-components.html)
- [Forms and Validation / Error handling](https://reactjs.org/docs/forms.html#controlled-components)
- [Complex Forms and Validation](https://formik.org/)
- [Higher-Order Components (HOCs)](https://reactjs.org/docs/higher-order-components.html)
- [Context API](https://reactjs.org/docs/context.html)
- [Advanced State Management](https://redux.js.org/)
- [Get Started with Skeleton Project](https://reactjs.org/docs/getting-started.html)
- [Side Effects and Data Fetching](https://reactjs.org/docs/hooks-effect.html)
- [Performance Optimization (React.memo, React.PureComponent, Code Splitting, and Lazy Loading)](https://reactjs.org/docs/optimizing-performance.html)
- [Advanced Performance Optimization](https://reactjs.org/docs/optimizing-performance.html#profiling-components-with-the-chrome-performance-tab)
- [GraphQL](https://graphql.org/)
- [Server-Side Rendering (SSR) with Next.js](https://nextjs.org/docs)
- [Animation in React](https://reactcommunity.org/react-transition-group/)
This comprehensive 4-hour training module ensures that students gain an in-depth understanding of React components, styling, and CRUD operations, with ample time for hands-on practice and advanced topics.
form {
margin: 20px;
}
input {
margin-right: 10px;
}
table {
width: 100%;
border-collapse: collapse;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment