Skip to content

Commit

Permalink
✨ Admin Login Update
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdra committed Oct 11, 2024
1 parent 8915e3c commit 190a587
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 45 deletions.
5 changes: 5 additions & 0 deletions backend/controllers/DLOcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ const assignReadyOrders = async () => {
// Save the new dOrder
await newDOrder.save()
/*console.log(`Order with ID ${order._id} has been successfully assigned to dOrder with new orderID ${newDOrder.orderID}.`)*/

// After saving the new dOrder, update the order status to "Assigning" in the Order model
order.orderStatus = ' .Ready. '
await order.save() // Save the updated order
// console.log(`Order with ID ${order._id} has been marked as "Assigning" in the Order model.`)
}
} catch (error) {
console.error('Error assigning ready orders to dOrder:', error)
Expand Down
37 changes: 23 additions & 14 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import ViewDelivery from './Pages/delivery/driver/ViewDelivery' // Import the Vi
import ViewDeliveries from './Pages/delivery/driver/ViewDeliveries' // Import the ViewDeliveries page
import DLMap from './Pages/delivery/DLMap' // Import the DLMap component
import IncomePage from './Pages/delivery/driver/incomepage' // Import the DLList component
import StaffPrivateRoute from './Components/Admin/AstaffPrivateRoute'

// Define all routes in a single Router
const router = createBrowserRouter(
Expand Down Expand Up @@ -176,23 +177,31 @@ const router = createBrowserRouter(

{/* Admin Routes */}
<Route path="/" element={<AdminLayout />}>
<Route path="/AdminDashboard" element={<AdminDashboard />} />
<Route path="/Admin" element={<AdminLogin />} />
<Route element={<StaffPrivateRoute />}>
<Route
path="/AdminDashboard"
element={<AdminDashboard />}
/>

{/* Staff */}
<Route path="/staff" element={<Staff />} />
<Route path="/addstaff" element={<AddStaff />} />
<Route path="/UpdateStaff/:id" element={<UpdateStaff />} />
{/* Staff */}
<Route path="/staff" element={<Staff />} />
<Route path="/addstaff" element={<AddStaff />} />
<Route path="/UpdateStaff/:id" element={<UpdateStaff />} />

{/* users */}
<Route path="/users" element={<Users />} />
{/* users */}
<Route path="/users" element={<Users />} />

{/* Coupon */}
<Route path="/coupons" element={<Coupens />} />
<Route path="/addcoupons" element={<AddCoupon />} />
<Route path="/updatecoupon/:id" element={<UpdateCoupon />} />
<Route path="/coupens" element={<Coupens />} />
<Route path="/finance" element={<Finance />} />
<Route path="/adl" element={<AdminLogin />} />
{/* Coupon */}
<Route path="/coupons" element={<Coupens />} />
<Route path="/addcoupons" element={<AddCoupon />} />
<Route
path="/updatecoupon/:id"
element={<UpdateCoupon />}
/>
<Route path="/coupens" element={<Coupens />} />
<Route path="/finance" element={<Finance />} />
</Route>

{/*
<Route path="/dashboard" element={< Dashboard/>} />
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/Components/Admin/AsideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FaTags,
FaChartLine,
FaSignOutAlt,
FaTruck,
} from 'react-icons/fa'

const AdminSidebar = () => {
Expand Down Expand Up @@ -50,6 +51,15 @@ const AdminSidebar = () => {
<span>Coupons</span>
</Link>
</li>
<li>
<Link
to="/manager/dashboard"
className="flex items-center px-4 py-2 text-gray-700 hover:bg-green-500 hover:text-white rounded text-left"
>
<FaTruck className="w-5 h-5 mr-3" />
<span>Drivers</span>
</Link>
</li>
<li>
<Link
to="/finance"
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/Components/Admin/AstaffPrivateRoute.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Navigate, Outlet } from 'react-router-dom'

const StaffPrivateRoute = () => {
// Check if user is authenticated (e.g., by checking for a token in local storage)
const staff = localStorage.getItem('staffToken') // Replace with your actual logic

// Log the user state for debugging
console.log(staff)

return staff ? <Outlet /> : <Navigate to="/Admin" replace />
}

export default StaffPrivateRoute
12 changes: 6 additions & 6 deletions frontend/src/Components/Admin/admnlogins.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ const AdminLogin = () => {
{
email: 'sanjeewa@gmail.com',
password: 'sanjeewa',
navigateTo: '/manager/dashboard' // Admin 1's dashboard
},
{
email: 'admin2@example.com',
email: 'admin@farmcart.com',
password: 'password123',
navigateTo: '/manager/dashboard' // Admin 2's dashboard
},
{
email: 'admin3@example.com',
password: 'securePass',
navigateTo: '/superuser/dashboard' // Admin 3's dashboard
},
]

Expand All @@ -39,9 +36,12 @@ const AdminLogin = () => {
)

if (user) {
// If user exists, navigate to their specific dashboard
// If user exists, save token and navigate to /Admin
const token =
'd0ahfFiO0dPMd1StZ0W7fqYhxxuIJYtEDXgi6t39Pp2J2qaWyfcFT0gJKO3iT6pz' // Replace with actual token logic
localStorage.setItem('staffToken', token) // Save token in local storage
navigate('/admindashboard')
toast.success('Login successful!')
navigate(user.navigateTo)
} else {
// If no match, show error message
setError('Invalid email or password.')
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Pages/Customer/UserDashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useMemo } from 'react'

Check failure on line 1 in frontend/src/Pages/Customer/UserDashboard.jsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontend/src/Pages/Customer/UserDashboard.jsx#L1

[no-unused-vars] 'React' is defined but never used.
import { Link } from 'react-router-dom'
import OrderTable from '../../Components/UserOrderTable'
import Breadcrumbs from '../../Components/Breadcrumbs'
// import Breadcrumbs from '../../Components/Breadcrumbs'
import gold from '../../assets/premiumGold.png'
import silver from '../../assets/premiumSilver.png'
import regular from '../../assets/regular.png'
Expand Down Expand Up @@ -54,7 +54,7 @@ function Dashboard() {
return (
<div className="relative min-h-screen bg-neutral-100 pr-8 pl-8 pb-6">
{/* Main Content */}
<Breadcrumbs /> {/* Breadcrumbs at the top */}
{/* <Breadcrumbs /> Breadcrumbs at the top */}
{/* Membership Banner */}
<div className="flex w-fit items-center max-md:flex-col gap-6 bg-gradient-to-tr from-green-800 to-green-600 text-white px-6 py-3.5 mx-6 rounded font-[sans-serif] mt-4 shadow-sm">
<p className="text-base flex-1 max-md:text-center">
Expand Down
52 changes: 29 additions & 23 deletions frontend/src/Pages/delivery/DLDriverDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ const DLDriverDashboard = () => {
setIsAvailable(data.isAvailable) // Set initial availability

// Check if NIC and password are the same
const nicCheckRes = await axios.get('/api/drivers/nic-password-check', {
headers: {
Authorization: `Bearer ${driverToken}`, // Pass token in headers
},
})
const nicCheckRes = await axios.get(
'/api/drivers/nic-password-check',
{
headers: {
Authorization: `Bearer ${driverToken}`, // Pass token in headers
},
}
)
setNicMatchesPassword(nicCheckRes.data.nicMatchesPassword) // Set NIC and password equality check result

// Fetch ongoing deliveries assigned to this driver
Expand Down Expand Up @@ -153,10 +156,10 @@ const DLDriverDashboard = () => {
status === 'Ready'
? 25
: status === 'Picked Up'
? 50
: status === 'On The Way'
? 75
: 100
? 50
: status === 'On The Way'
? 75
: 100
const bgColor = progress === 100 ? 'bg-gray-400' : 'bg-green-500'

return (
Expand All @@ -183,7 +186,8 @@ const DLDriverDashboard = () => {
<div className="bg-red-500 text-white p-4 rounded-md mb-6 text-center">
<strong>Warning:</strong> Your NIC number and password
are the same. Please update your password for better
security. When you change the password, you can assign orders.
security. When you change the password, you can assign
orders.
</div>
)}

Expand Down Expand Up @@ -216,7 +220,9 @@ const DLDriverDashboard = () => {
: 'bg-red-500 hover:bg-red-600'
}`}
>
{isAvailable ? 'Available' : 'Unavailable'}
{isAvailable
? 'Available'
: 'Unavailable'}
</button>
)}
<button
Expand Down Expand Up @@ -273,12 +279,12 @@ const DLDriverDashboard = () => {
'Ready'
? 25
: delivery.deliveryStatus ===
'Picked Up'
? 50
: delivery.deliveryStatus ===
'On The Way'
? 75
: 100
'Picked Up'
? 50
: delivery.deliveryStatus ===
'On The Way'
? 75
: 100
}%`,
}}
className={`${
Expand All @@ -295,12 +301,12 @@ const DLDriverDashboard = () => {
'Ready'
? '25%'
: delivery.deliveryStatus ===
'Picked Up'
? '50%'
: delivery.deliveryStatus ===
'On The Way'
? '75%'
: '100% (Delivered)'}
'Picked Up'
? '50%'
: delivery.deliveryStatus ===
'On The Way'
? '75%'
: '100% (Delivered)'}
</div>
</div>

Expand Down

0 comments on commit 190a587

Please sign in to comment.