Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit c37dcc8

Browse files
committed
fix admin dashboard
1 parent dbfc5ac commit c37dcc8

5 files changed

Lines changed: 165 additions & 44 deletions

File tree

client/src/views/dashboard/ShipmentInfo/ShipmentInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ShipmentInfo = ({ data }) => {
1010
const [showDetails, setShowDetails] = useState(false)
1111

1212
useEffect(() => {
13-
const socket = io('http://localhost:3000')
13+
const socket = io('https://core2.axleshift.com/')
1414

1515
socket.emit('joinRoom', data.trackingNumber)
1616

client/src/views/driver/drivermanagement.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DriverManagement = () => {
2121
useEffect(() => {
2222
const fetchShipments = async () => {
2323
try {
24-
const res = await fetch('http://localhost:5052/driver/shipments')
24+
const res = await fetch('/driver/shipments')
2525
const data = await res.json()
2626
setShipments(data)
2727
} catch (error) {
@@ -33,7 +33,7 @@ const DriverManagement = () => {
3333

3434
fetchShipments()
3535

36-
const socket = io('http://localhost:5052')
36+
const socket = io('https://backend-core2.axleshift.com/')
3737

3838
// Listen for shipment location updates
3939
socket.on('shipmentLocationUpdate', (data) => {

client/src/views/pages/admin/AdminDashboard.js

Lines changed: 130 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,141 @@
1-
import React, { useState } from 'react'
2-
import { CButton, CButtonGroup, CCard, CCardBody, CCol, CRow } from '@coreui/react'
3-
import CIcon from '@coreui/icons-react'
4-
import { cilCloudDownload } from '@coreui/icons'
5-
import WidgetsDropdown from '../../widgets/WidgetsDropdown'
6-
import MainChart from '../../dashboard/MainChart'
1+
import React, { useEffect, useState } from 'react'
2+
import axios from '../../../api/axios'
3+
import {
4+
CRow,
5+
CCol,
6+
CCard,
7+
CCardBody,
8+
CCardHeader,
9+
CWidgetStatsA,
10+
CSpinner,
11+
CAlert,
12+
} from '@coreui/react'
13+
import { CChartBar, CChartDoughnut } from '@coreui/react-chartjs'
714

815
const AdminDashboard = () => {
9-
const [activeFilter, setActiveFilter] = useState('Month')
16+
const [shipments, setShipments] = useState([])
17+
const [loading, setLoading] = useState(true)
18+
const [error, setError] = useState(null)
19+
20+
useEffect(() => {
21+
const fetchShipments = async () => {
22+
try {
23+
const res = await axios.get('/api/shipments')
24+
const data = Array.isArray(res.data) ? res.data : []
25+
setShipments(data)
26+
} catch (err) {
27+
console.error(err)
28+
setError('Failed to load shipments.')
29+
} finally {
30+
setLoading(false)
31+
}
32+
}
33+
34+
fetchShipments()
35+
}, [])
36+
37+
const total = shipments.length
38+
const packageReceived = shipments.filter((s) => s.status === 'Package Received').length
39+
const outForDelivery = shipments.filter((s) => s.status === 'Out for Delivery').length
40+
const pendingPickup = shipments.filter((s) =>
41+
s.events?.some((e) => e.status === 'Pending for Pickup'),
42+
).length
43+
44+
const deliveryDates = shipments.map((s) => new Date(s.expected_delivery).toLocaleDateString())
1045

1146
return (
1247
<>
13-
{/* Widgets Section */}
14-
<WidgetsDropdown className="mb-4" />
15-
16-
{/* Shipment Statistics Card */}
17-
<CCard className="mb-4 shadow-sm">
18-
<CCardBody>
19-
<CRow className="align-items-center">
20-
<CCol sm={6}>
21-
<h4 id="traffic" className="card-title mb-1">
22-
Current Shipment
23-
</h4>
24-
<div className="small text-muted">Updated just now</div>
48+
{loading && <CSpinner color="primary" />}
49+
{error && <CAlert color="danger">{error}</CAlert>}
50+
51+
{!loading && !error && (
52+
<>
53+
<CRow className="mb-4">
54+
<CCol sm={6} lg={3}>
55+
<CWidgetStatsA
56+
className="mb-3"
57+
color="primary"
58+
value={total}
59+
title="Total Shipments"
60+
/>
61+
</CCol>
62+
<CCol sm={6} lg={3}>
63+
<CWidgetStatsA
64+
className="mb-3"
65+
color="info"
66+
value={packageReceived}
67+
title="Package Received"
68+
/>
2569
</CCol>
26-
<CCol sm={6} className="d-flex justify-content-end">
27-
<CButton color="primary" className="me-3">
28-
<CIcon icon={cilCloudDownload} className="me-2" />
29-
Export
30-
</CButton>
31-
<CButtonGroup>
32-
{['Day', 'Month', 'Year'].map((value) => (
33-
<CButton
34-
key={value}
35-
color={activeFilter === value ? 'primary' : 'outline-secondary'}
36-
onClick={() => setActiveFilter(value)}
37-
>
38-
{value}
39-
</CButton>
40-
))}
41-
</CButtonGroup>
70+
<CCol sm={6} lg={3}>
71+
<CWidgetStatsA
72+
className="mb-3"
73+
color="warning"
74+
value={outForDelivery}
75+
title="Out for Delivery"
76+
/>
77+
</CCol>
78+
<CCol sm={6} lg={3}>
79+
<CWidgetStatsA
80+
className="mb-3"
81+
color="danger"
82+
value={pendingPickup}
83+
title="Pending Pickup"
84+
/>
85+
</CCol>
86+
</CRow>
87+
88+
<CRow>
89+
<CCol md={6}>
90+
<CCard className="mb-4">
91+
<CCardHeader>Shipment Distribution</CCardHeader>
92+
<CCardBody>
93+
<CChartDoughnut
94+
data={{
95+
labels: ['Package Received', 'Out for Delivery', 'Pending Pickup'],
96+
datasets: [
97+
{
98+
backgroundColor: ['#0d6efd', '#ffc107', '#dc3545'],
99+
data: [packageReceived, outForDelivery, pendingPickup],
100+
},
101+
],
102+
}}
103+
/>
104+
</CCardBody>
105+
</CCard>
106+
</CCol>
107+
108+
<CCol md={6}>
109+
<CCard className="mb-4">
110+
<CCardHeader>Expected Deliveries</CCardHeader>
111+
<CCardBody>
112+
<CChartBar
113+
data={{
114+
labels: [...new Set(deliveryDates)],
115+
datasets: [
116+
{
117+
label: 'Shipments',
118+
backgroundColor: '#6610f2',
119+
data: Object.values(
120+
deliveryDates.reduce((acc, date) => {
121+
acc[date] = (acc[date] || 0) + 1
122+
return acc
123+
}, {}),
124+
),
125+
},
126+
],
127+
}}
128+
options={{
129+
plugins: { legend: { display: false } },
130+
scales: { y: { beginAtZero: true } },
131+
}}
132+
/>
133+
</CCardBody>
134+
</CCard>
42135
</CCol>
43136
</CRow>
44-
<MainChart filter={activeFilter} />
45-
</CCardBody>
46-
</CCard>
137+
</>
138+
)}
47139
</>
48140
)
49141
}

server/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const { updateShipmentStatus } = require('./utils/statusUpdate');
1313
const admin = require("firebase-admin");
1414
const rateLimit = require('express-rate-limit');
1515
const serviceAccount = require("./firebase-service-account.json");
16+
const shipmentsRoutes = require('./routes/shipments');
1617
const User = require('./models/User');
1718
const Driver = require('./models/Driver');
1819
const TrackData = require('./models/TrackData');
@@ -22,7 +23,7 @@ const app = express();
2223
const server = http.createServer(app);
2324
const io = socketIo (server,{
2425
cors: {
25-
origin: 'http://localhost:3000',
26+
origin: 'https://core2.axleshift.com/',
2627
methods: ["GET", "POST"],
2728
},
2829
});
@@ -34,12 +35,12 @@ if (!admin.apps.length) {
3435
});
3536
}
3637
app.use(cors({
37-
origin: ['http://localhost:3000'],
38+
origin: ['https://core2.axleshift.com/'],
3839
methods: ['GET', 'POST'],
3940
credentials: true
4041
}));
4142
app.use(express.json());
42-
43+
app.use('/api/shipments', shipmentsRoutes);
4344
// MongoDB Connection
4445
const mongoURI = process.env.mongoURIProduction;
4546
mongoose.connect(mongoURI)

server/routes/shipments.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const Shipment = require('../models/TrackData'); // your existing schema!
4+
5+
// Get all shipments
6+
router.get('/', async (req, res) => {
7+
try {
8+
const shipments = await Shipment.find();
9+
res.json(shipments);
10+
} catch (error) {
11+
console.error(error);
12+
res.status(500).send('Server error');
13+
}
14+
});
15+
16+
// Optionally: Get single shipment by tracking number
17+
router.get('/:trackingNumber', async (req, res) => {
18+
try {
19+
const shipment = await Shipment.findOne({ trackingNumber: req.params.trackingNumber });
20+
if (!shipment) return res.status(404).send('Shipment not found');
21+
res.json(shipment);
22+
} catch (error) {
23+
console.error(error);
24+
res.status(500).send('Server error');
25+
}
26+
});
27+
28+
module.exports = router;

0 commit comments

Comments
 (0)