Initial commit of react-revamp for Auditor Portal

This commit is contained in:
2026-06-10 18:33:17 +05:30
commit a4c0892741
45 changed files with 7095 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import React, { useEffect, useState } from 'react';
import { Dialog, DialogTitle, DialogContent, List, ListItem, ListItemButton, ListItemText, CircularProgress, Box } from '@mui/material';
import { accountService } from '../../api/accountService';
interface Organization {
org_name: string;
org_id: string;
db_name: string;
}
interface DbSelectionDialogProps {
open: boolean;
onClose: (selectedOrg?: Organization) => void;
}
export const DbSelectionDialog: React.FC<DbSelectionDialogProps> = ({ open, onClose }) => {
const [organizations, setOrganizations] = useState<Organization[]>([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (open) {
setLoading(true);
accountService.getOrganizations()
.then((res: any) => {
const sorted = res.sort((a: Organization, b: Organization) =>
a.org_name.toLowerCase() > b.org_name.toLowerCase() ? 1 : -1
);
setOrganizations(sorted);
})
.catch((err) => {
console.error(err);
})
.finally(() => setLoading(false));
}
}, [open]);
return (
<Dialog open={open} onClose={() => onClose()} maxWidth="xs" fullWidth>
<DialogTitle>Select the organization</DialogTitle>
<DialogContent>
{loading ? (
<Box sx={{ display: 'flex', justifyContent: 'center', p: 2 }}>
<CircularProgress />
</Box>
) : (
<List>
{organizations.map((org) => (
<ListItem disablePadding key={org.org_id || org.org_name}>
<ListItemButton onClick={() => onClose(org)}>
<ListItemText primary={org.org_name} />
</ListItemButton>
</ListItem>
))}
</List>
)}
</DialogContent>
</Dialog>
);
};

163
src/pages/account/Login.tsx Normal file
View File

@@ -0,0 +1,163 @@
import React, { useState, useEffect } from 'react';
import { Box, Button, TextField, Typography, Container, Alert } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '../../store/authStore';
import { accountService } from '../../api/accountService';
import { DbSelectionDialog } from './DbSelectionDialog';
export const Login: React.FC = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [isInvalid, setIsInvalid] = useState(false);
const [loading, setLoading] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false);
const [tempUserData, setTempUserData] = useState<any>(null);
const { login, isAuthenticated } = useAuthStore();
const navigate = useNavigate();
// If already logged in, redirect
useEffect(() => {
if (isAuthenticated) {
navigate('/activity-feeds', { replace: true });
}
}, [isAuthenticated, navigate]);
const handleLogin = async () => {
setIsInvalid(false);
setLoading(true);
try {
const userData = await accountService.login(username, password);
if (!userData) {
setIsInvalid(true);
setLoading(false);
return;
}
const roles = userData.user_roles ? userData.user_roles.toLowerCase().split(',') : [];
if (roles.includes('sr_auditor')) {
// Open DB Selection Dialog
setTempUserData(userData);
setDialogOpen(true);
} else if (roles.includes('auditor')) {
// Direct login
login(userData);
navigate('/activity-feeds', { replace: true });
} else if (roles.includes('video_uploader')) {
// Direct login for dashboard
login(userData);
navigate('/activity-feeds', { replace: true });
} else {
alert("Your account is not configured to use this website. Please contact your admin for more info.");
}
} catch (error) {
setIsInvalid(true);
} finally {
setLoading(false);
}
};
const handleDbSelection = (selectedOrg?: any) => {
setDialogOpen(false);
if (selectedOrg && tempUserData) {
// Merge selected org details into user object
const finalUserData = {
...tempUserData,
org_id: selectedOrg.org_id,
db_name: selectedOrg.db_name,
selected_org_name: selectedOrg.org_name
};
login(finalUserData);
navigate('/activity-feeds', { replace: true });
}
};
return (
<Container component="main" maxWidth="xs">
<Box sx={{ marginTop: 8, display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
{/* Placeholder for Logo */}
<Box sx={{ mb: 6, display: 'flex', justifyContent: 'center' }}>
<img src="/images/SeekRightLogo.png" alt="Logo" width="250" onError={(e) => { e.currentTarget.style.display = 'none'; }} />
</Box>
<Box component="form" sx={{ mt: 1, width: '100%' }}>
<TextField
margin="normal"
required
fullWidth
id="username"
placeholder="Admin"
name="username"
autoFocus
value={username}
onChange={(e) => setUsername(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleLogin()}
InputProps={{
sx: { borderRadius: '50px', '& fieldset': { borderColor: '#738ab8' } }
}}
sx={{
mb: 1,
'& .MuiInputBase-input': { padding: '10px 14px', fontSize: '0.9rem', color: '#333' }
}}
/>
<TextField
margin="normal"
required
fullWidth
name="password"
placeholder="Password"
type="password"
id="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleLogin()}
InputProps={{
sx: { borderRadius: '50px', '& fieldset': { borderColor: '#738ab8' } }
}}
sx={{
mt: 1,
mb: 3,
'& .MuiInputBase-input': { padding: '10px 14px', fontSize: '0.9rem', color: '#333' }
}}
/>
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 3, mb: 4 }}>
<Button
variant="contained"
disabled={!username || !password || loading}
onClick={handleLogin}
sx={{
borderRadius: '50px',
backgroundColor: '#738ab8',
width: '140px',
pt: 1, pb: 1,
boxShadow: 'none',
'&:hover': {
backgroundColor: '#5c729c',
boxShadow: 'none',
}
}}
>
{loading ? '...' : 'LOGIN'}
</Button>
</Box>
{isInvalid && (
<Alert severity="error" sx={{ mt: 2 }}>
Invalid Credentials
</Alert>
)}
</Box>
</Box>
{/* Database Selection Dialog for SR_AUDITOR */}
<DbSelectionDialog open={dialogOpen} onClose={handleDbSelection} />
</Container>
);
};

View File

@@ -0,0 +1,60 @@
import React from 'react';
import { Card, CardMedia, CardContent, Typography, Box, Slider, Button } from '@mui/material';
interface AnomalyCardProps {
anomaly: any;
}
export const AnomalyCard: React.FC<AnomalyCardProps> = ({ anomaly }) => {
// Safe extraction of properties based on Angular's data structure
const assetName = anomaly?.Asset?.replace(/_/gi, ' ') || 'Unknown Asset';
const createdOn = anomaly?.Created_on || 'Unknown Date';
const confidence = anomaly?.Confidence || 0;
const imageSrc = anomaly?.Frame_Master || '/assets/images/placeholder.jpg';
const isAudited = anomaly?.IsAudited;
return (
<Card sx={{ display: 'flex', mb: 2, height: 180 }}>
{/* Image Section */}
<CardMedia
component="img"
sx={{ width: 250, objectFit: 'cover' }}
image={imageSrc}
alt={assetName}
/>
{/* Details Section */}
<CardContent sx={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
<Box>
<Typography variant="h6" component="div">
{assetName}
</Typography>
<Typography variant="body2" color="text.secondary">
Date: {createdOn} | Chainage: {anomaly?.Chainage || 'N/A'}
</Typography>
<Typography variant="body2" color="text.secondary">
Confidence: {confidence}% | Status: {isAudited ? 'Audited' : 'Unaudited'}
</Typography>
</Box>
{/* Sliders and Buttons (Placeholder logic for audit status) */}
<Box sx={{ display: 'flex', alignItems: 'center', mt: 2, gap: 2 }}>
<Typography variant="body2">True</Typography>
<Slider
value={anomaly?.anomaly_status_slider || 50}
step={100}
marks
min={0}
max={100}
sx={{ width: 100 }}
/>
<Typography variant="body2">False</Typography>
<Button variant="outlined" size="small" sx={{ ml: 'auto' }}>
{isAudited ? 'Edit' : 'Save'}
</Button>
</Box>
</CardContent>
</Card>
);
};

View File

@@ -0,0 +1,37 @@
import React from 'react';
import { Box, Typography } from '@mui/material';
import { useFeedStore } from '../../store/feedStore';
import { AnomalyCard } from './AnomalyCard';
export const AnomalyList: React.FC = () => {
const { tabs, selectedTabIndex } = useFeedStore();
if (tabs.length === 0 || selectedTabIndex < 0) {
return <Typography>Loading feeds...</Typography>;
}
const activeTab = tabs[selectedTabIndex];
const anomalies = activeTab.anomalies || [];
if (anomalies.length === 0) {
return (
<Box sx={{ p: 4, textAlign: 'center' }}>
<Typography variant="body1" color="textSecondary">
No anomalies found for the selected criteria.
</Typography>
</Box>
);
}
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
<Typography variant="subtitle2" color="textSecondary">
Showing {anomalies.length} / {activeTab.totalAnomalyCount} anomalies
</Typography>
{anomalies.map((anomaly: any, index: number) => (
<AnomalyCard key={anomaly._id || index} anomaly={anomaly} />
))}
</Box>
);
};

