|
|
@@ -15,6 +15,9 @@ import { |
|
|
Paper, |
|
|
Paper, |
|
|
CircularProgress, |
|
|
CircularProgress, |
|
|
TablePagination, |
|
|
TablePagination, |
|
|
|
|
|
FormControl, |
|
|
|
|
|
Select, |
|
|
|
|
|
MenuItem, |
|
|
} from '@mui/material'; |
|
|
} from '@mui/material'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
import dayjs from 'dayjs'; |
|
|
import dayjs from 'dayjs'; |
|
|
@@ -28,20 +31,18 @@ const MaterialPickStatusTable: React.FC = () => { |
|
|
const [data, setData] = useState<MaterialPickStatusItem[]>([]); |
|
|
const [data, setData] = useState<MaterialPickStatusItem[]>([]); |
|
|
const [loading, setLoading] = useState<boolean>(true); |
|
|
const [loading, setLoading] = useState<boolean>(true); |
|
|
const refreshCountRef = useRef<number>(0); |
|
|
const refreshCountRef = useRef<number>(0); |
|
|
|
|
|
const [selectedDate, setSelectedDate] = useState(dayjs().format("YYYY-MM-DD")); |
|
|
const [paginationController, setPaginationController] = useState({ |
|
|
const [paginationController, setPaginationController] = useState({ |
|
|
pageNum: 0, |
|
|
pageNum: 0, |
|
|
pageSize: 10, |
|
|
pageSize: 10, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const loadData = useCallback(async () => { |
|
|
const loadData = useCallback(async () => { |
|
|
setLoading(true); |
|
|
setLoading(true); |
|
|
try { |
|
|
try { |
|
|
const result = await fetchMaterialPickStatus(); |
|
|
|
|
|
// On second refresh, clear completed pick orders |
|
|
|
|
|
|
|
|
const result = await fetchMaterialPickStatus(selectedDate); |
|
|
if (refreshCountRef.current >= 1) { |
|
|
if (refreshCountRef.current >= 1) { |
|
|
// const filtered = result.filter(item => |
|
|
|
|
|
// item.pickStatus?.toLowerCase() !== 'completed' |
|
|
|
|
|
//); |
|
|
|
|
|
setData(result); |
|
|
setData(result); |
|
|
} else { |
|
|
} else { |
|
|
setData(result || []); |
|
|
setData(result || []); |
|
|
@@ -49,23 +50,19 @@ const MaterialPickStatusTable: React.FC = () => { |
|
|
refreshCountRef.current += 1; |
|
|
refreshCountRef.current += 1; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('Error fetching material pick status:', error); |
|
|
console.error('Error fetching material pick status:', error); |
|
|
setData([]); // Set empty array on error to stop loading |
|
|
|
|
|
|
|
|
setData([]); |
|
|
} finally { |
|
|
} finally { |
|
|
setLoading(false); |
|
|
setLoading(false); |
|
|
} |
|
|
} |
|
|
}, []); // Remove refreshCount from dependencies |
|
|
|
|
|
|
|
|
}, [selectedDate]); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
// Initial load |
|
|
|
|
|
loadData(); |
|
|
loadData(); |
|
|
|
|
|
|
|
|
// Set up auto-refresh every 10 minutes |
|
|
|
|
|
const interval = setInterval(() => { |
|
|
const interval = setInterval(() => { |
|
|
loadData(); |
|
|
loadData(); |
|
|
}, REFRESH_INTERVAL); |
|
|
}, REFRESH_INTERVAL); |
|
|
|
|
|
|
|
|
return () => clearInterval(interval); |
|
|
return () => clearInterval(interval); |
|
|
}, [loadData]); // Only depend on loadData, which is now stable |
|
|
|
|
|
|
|
|
}, [loadData]); |
|
|
|
|
|
|
|
|
const formatTime = (timeData: any): string => { |
|
|
const formatTime = (timeData: any): string => { |
|
|
if (!timeData) return ''; |
|
|
if (!timeData) return ''; |
|
|
@@ -235,10 +232,18 @@ const MaterialPickStatusTable: React.FC = () => { |
|
|
<Typography variant="h5" sx={{ fontWeight: 600 }}> |
|
|
<Typography variant="h5" sx={{ fontWeight: 600 }}> |
|
|
{t("Material Pick Status")} |
|
|
{t("Material Pick Status")} |
|
|
</Typography> |
|
|
</Typography> |
|
|
|
|
|
|
|
|
</Box> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormControl size="small" sx={{ minWidth: 160 }}> |
|
|
|
|
|
<Select |
|
|
|
|
|
value={selectedDate} |
|
|
|
|
|
onChange={(e) => setSelectedDate(e.target.value)} |
|
|
|
|
|
> |
|
|
|
|
|
<MenuItem value={dayjs().format("YYYY-MM-DD")}>{t("Today")}</MenuItem> |
|
|
|
|
|
<MenuItem value={dayjs().subtract(1, "day").format("YYYY-MM-DD")}>{t("Yesterday")}</MenuItem> |
|
|
|
|
|
<MenuItem value={dayjs().subtract(2, "day").format("YYYY-MM-DD")}>{t("Two Days Ago")}</MenuItem> |
|
|
|
|
|
</Select> |
|
|
|
|
|
</FormControl> |
|
|
|
|
|
</Box> |
|
|
|
|
|
|
|
|
<Box sx={{ mt: 2 }}> |
|
|
<Box sx={{ mt: 2 }}> |
|
|
{loading ? ( |
|
|
{loading ? ( |
|
|
|