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,
"email": "employee@example.com",
"password": "password123",
"role": "employee"
"name": "Admin User",
"email": "adminuser@example.com"
}
],
"employee": [
{
"id": 1,
"name": "Employee User",
"email": "employeeuser@example.com"
}
],
"products": [
{
"id": 1,
"name": "Product 1",
"category": "Category 1",
"price": 100
},
{
"id": 2,
"email": "admin@example.com",
"password": "admin123",
"role": "admin"
"name": "Product 2",
"category": "Category 2",
"price": 200
}
],
"categories": [
{
"id": 1,
"name": "Category 1"
},
{
"email": "employee@example.com",
"password": "password123",
"id": 3,
"role": "employee"
"id": 2,
"name": "Category 2"
}
],
"customers": [
{
"id": 1,
"name": "Customer 1",
"email": "customer1@example.com",
"phone": "1234567890"
},
{
"id": 4,
"email": "suraj@gmail.com",
"password": "pass",
"role": "employee"
},
{
"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
"id": 2,
"name": "Customer 2",
"email": "customer2@example.com",
"phone": "0987654321"
}
]
}
}

View File

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

View File

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

View File

@ -14,7 +14,7 @@ const LoginPage = () => {
setError('');
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);

View File

@ -1,13 +1,44 @@
import React from 'react';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import axiosInstance from '../../api/axiosConfig';
import Sidebar from '../sidebar/Sidebar';
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 (
<div className="flex flex-row">
<Sidebar />
<div className="w-full flex flex-col min-h-screen text-white">
<div className="min-h-screen text-gray-300 p-6">
<div className="w-full flex flex-col min-h-screen text-white">
<div className="min-h-screen text-gray-300 p-6">
<div className="flex justify-between items-center mb-6">
<h1 className="text-2xl font-semibold text-orange-500">Add Customer</h1>
<Link to="/" className="text-orange-500">skip for now</Link>
@ -34,35 +65,80 @@ const AddCustomer = () => {
</div>
{/* Form */}
<div className="md:col-span-2 space-y-4">
<div>
<label className="block text-sm font-medium text-black-700">Customer Name :</label>
<input type="text" className="input-underline" />
</div>
<div>
<label className="block text-sm font-medium text-black-700">Age :</label>
<input type="number" className="input-underline" />
</div>
<div>
<label className="block text-sm font-medium text-black-700">Gender :</label>
<input type="text" className="input-underline" />
</div>
<div>
<label className="block text-sm font-medium text-black-700">Email :</label>
<input type="email" className="input-underline" />
</div>
<div>
<label className="block text-sm font-medium text-black-700">Address :</label>
<input type="text" className="input-underline" />
</div>
<div>
<label className="block text-sm font-medium text-black-700">Mobile No :</label>
<input type="text" className="input-underline" />
</div>
<div className="text-center">
<button className="bg-orange-500 text-black px-4 py-2 rounded-md font-semibold text-sm">
Save Information
</button>
</div>
<form onSubmit={handleSubmit}>
<div>
<label className="block text-sm font-medium text-black-700">Customer Name :</label>
<input
type="text"
name="name"
value={customerData.name}
onChange={handleChange}
className="input-underline"
required
/>
</div>
<div>
<label className="block text-sm font-medium text-black-700">Age :</label>
<input
type="number"
name="age"
value={customerData.age}
onChange={handleChange}
className="input-underline"
required
/>
</div>
<div>
<label className="block text-sm font-medium text-black-700">Gender :</label>
<input
type="text"
name="gender"
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>

View File

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