View File

@@ -0,0 +1,124 @@
import React from 'react';
import { Box, Typography, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Slider, Checkbox } from '@mui/material';
import { useFeedStore } from '../../store/feedStore';
export const AnomalyTable: React.FC = () => {
const { tabs, selectedTabIndex, updateTab } = useFeedStore();
if (tabs.length === 0 || selectedTabIndex < 0) {
return <Typography sx={{ p: 2 }}>Loading feeds...</Typography>;
}
const activeTab = tabs[selectedTabIndex];
const anomalies = activeTab.anomalies || [];
if (anomalies.length === 0) {
return (
<Box sx={{ p: 4, textAlign: 'center' }}>
<Typography variant="body1" color="textSecondary">
No anomalies found for the selected criteria.
</Typography>
</Box>
);
}
const handleRowClick = (index: number) => {
updateTab(selectedTabIndex, { selectedAnomalyIndex: index });
};
const getRowColor = (index: number, _asset: string) => {
// Dark mode colors for table rows
const colors = ['rgba(255, 255, 255, 0.03)', 'rgba(255, 255, 255, 0.0)'];
return colors[index % colors.length];
};
return (
<TableContainer component={Paper} sx={{ borderRadius: 0, boxShadow: 'none', height: 'calc(100vh - 180px)', bgcolor: 'transparent' }}>
<Table stickyHeader size="small" sx={{ minWidth: 1200 }}>
<TableHead>
<TableRow>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>#ID</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>PLAZA</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>ROAD</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>DATE</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>CHAINAGE</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>LAT/LONG</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>ANOMALY</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>SIDE</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>ANOMALY True/False</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>FEATURES</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>COMMENTS</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>CHECKED</TableCell>
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>AUTO AUDIT</TableCell>
</TableRow>
</TableHead>
<TableBody>
{anomalies.map((anomaly: any, index: number) => {
const isSelected = activeTab.selectedAnomalyIndex === index;
const assetName = anomaly?.Asset?.replace(/_/gi, ' ') || 'Unknown Asset';
const rowColor = getRowColor(index, assetName);
// Parse Position
let latStr = 'N/A';
let longStr = 'E/A';
if (anomaly?.Pos) {
const match = String(anomaly.Pos).match(/([NS][0-9.]+)([EW][0-9.]+)/i);
if (match) {
latStr = match[1];
longStr = match[2];
} else {
latStr = anomaly.Pos; // Fallback
longStr = '';
}
}
return (
<TableRow
key={anomaly._id || index}
onClick={() => handleRowClick(index)}
sx={{
bgcolor: isSelected ? 'rgba(59, 130, 246, 0.2)' : rowColor,
cursor: 'pointer',
'&:hover': { bgcolor: 'rgba(255,255,255,0.08)' },
borderLeft: isSelected ? '4px solid #3b82f6' : '4px solid transparent',
mb: 1,
}}
>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>#{anomaly.id || anomaly._id?.substring(0, 7) || 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Plaza || 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.road || anomaly.Road || 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Created_on ? new Date(anomaly.Created_on).toLocaleDateString() : 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Chainage || 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)', fontSize: '0.75rem' }}>
{latStr}<br/>
{longStr}
</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{assetName}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Side || 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)', width: 120 }}>
<Slider
size="small"
value={anomaly.Audit_status || anomaly.anomaly_status_slider || 50}
step={100}
marks
min={0}
max={100}
sx={{ color: '#ff4d4f' }}
/>
</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Features || 'N/A'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Comments || '-'}</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>
<Checkbox size="small" checked={!!anomaly.IsAudited} />
</TableCell>
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>
<Checkbox size="small" checked={!!anomaly.auto_audit} />
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
);
};

View File

@@ -0,0 +1,324 @@
import React, { useState, useMemo, useEffect, useCallback, memo } from 'react';
import {
Box, TextField, Checkbox, FormControlLabel, Button, Typography, Dialog,
DialogContent, DialogActions, CircularProgress, Divider, InputAdornment, Chip
} from '@mui/material';
import SearchIcon from '@mui/icons-material/Search';
import { useFeedStore } from '../../store/feedStore';
import { activityFeedsService } from '../../api/activityFeedsService';
// ── Memoized asset row — only re-renders when ITS OWN checked state changes ──
const AssetRow = memo(({
assetId, assetName, checked, onToggle
}: {
assetId: number;
assetName: string;
checked: boolean;
onToggle: (id: number) => void;
}) => (
<FormControlLabel
control={
<Checkbox
size="small"
checked={checked}
onChange={() => onToggle(assetId)}
sx={{ color: '#475569', '&.Mui-checked': { color: '#3b82f6' }, py: 0.3 }}
/>
}
label={
<Typography variant="caption" sx={{ color: '#cbd5e1', fontSize: '0.72rem' }}>
{assetName.replace(/_/g, ' ')}
</Typography>
}
/>
));
// ── Memoized group header ──────────────────────────────────────────────────────
const GroupHeader = memo(({
typeName, assetCount, allGroupSelected, someGroupSelected, onToggle
}: {
typeName: string;
assetCount: number;
allGroupSelected: boolean;
someGroupSelected: boolean;
onToggle: () => void;
}) => (
<FormControlLabel
control={
<Checkbox
checked={allGroupSelected}
indeterminate={someGroupSelected}
onChange={onToggle}
size="small"
sx={{ color: '#64748b', '&.Mui-checked': { color: '#60a5fa' }, '&.MuiCheckbox-indeterminate': { color: '#60a5fa' } }}
/>
}
label={
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#60a5fa', textTransform: 'uppercase', fontSize: '0.7rem', letterSpacing: 1 }}>
{typeName?.replace(/_/g, ' ')} ({assetCount})
</Typography>
}
sx={{ mb: 0.5 }}
/>
));
export const FeedFilters: React.FC = () => {
const {
assetTypes, tabs, selectedTabIndex, updateTab,
isFiltersModalOpen, setIsFiltersModalOpen,
selectedAssetIds, setSelectedAssetIds,
filterFromDate, filterTillDate,
filterMinChainage, filterMaxChainage,
setFilterMinChainage, setFilterMaxChainage,
} = useFeedStore();
// ── Use a Set (stored in state) for O(1) has() lookups ────────────────────
// We store a Set but wrap it in an object so React detects the change
const [draftSet, setDraftSet] = useState<Set<number>>(() => new Set(selectedAssetIds));
const [draftFromDate, setDraftFromDate] = useState('');
const [draftTillDate, setDraftTillDate] = useState('');
const [draftMinChainage, setDraftMinChainage] = useState('');
const [draftMaxChainage, setDraftMaxChainage] = useState('');
const [assetSearch, setAssetSearch] = useState('');
const [loading, setLoading] = useState(false);
// When dialog opens, seed ALL drafts from current store values — not empty strings!
const [prevOpen, setPrevOpen] = useState(false);
if (isFiltersModalOpen && !prevOpen) {
setPrevOpen(true);
setDraftSet(new Set(selectedAssetIds));
setDraftFromDate(filterFromDate); // ← seeded from store
setDraftTillDate(filterTillDate); // ← seeded from store
setDraftMinChainage(filterMinChainage); // ← seeded from store
setDraftMaxChainage(filterMaxChainage); // ← seeded from store
setAssetSearch('');
} else if (!isFiltersModalOpen && prevOpen) {
setPrevOpen(false);
}
const allAssetIds = useMemo(
() => assetTypes.flatMap((t: any) => t.assets.map((a: any) => a.asset_id as number)),
[assetTypes]
);
const filteredAssetTypes = useMemo(() => {
if (!assetSearch.trim()) return assetTypes;
const q = assetSearch.toLowerCase();
return assetTypes
.map((type: any) => ({
...type,
assets: type.assets.filter((a: any) => a.asset_name.toLowerCase().includes(q))
}))
.filter((type: any) => type.assets.length > 0);
}, [assetTypes, assetSearch]);
const allSelected = allAssetIds.length > 0 && allAssetIds.every(id => draftSet.has(id));
const someSelected = draftSet.size > 0 && !allSelected;
// ── Stable callbacks (useCallback so memoized children don't re-render) ───
const handleToggleAsset = useCallback((assetId: number) => {
setDraftSet(prev => {
const next = new Set(prev);
if (next.has(assetId)) next.delete(assetId); else next.add(assetId);
return next;
});
}, []);
const handleToggleAll = useCallback(() => {
setDraftSet(prev =>
prev.size === allAssetIds.length ? new Set() : new Set(allAssetIds)
);
}, [allAssetIds]);
const makeGroupToggle = useCallback((groupIds: number[]) => () => {
setDraftSet(prev => {
const allIn = groupIds.every(id => prev.has(id));
const next = new Set(prev);
if (allIn) groupIds.forEach(id => next.delete(id));
else groupIds.forEach(id => next.add(id));
return next;
});
}, []);
const handleClearAll = useCallback(() => {
setDraftSet(new Set());
setDraftFromDate('');
setDraftTillDate('');
setDraftMinChainage('');
setDraftMaxChainage('');
setAssetSearch('');
}, []);
// ── Apply — only now do we write to the store ────────────────────────────
const handleApplyFilter = async () => {
setLoading(true);
try {
const { selectedSite, auditStatus, setFilterFromDate, setFilterTillDate } = useFeedStore.getState();
const draftAssetArr = Array.from(draftSet);
// Commit ALL filter state to the global store
setFilterFromDate(draftFromDate);
setFilterTillDate(draftTillDate);
setFilterMinChainage(draftMinChainage); // persist chainage globally
setFilterMaxChainage(draftMaxChainage); // persist chainage globally
setSelectedAssetIds(draftAssetArr);
if (selectedTabIndex >= 0) {
const activeTab = tabs[selectedTabIndex];
const siteIdParam = (!selectedSite || selectedSite?.site_id === 'All Sites')
? '' : String(selectedSite.site_id || '');
const historyRes: any = await activityFeedsService.getHistory({
date: activeTab.date,
fromDate: draftFromDate,
tillDate: draftTillDate,
pageNo: 0,
pageSize: 20,
siteIds: siteIdParam,
assetsIds: draftAssetArr.join(','),
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
isRectificationEnabled: false,
auto_audit: false,
fromChainage: draftMinChainage,
toChainage: draftMaxChainage,
});
if (historyRes?.anomalies) {
updateTab(selectedTabIndex, {
anomalies: historyRes.anomalies,
anomaliesCopy: historyRes.anomalies,
totalAnomalyCount: historyRes.count || historyRes.anomalies.length,
filters: { fromDate: draftFromDate, tillDate: draftTillDate, fromChainage: draftMinChainage, toChainage: draftMaxChainage }
});
}
}
setIsFiltersModalOpen(false);
} catch (err) {
console.error('Filter apply failed', err);
} finally {
setLoading(false);
}
};
return (
<Dialog
open={isFiltersModalOpen}
onClose={() => setIsFiltersModalOpen(false)}
maxWidth="lg"
fullWidth
// Zero transition — opens instantly
transitionDuration={0}
PaperProps={{
sx: {
borderRadius: 3,
bgcolor: '#0f172a',
color: '#f8fafc',
border: '1px solid #1e293b',
maxHeight: '90vh'
}
}}
>
<DialogContent sx={{ p: 3 }}>
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2 }}>
<Typography variant="h6" sx={{ fontWeight: 'bold', color: '#f8fafc' }}>Filters</Typography>
{draftSet.size > 0 && (
<Chip
label={`${draftSet.size} asset${draftSet.size > 1 ? 's' : ''} selected`}
size="small" color="primary"
onDelete={() => setDraftSet(new Set())}
/>
)}
</Box>
{/* Date & Chainage */}
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 2, mb: 3, alignItems: 'center' }}>
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#94a3b8', whiteSpace: 'nowrap' }}>From Date</Typography>
<TextField size="small" type="date" value={draftFromDate} onChange={(e) => setDraftFromDate(e.target.value)}
sx={{ bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
</Box>
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#94a3b8', whiteSpace: 'nowrap' }}>Till Date</Typography>
<TextField size="small" type="date" value={draftTillDate} onChange={(e) => setDraftTillDate(e.target.value)}
sx={{ bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
</Box>
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#94a3b8', whiteSpace: 'nowrap' }}>Chainage</Typography>
<TextField size="small" placeholder="From" value={draftMinChainage} onChange={(e) => setDraftMinChainage(e.target.value)}
sx={{ width: 90, bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
<Typography variant="body2" sx={{ color: '#64748b' }}></Typography>
<TextField size="small" placeholder="To" value={draftMaxChainage} onChange={(e) => setDraftMaxChainage(e.target.value)}
sx={{ width: 90, bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
</Box>
</Box>
<Divider sx={{ borderColor: '#1e293b', mb: 2 }} />
<Typography variant="subtitle1" sx={{ fontWeight: 'bold', color: '#f8fafc', mb: 1 }}>Assets</Typography>
<TextField
placeholder="Search assets..."
variant="outlined" size="small" fullWidth
value={assetSearch}
onChange={(e) => setAssetSearch(e.target.value)}
sx={{ mb: 2, bgcolor: 'rgba(255,255,255,0.05)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }}
slotProps={{ input: { startAdornment: <InputAdornment position="start"><SearchIcon sx={{ color: '#64748b' }} /></InputAdornment> } }}
/>
<FormControlLabel
control={
<Checkbox checked={allSelected} indeterminate={someSelected} onChange={handleToggleAll}
sx={{ color: '#64748b', '&.Mui-checked': { color: '#3b82f6' }, '&.MuiCheckbox-indeterminate': { color: '#3b82f6' } }} />
}
label={<Typography variant="body2" sx={{ color: '#94a3b8', fontWeight: 'bold' }}>Select All ({allAssetIds.length})</Typography>}
sx={{ mb: 1 }}
/>
<Box sx={{ maxHeight: 350, overflowY: 'auto', pr: 1 }}>
{filteredAssetTypes.length === 0 ? (
<Typography variant="body2" sx={{ color: '#64748b' }}>No assets match your search.</Typography>
) : (
filteredAssetTypes.map((type: any) => {
const groupIds: number[] = type.assets.map((a: any) => a.asset_id);
const allGroupSelected = groupIds.every(id => draftSet.has(id));
const someGroupSelected = groupIds.some(id => draftSet.has(id)) && !allGroupSelected;
return (
<Box key={type.type_id} sx={{ mb: 2 }}>
<GroupHeader
typeName={type.type_name}
assetCount={type.assets.length}
allGroupSelected={allGroupSelected}
someGroupSelected={someGroupSelected}
onToggle={makeGroupToggle(groupIds)}
/>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 0, pl: 3 }}>
{type.assets.map((asset: any) => (
<AssetRow
key={asset.asset_id}
assetId={asset.asset_id}
assetName={asset.asset_name}
checked={draftSet.has(asset.asset_id)}
onToggle={handleToggleAsset}
/>
))}
</Box>
</Box>
);
})
)}
</Box>
</DialogContent>
<DialogActions sx={{ justifyContent: 'space-between', px: 3, pb: 3, borderTop: '1px solid #1e293b', pt: 2 }}>
<Button variant="outlined" onClick={handleClearAll}
sx={{ borderColor: '#334155', color: '#94a3b8', borderRadius: 2, '&:hover': { borderColor: '#64748b', bgcolor: 'rgba(255,255,255,0.05)' } }}>
Clear All
</Button>
<Button variant="contained" onClick={handleApplyFilter} disabled={loading}
sx={{ bgcolor: '#3b82f6', color: '#fff', width: 160, borderRadius: 2, '&:hover': { bgcolor: '#2563eb' } }}>
{loading ? <CircularProgress size={22} color="inherit" /> : 'Apply Filters'}
</Button>
</DialogActions>
</Dialog>
);
};

View File

@@ -0,0 +1,55 @@
import React from 'react';
import { Tabs, Tab, Box, IconButton } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import { useFeedStore } from '../../store/feedStore';
export const FeedTabs: React.FC = () => {
const { tabs, selectedTabIndex, setSelectedTabIndex, closeTab } = useFeedStore();
const handleChange = (_event: React.SyntheticEvent, newValue: number) => {
setSelectedTabIndex(newValue);
};
if (tabs.length === 0) return null;
return (
<Box sx={{ bgcolor: 'background.paper', pt: 1, px: 2 }}>
<Tabs
value={selectedTabIndex}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
sx={{ minHeight: 40, '& .MuiTabs-indicator': { display: 'none' } }}
>
{tabs.map((tab, index) => (
<Tab
key={index}
sx={{
bgcolor: selectedTabIndex === index ? 'background.default' : 'transparent',
color: selectedTabIndex === index ? 'text.primary' : 'text.secondary',
borderTopLeftRadius: 4,
borderTopRightRadius: 4,
minHeight: 40,
textTransform: 'none',
fontWeight: 'bold',
mr: 1,
'&.Mui-selected': {
color: 'text.primary',
}
}}
label={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
{tab.date === '' ? 'Unaudited' : tab.date}
{index !== 0 && ( // Don't allow closing the first tab usually
<IconButton size="small" onClick={(e) => { e.stopPropagation(); closeTab(index); }} sx={{ ml: 1, color: 'inherit', p: 0.5 }}>
<CloseIcon fontSize="small" />
</IconButton>
)}
</Box>
}
/>
))}
</Tabs>
</Box>
);
};

View File

@@ -0,0 +1,283 @@
import React, { useEffect } from 'react';
import { Box, Typography, TablePagination, Button, FormControl, Select, MenuItem } from '@mui/material';
import FilterListIcon from '@mui/icons-material/FilterList';
import HistoryIcon from '@mui/icons-material/History';
import { TopFilterBar } from '../../components/common/TopFilterBar';
import { FeedTabs } from './FeedTabs';
import { AnomalyTable } from './AnomalyTable';
import { PreviewPanel } from './PreviewPanel';
import { useFeedStore } from '../../store/feedStore';
import { useAuthStore } from '../../store/authStore';
import { activityFeedsService } from '../../api/activityFeedsService';
export const GlobalFeed: React.FC = () => {
const {
setAssets, setAssetTypes, addTab, tabs, selectedTabIndex, updateTab,
sites, setSites, selectedSite, setSelectedSite, auditStatus,
isInitialized, setIsInitialized,
lastFetchedFilterKey, setLastFetchedFilterKey
} = useFeedStore();
const { user } = useAuthStore();
// Ref to skip the first run of the site/auditStatus effect
const isFirstRender = React.useRef(true);
useEffect(() => {
// Initial Load
const loadInitialData = async () => {
try {
const assetRes: any = await activityFeedsService.getAssets();
if (assetRes && assetRes.asset_types) {
// Map assets mimicking the Angular logic
let flattenedAssets: any[] = [];
assetRes.asset_types.forEach((type: any) => {
const mapped = type.assets.map((a: any) => ({
id: a.asset_id,
name: a.asset_name,
asset_type_id: type.type_id
}));
flattenedAssets = [...flattenedAssets, ...mapped];
});
setAssets(flattenedAssets);
setAssetTypes(assetRes.asset_types); // store raw grouped data for filters dialog
}
// Fetch Sites
let defaultSite = null;
if (user?.org_id) {
try {
const sitesRes: any = await activityFeedsService.getOrganizationSites(user.org_id);
let parsedSites: any[] = [];
if (sitesRes?.responseData?.[0]?.records) {
parsedSites = sitesRes.responseData[0].records;
// Handle nested array response [ [ {site1}, {site2} ] ]
if (parsedSites.length === 1 && Array.isArray(parsedSites[0])) {
parsedSites = parsedSites[0];
} else if (parsedSites.length > 0 && Array.isArray(parsedSites[0])) {
parsedSites = parsedSites.flat();
}
} else if (Array.isArray(sitesRes)) {
parsedSites = sitesRes;
} else if (sitesRes?.data && Array.isArray(sitesRes.data)) {
parsedSites = sitesRes.data;
}
if (parsedSites.length > 0) {
// Filter to ensure we only show sites for the currently selected org
parsedSites = parsedSites.filter(site => {
let siteOrgId = site.org_id;
if (siteOrgId === undefined && site.sub_sites && site.sub_sites.length > 0) {
siteOrgId = site.sub_sites[0].org_id;
}
if (siteOrgId !== undefined && siteOrgId !== null) {
return String(siteOrgId) === String(user.org_id);
}
return true;
}).map(site => {
// Normalize site_id: if missing, aggregate from sub_sites
if (!site.site_id && site.sub_sites && site.sub_sites.length > 0) {
site.site_id = site.sub_sites.map((sub: any) => sub.site_id).filter(Boolean).join(',');
}
return site;
});
setSites(parsedSites);
defaultSite = { site_id: 'All Sites', site_name: 'All Sites' };
setSelectedSite(defaultSite);
}
} catch (siteErr) {
console.error("Failed to fetch sites", siteErr);
}
}
// Add default Unaudited tab if empty and fetch data
if (useFeedStore.getState().tabs.length === 0) {
addTab({
date: '', // Unaudited
isRectificationTab: false,
totalAnomalyCount: 0,
anomalies: [],
anomaliesCopy: [],
selectedAnomalyIndex: 0,
filters: {},
page: 0,
rowsPerPage: 20
});
try {
const historyRes: any = await activityFeedsService.getHistory({
date: '',
pageNo: 0,
pageSize: 20,
siteIds: defaultSite?.site_id === 'All Sites' ? '' : (defaultSite?.site_id || ''),
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
auto_audit: false,
isRectificationEnabled: false
});
if (historyRes && historyRes.anomalies) {
updateTab(0, {
anomalies: historyRes.anomalies,
anomaliesCopy: historyRes.anomalies,
totalAnomalyCount: historyRes.count || historyRes.anomalies.length
});
}
} catch (historyErr) {
console.error("[GlobalFeed] Failed to load history", historyErr);
}
}
} catch (error) {
console.error("Failed to load initial feed data", error);
} finally {
setIsInitialized(true); // Mark as initialized regardless, to prevent retry loops
}
};
// GUARD: Only run initial load once across tab switches
if (useFeedStore.getState().isInitialized) {
return;
}
loadInitialData();
}, []); // eslint-disable-line react-hooks/exhaustive-deps
// Fetch data when selectedSite or auditStatus changes
useEffect(() => {
// GUARD: Skip if tabs are not initialized (initial load hasn't finished)
if (useFeedStore.getState().tabs.length === 0) {
return;
}
// Build a key for the current filter state
const filterKey = `${selectedSite?.site_id ?? ''}|${auditStatus}`;
// CACHE HIT: This exact filter combo was already fetched — skip re-fetch on remount
if (filterKey === lastFetchedFilterKey) {
return;
}
const fetchFilteredHistory = async () => {
const state = useFeedStore.getState();
const currentTabIndex = state.selectedTabIndex > -1 ? state.selectedTabIndex : 0;
const activeTab = state.tabs[currentTabIndex];
const siteIdParam = (!selectedSite || selectedSite?.site_id === 'All Sites')
? '' : String(selectedSite.site_id || '');
try {
const historyRes: any = await activityFeedsService.getHistory({
date: activeTab?.date || '',
pageNo: 0,
pageSize: 20,
siteIds: siteIdParam,
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
auto_audit: false,
isRectificationEnabled: false,
...(activeTab?.filters || {})
});
if (historyRes && historyRes.anomalies) {
useFeedStore.getState().updateTab(currentTabIndex, {
anomalies: historyRes.anomalies,
anomaliesCopy: historyRes.anomalies,
totalAnomalyCount: historyRes.count || historyRes.anomalies.length
});
setLastFetchedFilterKey(filterKey); // mark this combo as fetched
}
} catch (err) {
console.error('[GlobalFeed] Failed to load history for site/audit status change', err);
}
};
fetchFilteredHistory();
// Use primitive/stable values to avoid spurious re-runs.
// selectedSite?.site_id and auditStatus are both strings/primitives.
}, [selectedSite?.site_id, auditStatus]); // eslint-disable-line react-hooks/exhaustive-deps
const handlePageChange = async (event: unknown, newPage: number) => {
if (selectedTabIndex < 0 || tabs.length === 0) return;
const activeTab = tabs[selectedTabIndex];
const allSiteIds = sites.map(s => s.site_id).filter(Boolean).join(',');
const rowsPerPage = activeTab.rowsPerPage || 20;
try {
const historyRes: any = await activityFeedsService.getHistory({
date: activeTab?.date || '',
pageNo: newPage * rowsPerPage,
pageSize: rowsPerPage,
siteIds: selectedSite?.site_id === 'All Sites' ? '' : (selectedSite?.site_id || ''),
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
auto_audit: false,
isRectificationEnabled: false,
...(activeTab?.filters || {})
});
if (historyRes && historyRes.anomalies) {
updateTab(selectedTabIndex, {
anomalies: historyRes.anomalies,
anomaliesCopy: historyRes.anomalies,
totalAnomalyCount: historyRes.count || historyRes.anomalies.length,
page: newPage,
});
}
} catch (err) {
console.error("Failed to load history for page change", err);
}
};
const handleRowsPerPageChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
if (selectedTabIndex < 0 || tabs.length === 0) return;
const activeTab = tabs[selectedTabIndex];
const allSiteIds = sites.map(s => s.site_id).filter(Boolean).join(',');
const newRowsPerPage = parseInt(event.target.value, 10);
const newPage = 0;
try {
const historyRes: any = await activityFeedsService.getHistory({
date: activeTab?.date || '',
pageNo: newPage * newRowsPerPage,
pageSize: newRowsPerPage,
siteIds: selectedSite?.site_id === 'All Sites' ? '' : (selectedSite?.site_id || ''),
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
auto_audit: false,
isRectificationEnabled: false,
...(activeTab?.filters || {})
});
if (historyRes && historyRes.anomalies) {
updateTab(selectedTabIndex, {
anomalies: historyRes.anomalies,
anomaliesCopy: historyRes.anomalies,
totalAnomalyCount: historyRes.count || historyRes.anomalies.length,
page: newPage,
rowsPerPage: newRowsPerPage,
});
}
} catch (err) {
console.error("Failed to load history for rowsPerPage change", err);
}
};
return (
<Box sx={{ height: 'calc(100vh - 64px)', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
<TopFilterBar />
<FeedTabs />
<Box sx={{ display: 'flex', flex: 1, overflow: 'hidden', bgcolor: 'background.default' }}>
{/* Left side Table */}
<Box sx={{ flex: 1, overflow: 'auto', px: 2, display: 'flex', flexDirection: 'column' }}>
<Box sx={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', py: 0 }}>
<TablePagination
component="div"
count={tabs[selectedTabIndex]?.totalAnomalyCount || 0}
page={tabs[selectedTabIndex]?.page || 0}
onPageChange={handlePageChange}
rowsPerPage={tabs[selectedTabIndex]?.rowsPerPage || 20}
onRowsPerPageChange={handleRowsPerPageChange}
rowsPerPageOptions={[10, 20, 50, 100]}
/>
</Box>
<Box sx={{ flex: 1, overflow: 'auto' }}>
<AnomalyTable />
</Box>
</Box>
{/* Right side Preview Panel */}
<PreviewPanel />
</Box>
</Box>
);
};

View File

@@ -0,0 +1,80 @@
import React from 'react';
import { Box, Typography, Button } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import { useFeedStore } from '../../store/feedStore';
export const PreviewPanel: React.FC = () => {
const { tabs, selectedTabIndex } = useFeedStore();
const navigate = useNavigate();
if (tabs.length === 0 || selectedTabIndex < 0) return null;
const activeTab = tabs[selectedTabIndex];
const anomalies = activeTab.anomalies || [];
const selectedIndex = activeTab.selectedAnomalyIndex || 0;
const anomaly = anomalies[selectedIndex];
if (!anomaly) {
return (
<Box sx={{ width: 350, p: 2, bgcolor: '#f4f6f8', height: '100%', borderLeft: '1px solid #ddd' }}>
<Typography>No anomaly selected</Typography>
</Box>
);
}
const IMAGES_AWS_PREFIX = "https://auditor-master-images.seekright.com/SeekRight/";
const IMAGES_TEST_AUDIT_PREFIX = "https://dashboard-images.seekright.com/SeekRight/";
let masterImageSrc = '';
if (anomaly.Frame_Master) {
masterImageSrc = IMAGES_AWS_PREFIX + anomaly.Frame_Master;
} else if (!anomaly.Frame_Master && !anomaly.Frame_Test) {
masterImageSrc = '/assets/images/master_and_shift_image_not_available.png';
} else {
masterImageSrc = '/assets/images/only_master_image_not_available.png';
}
let anomalyImageSrc = '/assets/images/placeholder.jpg';
if (anomaly.Frame_Test) {
anomalyImageSrc = IMAGES_TEST_AUDIT_PREFIX + anomaly.Frame_Test;
}
return (
<Box sx={{ width: 400, p: 2, bgcolor: 'background.paper', height: 'calc(100vh - 120px)', borderLeft: '1px solid rgba(255,255,255,0.1)', overflowY: 'auto' }}>
<Box sx={{ mb: 2, border: '1px solid rgba(255,255,255,0.1)', borderRadius: 2, overflow: 'hidden' }}>
<img
src={masterImageSrc}
alt="Master"
style={{ width: '100%', height: 'auto', display: 'block' }}
/>
<Box sx={{ bgcolor: 'rgba(255,255,255,0.05)', color: 'text.primary', textAlign: 'center', py: 0.5 }}>
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>MASTER IMAGE</Typography>
</Box>
</Box>
<Box sx={{ mb: 2, border: '1px solid rgba(255,255,255,0.1)', borderRadius: 2, overflow: 'hidden' }}>
<img
src={anomalyImageSrc}
alt="Anomaly"
style={{ width: '100%', height: 'auto', display: 'block' }}
/>
<Box sx={{ bgcolor: 'rgba(255,255,255,0.05)', color: 'text.primary', textAlign: 'center', py: 0.5 }}>
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>ANOMALY IMAGE</Typography>
</Box>
</Box>
<Button
variant="contained"
fullWidth
color="primary"
onClick={() => navigate('/audit-session', { state: { useExistingFeed: true, startIndex: selectedIndex } })}
sx={{ mt: 1, py: 1.5, fontWeight: 'bold', borderRadius: 2 }}
>
Audit Item
</Button>
</Box>
);
};

View File

@@ -0,0 +1,477 @@
import React, { useState, useEffect, useCallback } from 'react';
import { Box, Typography, Button, IconButton, Chip } from '@mui/material';
import { useNavigate, useLocation } from 'react-router-dom';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { activityFeedsService } from '../../api/activityFeedsService';
import { useAuthStore } from '../../store/authStore';
import { useFeedStore } from '../../store/feedStore';
export const AuditSession: React.FC = () => {
const navigate = useNavigate();
const { user } = useAuthStore();
const [anomalies, setAnomalies] = useState<any[]>([]);
const [currentIndex, setCurrentIndex] = useState(0);
const [loading, setLoading] = useState(true);
const [carouselIndex, setCarouselIndex] = useState(0);
// For the right sidebar state
const [selectedCategory, setSelectedCategory] = useState<number | null>(null);
const [notes, setNotes] = useState('');
const [isAnomaly, setIsAnomaly] = useState<boolean | null>(null); // true = Anomaly, false = Safe
const location = useLocation();
const { tabs, selectedTabIndex } = useFeedStore();
useEffect(() => {
const navState = location.state as any;
if (navState?.useExistingFeed) {
// Use anomalies from the global feed store
const activeTab = tabs[selectedTabIndex];
if (activeTab && activeTab.anomalies) {
setAnomalies(activeTab.anomalies);
setCurrentIndex(navState.startIndex || 0);
setLoading(false);
} else {
setLoading(false);
}
} else {
// Fetch 50 items for the session (default behavior from Dashboard)
const fetchSessionData = async () => {
try {
setLoading(true);
const res: any = await activityFeedsService.getHistory({
date: '',
pageNo: 0,
pageSize: 50,
isTrueFalse: 'false', // Fetch unaudited
auto_audit: false,
isRectificationEnabled: false,
});
if (res && res.anomalies) {
setAnomalies(res.anomalies);
}
} catch (err) {
console.error('Failed to fetch session data', err);
} finally {
setLoading(false);
}
};
fetchSessionData();
}
}, [location.state, tabs, selectedTabIndex]);
const IMAGES_AWS_PREFIX = "https://auditor-master-images.seekright.com/SeekRight/";
const IMAGES_TEST_AUDIT_PREFIX = "https://dashboard-images.seekright.com/SeekRight/";
const currentAnomaly = anomalies[currentIndex];
useEffect(() => {
if (currentAnomaly?.images && currentAnomaly.images.length > 0) {
const selectedIdx = currentAnomaly.images.findIndex((img: any) => img.selected);
setCarouselIndex(selectedIdx !== -1 ? selectedIdx : 0);
} else {
setCarouselIndex(0);
}
}, [currentAnomaly]);
let masterImageSrc = '';
let anomalyImageSrc = '';
let latStr = 'N/A';
let longStr = 'E/A';
if (currentAnomaly) {
if (currentAnomaly.Frame_Master) {
masterImageSrc = IMAGES_AWS_PREFIX + currentAnomaly.Frame_Master;
} else if (!currentAnomaly.Frame_Master && !currentAnomaly.Frame_Test) {
masterImageSrc = '/assets/images/master_and_shift_image_not_available.png';
} else {
masterImageSrc = '/assets/images/only_master_image_not_available.png';
}
// Parse Position
if (currentAnomaly.Pos) {
const match = String(currentAnomaly.Pos).match(/([NS][0-9.]+)([EW][0-9.]+)/i);
if (match) {
latStr = match[1];
longStr = match[2];
} else {
latStr = currentAnomaly.Pos; // Fallback
longStr = '';
}
}
}
const mediaItems: { type: 'image'|'video', url: string }[] = React.useMemo(() => {
if (!currentAnomaly) return [];
const items: { type: 'image'|'video', url: string }[] = [];
if (currentAnomaly.images && currentAnomaly.images.length > 0) {
currentAnomaly.images.forEach((img: any) => {
items.push({ type: 'image', url: IMAGES_TEST_AUDIT_PREFIX + img.src });
});
} else if (currentAnomaly.Frame_Test) {
items.push({ type: 'image', url: IMAGES_TEST_AUDIT_PREFIX + currentAnomaly.Frame_Test });
}
if (currentAnomaly.video_url) {
items.push({ type: 'video', url: IMAGES_TEST_AUDIT_PREFIX + currentAnomaly.video_url });
}
return items;
}, [currentAnomaly]);
const handleNext = () => {
if (currentIndex < anomalies.length - 1) {
setCurrentIndex(prev => prev + 1);
// Reset form
setSelectedCategory(null);
setNotes('');
setIsAnomaly(null);
} else {
// Done with session
const navState = location.state as any;
if (navState?.useExistingFeed) {
navigate('/activity-feeds');
} else {
navigate('/dashboard');
}
}
};
const handlePrev = () => {
if (currentIndex > 0) {
setCurrentIndex(prev => prev - 1);
// We would ideally preserve form state for previously visited items
}
};
const handleSaveAndNext = async () => {
if (!currentAnomaly) return;
// Placeholder for save logic
// await activityFeedsService.updateAuditedAnomaly(...)
console.log('Saved:', { id: currentAnomaly.anomaly_id, isAnomaly, selectedCategory, notes });
handleNext();
};
// Keyboard shortcuts
const handleKeyDown = useCallback((e: KeyboardEvent) => {
// Prevent default on shortcuts if focused on inputs?
if (document.activeElement?.tagName === 'TEXTAREA' || document.activeElement?.tagName === 'INPUT') {
return; // Don't trigger shortcuts when typing notes
}
switch (e.key.toLowerCase()) {
case 'a':
setIsAnomaly(true);
break;
case 's':
setIsAnomaly(false);
break;
case '1': setSelectedCategory(1); break;
case '2': setSelectedCategory(2); break;
case '3': setSelectedCategory(3); break;
case '4': setSelectedCategory(4); break;
case '5': setSelectedCategory(5); break;
case 'enter':
handleSaveAndNext();
break;
case 'arrowright':
handleSaveAndNext();
break;
case 'arrowleft':
handlePrev();
break;
}
}, [currentIndex, anomalies, isAnomaly, selectedCategory, notes]);
useEffect(() => {
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [handleKeyDown]);
if (loading) {
return <Box sx={{ p: 4, color: 'white' }}>Loading session...</Box>;
}
if (anomalies.length === 0) {
return (
<Box sx={{ p: 4, color: 'white' }}>
<Typography mb={2}>No unaudited anomalies found to audit.</Typography>
<Button variant="contained" onClick={() => {
const navState = location.state as any;
navigate(navState?.useExistingFeed ? '/activity-feeds' : '/dashboard');
}}>Back</Button>
</Box>
);
}
const getSeverityBadge = () => {
// Placeholder badge logic
return <Chip label="HIGH" color="error" size="small" sx={{ borderRadius: 1, fontWeight: 'bold' }} />;
};
return (
<Box sx={{
display: 'flex',
flexDirection: 'column',
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
bgcolor: '#0b1121',
color: '#f8fafc',
overflow: 'hidden',
zIndex: 9999
}}>
{/* Header */}
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', p: 1, px: 2, borderBottom: '1px solid #1e293b', bgcolor: '#0f172a' }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<Button
startIcon={<ArrowBackIcon fontSize="small" />}
onClick={() => {
const navState = location.state as any;
navigate(navState?.useExistingFeed ? '/activity-feeds' : '/dashboard');
}}
sx={{ color: '#94a3b8', textTransform: 'none', minWidth: 'auto', p: 0, '&:hover': { color: 'white', bgcolor: 'transparent' } }}
>
Back
</Button>
<Typography sx={{ fontWeight: 'bold', fontSize: '0.9rem' }}>
Item {currentIndex + 1} of {anomalies.length} <span style={{ color: '#64748b', fontWeight: 'normal' }}>(session)</span>
</Typography>
{getSeverityBadge()}
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<Typography sx={{ fontWeight: 'bold', fontSize: '0.9rem' }}>{user?.first_name} {user?.last_name}</Typography>
<Button size="small" sx={{ color: '#94a3b8', border: '1px solid #334155', textTransform: 'none', borderRadius: 2 }}>? Shortcuts</Button>
</Box>
</Box>
{/* Main Content Area */}
<Box sx={{ display: 'flex', flex: 1, overflow: 'hidden', p: 2, gap: 2 }}>
{/* Left Side: Images & Overlay */}
<Box sx={{ display: 'flex', flexDirection: 'column', flex: 1, gap: 2, overflow: 'hidden' }}>
{/* Images Row */}
<Box sx={{ display: 'flex', flex: 1, gap: 2, overflow: 'hidden' }}>
{/* Previous Image Pane */}
<Box sx={{ flex: 1, bgcolor: '#0f172a', borderRadius: 2, border: '1px solid #1e293b', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
<Box sx={{ px: 2, py: 1, borderBottom: '1px solid #1e293b', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1 }}>MASTER IMAGE</Typography>
</Box>
<Box sx={{ flex: 1, position: 'relative' }}>
{masterImageSrc ? (
<img src={masterImageSrc} alt="Master" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
) : (
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', color: '#334155' }}>No Master Image</Box>
)}
</Box>
</Box>
{/* Current Image Pane */}
<Box sx={{ flex: 1, bgcolor: '#0f172a', borderRadius: 2, border: '1px solid #1e293b', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
<Box sx={{ px: 2, py: 1, borderBottom: '1px solid #1e293b', display: 'flex', justifyContent: 'space-between', alignItems: 'center', bgcolor: '#1e3a8a' }}>
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#60a5fa', letterSpacing: 1 }}>ANOMALY IMAGE</Typography>
<Typography sx={{ fontSize: '0.75rem', color: '#93c5fd' }}>{currentAnomaly?.date_of_audit || currentAnomaly?.Created_on}</Typography>
</Box>
<Box sx={{ flex: 1, position: 'relative' }}>
{mediaItems.length > 0 ? (
<>
{mediaItems[carouselIndex]?.type === 'video' ? (
<video src={mediaItems[carouselIndex]?.url} controls autoPlay loop style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
) : (
<img src={mediaItems[carouselIndex]?.url} alt="Anomaly" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
)}
{mediaItems.length > 1 && (
<Box sx={{ position: 'absolute', bottom: 16, left: '50%', transform: 'translateX(-50%)', display: 'flex', gap: 1, bgcolor: 'rgba(0,0,0,0.6)', p: 0.5, borderRadius: 2 }}>
<Button size="small" variant="text" sx={{ color: 'white', minWidth: 'auto', px: 2, '&:hover': { bgcolor: 'rgba(255,255,255,0.1)' } }} onClick={() => setCarouselIndex(prev => prev > 0 ? prev - 1 : mediaItems.length - 1)}>
&lt;
</Button>
<Typography sx={{ color: 'white', px: 1, display: 'flex', alignItems: 'center', fontSize: '0.875rem' }}>
{carouselIndex + 1} / {mediaItems.length}
</Typography>
<Button size="small" variant="text" sx={{ color: 'white', minWidth: 'auto', px: 2, '&:hover': { bgcolor: 'rgba(255,255,255,0.1)' } }} onClick={() => setCarouselIndex(prev => prev < mediaItems.length - 1 ? prev + 1 : 0)}>
&gt;
</Button>
</Box>
)}
</>
) : (
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', color: '#334155' }}>No Anomaly Media</Box>
)}
</Box>
</Box>
</Box>
{/* Bottom Bar: Location Overlay */}
<Box sx={{ bgcolor: '#0f172a', borderRadius: 2, border: '1px solid #1e293b', p: 2, display: 'flex', alignItems: 'center', gap: 2 }}>
<Box sx={{ width: 12, height: 12, borderRadius: '50%', bgcolor: '#ef4444' }} />
<Box>
<Typography sx={{ fontWeight: 'bold', fontSize: '0.9rem' }}>{currentAnomaly?.Plaza || 'Unknown Location'}</Typography>
<Typography sx={{ fontSize: '0.8rem', color: '#94a3b8' }}>
{latStr}, {longStr} ID #{currentAnomaly?.id || currentAnomaly?.anomaly_id || 'N/A'}
</Typography>
</Box>
</Box>
</Box>
{/* Right Side: Sidebar */}
<Box sx={{ width: 320, display: 'flex', flexDirection: 'column', gap: 3 }}>
{/* Anomaly/Safe Toggle */}
<Box>
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 1 }}>
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1 }}>ANOMALY?</Typography>
<Typography sx={{ fontSize: '0.75rem', color: '#64748b' }}>A / S</Typography>
</Box>
<Box sx={{ display: 'flex', gap: 1 }}>
<Button
fullWidth
variant={isAnomaly === true ? "contained" : "outlined"}
color={isAnomaly === true ? "error" : "inherit"}
onClick={() => setIsAnomaly(true)}
sx={{ borderRadius: 2, textTransform: 'none', borderColor: '#334155', color: isAnomaly === true ? 'white' : '#cbd5e1' }}
>
Anomaly
</Button>
<Button
fullWidth
variant={isAnomaly === false ? "contained" : "outlined"}
color={isAnomaly === false ? "success" : "inherit"}
onClick={() => setIsAnomaly(false)}
sx={{ borderRadius: 2, textTransform: 'none', borderColor: '#334155', color: isAnomaly === false ? 'white' : '#cbd5e1' }}
>
Safe
</Button>
</Box>
</Box>
{/* Category */}
<Box>
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1, mb: 1 }}>CATEGORY</Typography>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
{[
{ id: 1, label: 'No Issue', color: '#22c55e' },
{ id: 2, label: 'Minor Crack', color: '#eab308' },
{ id: 3, label: 'Major Crack', color: '#f97316' },
{ id: 4, label: 'Structural Damage', color: '#ef4444' },
{ id: 5, label: 'Needs Investigation', color: '#8b5cf6' },
].map(cat => (
<Button
key={cat.id}
onClick={() => setSelectedCategory(cat.id)}
sx={{
justifyContent: 'flex-start',
textTransform: 'none',
color: selectedCategory === cat.id ? 'white' : '#cbd5e1',
bgcolor: selectedCategory === cat.id ? 'rgba(255,255,255,0.05)' : 'transparent',
borderRadius: 2,
p: 1,
'&:hover': { bgcolor: 'rgba(255,255,255,0.1)' }
}}
>
<Box sx={{ width: 24, height: 24, borderRadius: '50%', bgcolor: cat.color, display: 'flex', alignItems: 'center', justifyContent: 'center', mr: 2, fontSize: '0.75rem', fontWeight: 'bold', color: 'white' }}>
{cat.id}
</Box>
{cat.label}
</Button>
))}
</Box>
</Box>
{/* Notes */}
<Box sx={{ flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0 }}>
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1, mb: 1 }}>NOTES</Typography>
<Box
component="textarea"
value={notes}
onChange={(e) => setNotes(e.target.value)}
placeholder="Optional observations..."
sx={{
width: '100%',
flex: 1,
minHeight: 60,
bgcolor: '#0f172a',
border: '1px solid #1e293b',
borderRadius: 2,
color: 'white',
p: 2,
fontFamily: 'inherit',
resize: 'none',
'&:focus': { outline: 'none', borderColor: '#3b82f6' }
}}
/>
</Box>
{/* Actions */}
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<Button
variant="contained"
color="primary"
onClick={handleSaveAndNext}
sx={{ borderRadius: 2, py: 1.5, textTransform: 'none', fontWeight: 'bold', display: 'flex', justifyContent: 'space-between', px: 3 }}
>
Save & Next <Typography component="span" sx={{ fontSize: '0.75rem', opacity: 0.7 }}>Enter / </Typography>
</Button>
<Box sx={{ display: 'flex', gap: 1 }}>
<Button
variant="outlined"
onClick={handlePrev}
disabled={currentIndex === 0}
sx={{ flex: 1, borderRadius: 2, textTransform: 'none', borderColor: '#1e293b', color: '#94a3b8', '&:hover': { borderColor: '#334155' } }}
>
Prev
</Button>
<Button
variant="outlined"
onClick={handleNext}
sx={{ flex: 1, borderRadius: 2, textTransform: 'none', borderColor: '#1e293b', color: '#94a3b8', '&:hover': { borderColor: '#334155' } }}
>
Skip <span style={{ fontSize: '0.75rem', opacity: 0.7, marginLeft: 8 }}>Tab</span>
</Button>
</Box>
</Box>
</Box>
</Box>
{/* Footer Shortcuts */}
<Box sx={{ borderTop: '1px solid #1e293b', p: 1, px: 2, display: 'flex', gap: 3, alignItems: 'center', overflowX: 'auto', '& > div': { display: 'flex', alignItems: 'center', gap: 1, whiteSpace: 'nowrap' } }}>
<Typography sx={{ fontSize: '0.75rem', color: '#64748b' }}>Keys:</Typography>
<Box>
<Chip label="A" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Anomaly</Typography>
</Box>
<Box>
<Chip label="S" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Safe</Typography>
</Box>
<Box>
<Chip label="1-5" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Category</Typography>
</Box>
<Box>
<Chip label="Enter" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Save & Next</Typography>
</Box>
<Box>
<Chip label="← →" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Navigate</Typography>
</Box>
<Box>
<Chip label="Tab" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Skip</Typography>
</Box>
<Box>
<Chip label="?" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Help</Typography>
</Box>
</Box>
</Box>
);
};

View File

@@ -0,0 +1,205 @@
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Box, Typography, Button, Paper, LinearProgress, Container } from '@mui/material';
import WarningAmberIcon from '@mui/icons-material/WarningAmber';
import { activityFeedsService } from '../../api/activityFeedsService';
import { TopFilterBar } from '../../components/common/TopFilterBar';
import { useFeedStore } from '../../store/feedStore';
export const Dashboard: React.FC = () => {
const {
selectedSite, auditStatus, filterFromDate, filterTillDate,
filterMinChainage, filterMaxChainage,
selectedAssetIds, dashboardCache, setDashboardCache
} = useFeedStore();
const navigate = useNavigate();
const selectedSiteId = selectedSite?.site_id ?? '';
const assetIdsKey = selectedAssetIds.join(',');
// Build a key that uniquely identifies the current filter state
const currentFilterKey = `${selectedSiteId}|${auditStatus}|${filterFromDate}|${filterTillDate}|${assetIdsKey}|${filterMinChainage}|${filterMaxChainage}`;
// Initialise stats from cache immediately (no flicker on tab switch)
const [stats, setStats] = useState(() =>
dashboardCache.stats ?? { total: 0, audited: 0, pending: 0, anomaliesFound: 0 }
);
// Only show loading spinner if there's no cached result for these filters
const [loading, setLoading] = useState(dashboardCache.stats === null);
useEffect(() => {
// CACHE HIT: filters unchanged since last fetch — skip API call entirely
if (dashboardCache.stats !== null && currentFilterKey === `${dashboardCache.siteId}|${dashboardCache.auditStatus}|${dashboardCache.fromDate}|${dashboardCache.tillDate}|${dashboardCache.assetIds}|${dashboardCache.minChainage}|${dashboardCache.maxChainage}`) {
setStats(dashboardCache.stats);
setLoading(false);
return;
}
const fetchStats = async () => {
try {
setLoading(true);
const res: any = await activityFeedsService.getHistory({
date: '',
pageNo: 0,
pageSize: 200,
sortByDateAsc: false,
isRectificationEnabled: false,
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
auto_audit: false,
siteIds: (!selectedSiteId || selectedSiteId === 'All Sites') ? '' : selectedSiteId,
assetsIds: assetIdsKey,
fromDate: filterFromDate,
tillDate: filterTillDate,
fromChainage: filterMinChainage,
toChainage: filterMaxChainage,
});
if (res) {
const anomalies = res.anomalies || [];
const newStats = {
total: res.count || anomalies.length,
audited: anomalies.filter((a: any) => a.IsAudited === 1).length,
pending: anomalies.filter((a: any) => a.IsAudited === 0).length,
anomaliesFound: anomalies.filter((a: any) => a.Audit_status === 1).length,
};
setStats(newStats);
// Persist to store cache so re-mounting the Dashboard skips this fetch
setDashboardCache({
siteId: selectedSiteId,
auditStatus,
fromDate: filterFromDate,
tillDate: filterTillDate,
assetIds: assetIdsKey,
minChainage: filterMinChainage,
maxChainage: filterMaxChainage,
stats: newStats,
});
}
} catch (err) {
console.error('Failed to load dashboard stats', err);
} finally {
setLoading(false);
}
};
fetchStats();
}, [currentFilterKey]); // eslint-disable-line react-hooks/exhaustive-deps
const progressPercent = stats.total > 0 ? Math.round((stats.audited / stats.total) * 100) : 0;
return (
<Box sx={{ width: '100%', maxWidth: '100vw', display: 'flex', flexDirection: 'column' }}>
<TopFilterBar />
<Box sx={{ px: 2, pt: 2, pb: 4, width: '100%' }}>
<Box sx={{ width: '100%' }}>
{/* Stats Row */}
<Box sx={{ display: 'flex', gap: 2, mb: 3 }}>
{/* Total Items */}
<Paper sx={{
flex: 1, p: 3, bgcolor: '#0f172a', border: '1px solid #1e293b', borderRadius: 2
}}>
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Total Items</Typography>
<Typography variant="h4" sx={{ color: '#3b82f6', fontWeight: 'bold' }}>
{loading ? '...' : stats.total.toLocaleString()}
</Typography>
</Paper>
{/* Audited */}
<Paper sx={{
flex: 1, p: 3, bgcolor: '#052e16', border: '1px solid #14532d', borderRadius: 2
}}>
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Audited</Typography>
<Typography variant="h4" sx={{ color: '#22c55e', fontWeight: 'bold' }}>
{loading ? '...' : stats.audited.toLocaleString()}
</Typography>
</Paper>
{/* Pending */}
<Paper sx={{
flex: 1, p: 3, bgcolor: '#422006', border: '1px solid #713f12', borderRadius: 2
}}>
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Pending</Typography>
<Typography variant="h4" sx={{ color: '#eab308', fontWeight: 'bold' }}>
{loading ? '...' : stats.pending.toLocaleString()}
</Typography>
</Paper>
{/* Anomalies Found */}
<Paper sx={{
flex: 1, p: 3, bgcolor: '#450a0a', border: '1px solid #7f1d1d', borderRadius: 2
}}>
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Anomalies Found</Typography>
<Typography variant="h4" sx={{ color: '#ef4444', fontWeight: 'bold' }}>
{loading ? '...' : stats.anomaliesFound.toLocaleString()}
</Typography>
</Paper>
</Box>
{/* Overall Progress */}
<Paper sx={{ p: 3, bgcolor: '#0f172a', border: '1px solid #1e293b', borderRadius: 2, mb: 3 }}>
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 1 }}>
<Typography variant="subtitle2" sx={{ fontWeight: 'bold', color: '#f8fafc' }}>Overall Progress</Typography>
<Typography variant="body2" sx={{ color: '#94a3b8' }}>{stats.audited} / {stats.total} completed</Typography>
</Box>
<LinearProgress
variant="determinate"
value={progressPercent}
sx={{
height: 10,
borderRadius: 5,
bgcolor: '#1e293b',
'& .MuiLinearProgress-bar': { bgcolor: '#3b82f6', borderRadius: 5 }
}}
/>
<Box sx={{ display: 'flex', justifyContent: 'space-between', mt: 1 }}>
<Typography variant="caption" sx={{ color: '#64748b' }}>{progressPercent}% complete</Typography>
<Typography variant="caption" sx={{ color: '#64748b' }}>~{Math.ceil(stats.pending / 50)} sessions remaining at 50/session</Typography>
</Box>
</Paper>
{/* Next Session Info */}
<Paper sx={{ p: 2, px: 3, bgcolor: '#0f172a', border: '1px solid #1e293b', borderRadius: 2, mb: 2 }}>
<Typography variant="body1" sx={{ color: '#f8fafc' }}>
<Typography component="span" sx={{ color: '#3b82f6', fontWeight: 'bold' }}>Next session:</Typography> 50 items will be queued ({stats.pending} pending total)
</Typography>
</Paper>
{/* Warning Box */}
<Paper sx={{ p: 2, px: 3, bgcolor: '#450a0a', border: '1px solid #7f1d1d', borderRadius: 2, mb: 4, display: 'flex', alignItems: 'center', gap: 1 }}>
<WarningAmberIcon sx={{ color: '#ef4444', fontSize: 20 }} />
<Typography variant="body1" sx={{ color: '#f8fafc' }}>
<Typography component="span" sx={{ color: '#ef4444', fontWeight: 'bold' }}>181 high-priority items</Typography> will appear first in the queue
</Typography>
</Paper>
{/* Start Button */}
<Button
variant="contained"
fullWidth
onClick={() => navigate('/audit-session')}
sx={{
py: 2,
bgcolor: '#3b82f6',
'&:hover': { bgcolor: '#2563eb' },
textTransform: 'none',
fontSize: '1.1rem',
fontWeight: 'bold',
borderRadius: 2
}}
>
Start Session Audit Next 50 Items
</Button>
{/* Footer links */}
<Box sx={{ display: 'flex', justifyContent: 'space-between', mt: 2 }}>
<Typography variant="caption" sx={{ color: '#475569' }}>Keyboard shortcuts available inside the audit view</Typography>
<Typography variant="caption" sx={{ color: '#64748b', textDecoration: 'underline', cursor: 'pointer', '&:hover': { color: '#f8fafc' } }}>Reset demo data</Typography>
</Box>
</Box>
</Box>
</Box>
);
};