fix update status plate user
This commit is contained in:
@@ -24,11 +24,13 @@ function UserDashboard({ token, username }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Real-time status updates
|
// Real-time status updates
|
||||||
|
socket.on('new_plate_registered', () => fetchPlates()); // Sync when plate added
|
||||||
socket.on('plate_status_updated', () => fetchPlates());
|
socket.on('plate_status_updated', () => fetchPlates());
|
||||||
socket.on('people_updated', () => fetchPeople());
|
socket.on('people_updated', () => fetchPeople());
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.off('new_detection');
|
socket.off('new_detection');
|
||||||
|
socket.off('new_plate_registered');
|
||||||
socket.off('plate_status_updated');
|
socket.off('plate_status_updated');
|
||||||
socket.off('people_updated');
|
socket.off('people_updated');
|
||||||
};
|
};
|
||||||
@@ -39,10 +41,8 @@ function UserDashboard({ token, username }) {
|
|||||||
const res = await axios.get(`${API_URL}/api/plates`, {
|
const res = await axios.get(`${API_URL}/api/plates`, {
|
||||||
headers: { Authorization: `Bearer ${token}` }
|
headers: { Authorization: `Bearer ${token}` }
|
||||||
});
|
});
|
||||||
// Filter plates added by this user (if backend doesn't filter, we filter here)
|
// Backend already filters by user, so use data directly
|
||||||
// Note: Backend currently returns ALL plates. We can filter on client for now.
|
setPlates(res.data);
|
||||||
const myPlates = res.data.filter(p => p.addedBy?.username === username);
|
|
||||||
setPlates(myPlates);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ function UserDashboard({ token, username }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<span className={`px-2 py-1 rounded text-xs font-bold ${p.status === 'APPROVED' ? 'bg-green-900 text-green-300' :
|
<span className={`px-2 py-1 rounded text-xs font-bold ${p.status === 'APPROVED' ? 'bg-green-900 text-green-300' :
|
||||||
p.status === 'DENIED' ? 'bg-red-900 text-red-300' : 'bg-yellow-900 text-yellow-300'
|
p.status === 'DENIED' ? 'bg-red-900 text-red-300' : 'bg-yellow-900 text-yellow-300'
|
||||||
}`}>
|
}`}>
|
||||||
{p.status}
|
{p.status}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user