FPSMS-frontend
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

164 Zeilen
4.9 KiB

  1. "use client";
  2. import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
  3. import {
  4. Box,
  5. Typography,
  6. FormControl,
  7. InputLabel,
  8. Select,
  9. MenuItem,
  10. Card,
  11. CardContent,
  12. Stack,
  13. Table,
  14. TableBody,
  15. TableCell,
  16. TableContainer,
  17. TableHead,
  18. TableRow,
  19. Paper,
  20. CircularProgress,
  21. Chip
  22. } from '@mui/material';
  23. import { useTranslation } from 'react-i18next';
  24. import dayjs from 'dayjs';
  25. interface GoodsReceiptStatusItem {
  26. id: string;
  27. }
  28. const GoodsReceiptStatus: React.FC = () => {
  29. const { t } = useTranslation("dashboard");
  30. const [selectedFilter, setSelectedFilter] = useState<string>("");
  31. const [data, setData] = useState<GoodsReceiptStatusItem[]>([]);
  32. const [loading, setLoading] = useState<boolean>(false);
  33. const [currentTime, setCurrentTime] = useState<dayjs.Dayjs | null>(null);
  34. const [isClient, setIsClient] = useState<boolean>(false);
  35. useEffect(() => {
  36. setIsClient(true);
  37. setCurrentTime(dayjs());
  38. }, []);
  39. const loadData = useCallback(async () => {
  40. try {
  41. setData([]);
  42. } catch (error) {
  43. console.error('Error fetching goods receipt status:', error);
  44. } finally {
  45. setLoading(false);
  46. }
  47. }, []);
  48. useEffect(() => {
  49. loadData();
  50. const refreshInterval = setInterval(() => {
  51. loadData();
  52. }, 5 * 60 * 1000);
  53. return () => clearInterval(refreshInterval);
  54. }, [loadData]);
  55. useEffect(() => {
  56. if (!isClient) return;
  57. const timeInterval = setInterval(() => {
  58. setCurrentTime(dayjs());
  59. }, 60 * 1000);
  60. return () => clearInterval(timeInterval);
  61. }, [isClient]);
  62. const filteredData = useMemo(() => {
  63. if (!selectedFilter) return data;
  64. return data.filter(item => true);
  65. }, [data, selectedFilter]);
  66. return (
  67. <Card sx={{ mb: 2 }}>
  68. <CardContent>
  69. {/* Filter */}
  70. <Stack direction="row" spacing={2} sx={{ mb: 3 }}>
  71. <FormControl sx={{ minWidth: 150 }} size="small">
  72. <InputLabel id="filter-select-label" shrink={true}>
  73. {t("Filter")}
  74. </InputLabel>
  75. <Select
  76. labelId="filter-select-label"
  77. id="filter-select"
  78. value={selectedFilter}
  79. label={t("Filter")}
  80. onChange={(e) => setSelectedFilter(e.target.value)}
  81. displayEmpty
  82. >
  83. <MenuItem value="">{t("All")}</MenuItem>
  84. {/* TODO: Add filter options when implementing */}
  85. </Select>
  86. </FormControl>
  87. <Typography variant="body2" sx={{ alignSelf: 'center', color: 'text.secondary' }}>
  88. {t("Auto-refresh every 5 minutes")} | {t("Last updated")}: {isClient && currentTime ? currentTime.format('HH:mm:ss') : '--:--:--'}
  89. </Typography>
  90. </Stack>
  91. {/* Table */}
  92. <Box sx={{ mt: 2 }}>
  93. {loading ? (
  94. <Box sx={{ display: 'flex', justifyContent: 'center', p: 3 }}>
  95. <CircularProgress />
  96. </Box>
  97. ) : (
  98. <TableContainer component={Paper}>
  99. <Table size="small" sx={{ minWidth: 1200 }}>
  100. <TableHead>
  101. <TableRow sx={{ backgroundColor: 'grey.100' }}>
  102. <TableCell sx={{ fontWeight: 600 }}>{t("Column 1")}</TableCell>
  103. <TableCell sx={{ fontWeight: 600 }}>{t("Column 2")}</TableCell>
  104. <TableCell sx={{ fontWeight: 600 }}>{t("Column 3")}</TableCell>
  105. {/* TODO: Add table columns when implementing */}
  106. </TableRow>
  107. </TableHead>
  108. <TableBody>
  109. {filteredData.length === 0 ? (
  110. <TableRow>
  111. <TableCell colSpan={3} align="center">
  112. <Typography variant="body2" color="text.secondary">
  113. {t("No data available")}
  114. </Typography>
  115. </TableCell>
  116. </TableRow>
  117. ) : (
  118. filteredData.map((row, index) => (
  119. <TableRow
  120. key={row.id || index}
  121. sx={{
  122. '&:hover': { backgroundColor: 'grey.50' }
  123. }}
  124. >
  125. <TableCell>
  126. {/* TODO: Add table cell content when implementing */}
  127. -
  128. </TableCell>
  129. <TableCell>
  130. -
  131. </TableCell>
  132. <TableCell>
  133. -
  134. </TableCell>
  135. </TableRow>
  136. ))
  137. )}
  138. </TableBody>
  139. </Table>
  140. </TableContainer>
  141. )}
  142. </Box>
  143. </CardContent>
  144. </Card>
  145. );
  146. };
  147. export default GoodsReceiptStatus;