import { useState, useMemo, Fragment } from 'react'; import { useNavigate } from 'react-router-dom'; import { Grid, Card, Stack, Button, TextField, MenuItem, InputAdornment, Box, Tabs, Tab, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, IconButton, Tooltip, TablePagination, Typography, Chip, Collapse } from '@mui/material'; import SearchIcon from '@mui/icons-material/Search'; import AddIcon from '@mui/icons-material/Add'; import EditOutlinedIcon from '@mui/icons-material/EditOutlined'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'; import GroupsOutlinedIcon from '@mui/icons-material/GroupsOutlined'; import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; import TwoWheelerOutlinedIcon from '@mui/icons-material/TwoWheelerOutlined'; import PowerSettingsNewOutlinedIcon from '@mui/icons-material/PowerSettingsNewOutlined'; import PageHeader from '@/components/PageHeader'; import StatCard from '@/components/StatCard'; import StatusChip from '@/components/StatusChip'; import UserAvatar from '@/components/UserAvatar'; import TabLabelCount from '@/components/TabLabelCount'; import { riders, riderLogs, locations } from '@/data/mock'; import { inr } from '@/utils/format'; const TABS = [ { key: 'all', label: 'ALL' }, { key: 'active', label: 'Active' } ]; export default function Riders() { const navigate = useNavigate(); const [tab, setTab] = useState(0); const [search, setSearch] = useState(''); const [location, setLocation] = useState('all'); const [page, setPage] = useState(0); const [rpp, setRpp] = useState(5); const [expanded, setExpanded] = useState(null); const tabKey = TABS[tab].key; const filtered = useMemo( () => riders.filter((r) => { const matchTab = tabKey === 'all' ? true : r.status !== 'offline'; const matchLocation = location === 'all' || r.address.includes(location); const matchSearch = !search || [r.id, r.userId, r.name, r.phone, r.address, r.vehicle, r.vehicleNo] .join(' ') .toLowerCase() .includes(search.toLowerCase()); return matchTab && matchLocation && matchSearch; }), [tabKey, location, search] ); const paged = filtered.slice(page * rpp, page * rpp + rpp); const counts = { total: riders.length, active: riders.filter((r) => r.status === 'online').length, onDelivery: riders.filter((r) => r.status === 'on-delivery').length, offline: riders.filter((r) => r.status === 'offline').length, all: riders.length, activeTab: riders.filter((r) => r.status !== 'offline').length }; return ( <> setLocation(e.target.value)} sx={{ minWidth: 170 }} label="Location"> All Locations {locations.map((l) => {l})} } /> { setSearch(e.target.value); setPage(0); }} sx={{ minWidth: 240 }} InputProps={{ startAdornment: }} /> { setTab(v); setPage(0); }}> {TABS.map((t, i) => ( } /> ))} S.NO User ID Rider Address Vehicle Shift Time Fare Fuel Status Action {paged.map((r, i) => ( {page * rpp + i + 1} {r.userId} {r.name} {r.phone} {r.address} {r.vehicle} {r.vehicleNo} {r.shift} {inr(r.fare)} {inr(r.fuel)} navigate(`/riders/${r.id}/edit`)}> setExpanded(expanded === r.id ? null : r.id)}> {expanded === r.id ? : } Rider Logs
Location Battery Charging Speed Accuracy Time Order Status {riderLogs.map((log, li) => ( {log.location} {log.battery} {log.charging} {log.speed} {log.accuracy} {log.time} {log.order} ))}
))}
setPage(p)} rowsPerPage={rpp} onRowsPerPageChange={(e) => { setRpp(+e.target.value); setPage(0); }} rowsPerPageOptions={[5, 10, 25]} />
); }