Adding endpoint to the json file and modified in Auth login page

This commit is contained in:
surajbirewar001 2024-07-11 11:47:10 +05:30
parent d1fa80bac7
commit f7871882a1
6 changed files with 171 additions and 90 deletions

114
db.json
View File

@ -1,67 +1,71 @@
{ {
"users": [ "authlogin": [
{
"id": 1,
"email": "admin@gmail.com",
"password": "123",
"role": "admin"
},
{
"id": 2,
"email": "employee@gmail.com",
"password": "123",
"role": "employee"
}
],
"health-check": {
"status": "OK"
},
"admin": [
{ {
"id": 1, "id": 1,
"email": "employee@example.com", "name": "Admin User",
"password": "password123", "email": "adminuser@example.com"
"role": "employee" }
],
"employee": [
{
"id": 1,
"name": "Employee User",
"email": "employeeuser@example.com"
}
],
"products": [
{
"id": 1,
"name": "Product 1",
"category": "Category 1",
"price": 100
}, },
{ {
"id": 2, "id": 2,
"email": "admin@example.com", "name": "Product 2",
"password": "admin123", "category": "Category 2",
"role": "admin" "price": 200
}
],
"categories": [
{
"id": 1,
"name": "Category 1"
}, },
{ {
"email": "employee@example.com", "id": 2,
"password": "password123", "name": "Category 2"
"id": 3, }
"role": "employee" ],
"customers": [
{
"id": 1,
"name": "Customer 1",
"email": "customer1@example.com",
"phone": "1234567890"
}, },
{ {
"id": 4, "id": 2,
"email": "suraj@gmail.com", "name": "Customer 2",
"password": "pass", "email": "customer2@example.com",
"role": "employee" "phone": "0987654321"
},
{
"id": 5
},
{
"id": 6
},
{
"id": 7
},
{
"id": 8
},
{
"id": 9
},
{
"id": 10
},
{
"id": 11,
"email": "urhtuhreiuuryuihd@gmail.com",
"password": "password12",
"role": "employee"
},
{
"id": 12
},
{
"id": 13
},
{
"id": 14
},
{
"id": 15
},
{
"id": 16
} }
] ]
} }

View File

@ -9,6 +9,8 @@ import AddCustomer from './components/customer/AddCustomer';
import Sidebar from './components/sidebar/Sidebar'; import Sidebar from './components/sidebar/Sidebar';
import CustomerMeasurements from './components/customer/CustomerMeasurements'; import CustomerMeasurements from './components/customer/CustomerMeasurements';
import { AuthProvider, AuthContext } from './contexts/AuthContext'; import { AuthProvider, AuthContext } from './contexts/AuthContext';
const { Content } = Layout; const { Content } = Layout;

View File

@ -1,5 +1,3 @@
// src/api/axiosConfig.js
import axios from 'axios'; import axios from 'axios';
const axiosInstance = axios.create({ const axiosInstance = axios.create({

View File

@ -14,7 +14,7 @@ const LoginPage = () => {
setError(''); setError('');
try { try {
const response = await axiosInstance.get('http://localhost:5000/users'); const response = await axiosInstance.get('http://localhost:5000/authlogin');
const user = response.data.find(user => user.email === email && user.password === password); const user = response.data.find(user => user.email === email && user.password === password);

View File

@ -1,13 +1,44 @@
import React from 'react'; import React, { useState } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import axiosInstance from '../../api/axiosConfig';
import Sidebar from '../sidebar/Sidebar'; import Sidebar from '../sidebar/Sidebar';
const AddCustomer = () => { const AddCustomer = () => {
const [customerData, setCustomerData] = useState({
name: '',
age: '',
gender: '',
email: '',
address: '',
mobileNo: ''
});
const handleChange = (e) => {
const { name, value } = e.target;
setCustomerData({
...customerData,
[name]: value
});
};
const handleSubmit = async (e) => {
e.preventDefault();
try {
const response = await axiosInstance.post('/api/customers', customerData);
console.log('Customer data saved:', response.data);
} catch (error) {
console.error('Error saving customer data:', error);
}
};
return ( return (
<div className="flex flex-row"> <div className="flex flex-row">
<Sidebar /> <Sidebar />
<div className="w-full flex flex-col min-h-screen text-white"> <div className="w-full flex flex-col min-h-screen text-white">
<div className="min-h-screen text-gray-300 p-6"> <div className="min-h-screen text-gray-300 p-6">
<div className="flex justify-between items-center mb-6"> <div className="flex justify-between items-center mb-6">
<h1 className="text-2xl font-semibold text-orange-500">Add Customer</h1> <h1 className="text-2xl font-semibold text-orange-500">Add Customer</h1>
<Link to="/" className="text-orange-500">skip for now</Link> <Link to="/" className="text-orange-500">skip for now</Link>
@ -34,35 +65,80 @@ const AddCustomer = () => {
</div> </div>
{/* Form */} {/* Form */}
<div className="md:col-span-2 space-y-4"> <div className="md:col-span-2 space-y-4">
<div> <form onSubmit={handleSubmit}>
<label className="block text-sm font-medium text-black-700">Customer Name :</label> <div>
<input type="text" className="input-underline" /> <label className="block text-sm font-medium text-black-700">Customer Name :</label>
</div> <input
<div> type="text"
<label className="block text-sm font-medium text-black-700">Age :</label> name="name"
<input type="number" className="input-underline" /> value={customerData.name}
</div> onChange={handleChange}
<div> className="input-underline"
<label className="block text-sm font-medium text-black-700">Gender :</label> required
<input type="text" className="input-underline" /> />
</div> </div>
<div> <div>
<label className="block text-sm font-medium text-black-700">Email :</label> <label className="block text-sm font-medium text-black-700">Age :</label>
<input type="email" className="input-underline" /> <input
</div> type="number"
<div> name="age"
<label className="block text-sm font-medium text-black-700">Address :</label> value={customerData.age}
<input type="text" className="input-underline" /> onChange={handleChange}
</div> className="input-underline"
<div> required
<label className="block text-sm font-medium text-black-700">Mobile No :</label> />
<input type="text" className="input-underline" /> </div>
</div> <div>
<div className="text-center"> <label className="block text-sm font-medium text-black-700">Gender :</label>
<button className="bg-orange-500 text-black px-4 py-2 rounded-md font-semibold text-sm"> <input
Save Information type="text"
</button> name="gender"
</div> value={customerData.gender}
onChange={handleChange}
className="input-underline"
required
/>
</div>
<div>
<label className="block text-sm font-medium text-black-700">Email :</label>
<input
type="email"
name="email"
value={customerData.email}
onChange={handleChange}
className="input-underline"
required
/>
</div>
<div>
<label className="block text-sm font-medium text-black-700">Address :</label>
<input
type="text"
name="address"
value={customerData.address}
onChange={handleChange}
className="input-underline"
required
/>
</div>
<div>
<label className="block text-sm font-medium text-black-700">Mobile No :</label>
<input
type="text"
name="mobileNo"
value={customerData.mobileNo}
onChange={handleChange}
className="input-underline"
required
/>
</div> <br/>
<div className="text-center">
<button type="submit" className="bg-orange-500 text-black px-4 py-2 rounded-md font-semibold text-sm">
Save Information
</button>
</div>
</form>
</div> </div>
</div> </div>
</div> </div>

View File

@ -4,6 +4,7 @@ import App from './App';
import 'antd/dist/reset.css'; import 'antd/dist/reset.css';
import './index.css'; import './index.css';
ReactDOM.createRoot(document.getElementById('root')).render( ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode> <React.StrictMode>
<App /> <App />