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.
 
 

201 Zeilen
4.9 KiB

  1. "use client";
  2. import { QcItemInfo } from "@/app/api/settings/qcCategory";
  3. import {
  4. Box,
  5. Card,
  6. CircularProgress,
  7. Divider,
  8. List,
  9. ListItem,
  10. Stack,
  11. Typography,
  12. } from "@mui/material";
  13. import { CheckCircleOutline, FormatListNumbered } from "@mui/icons-material";
  14. import { useTranslation } from "react-i18next";
  15. type Props = {
  16. qcItems: QcItemInfo[];
  17. loading?: boolean;
  18. categorySelected?: boolean;
  19. };
  20. const QcItemsList: React.FC<Props> = ({
  21. qcItems,
  22. loading = false,
  23. categorySelected = false,
  24. }) => {
  25. const { t } = useTranslation("items");
  26. // Sort items by order
  27. const sortedItems = [...qcItems].sort((a, b) => a.order - b.order);
  28. if (loading) {
  29. return (
  30. <Box
  31. display="flex"
  32. justifyContent="center"
  33. alignItems="center"
  34. py={4}
  35. sx={{
  36. backgroundColor: "grey.50",
  37. borderRadius: 2,
  38. border: "1px dashed",
  39. borderColor: "grey.300",
  40. }}
  41. >
  42. <CircularProgress size={24} sx={{ mr: 1.5 }} />
  43. <Typography variant="body2" color="text.secondary">
  44. {t("Loading QC items...")}
  45. </Typography>
  46. </Box>
  47. );
  48. }
  49. if (!categorySelected) {
  50. return (
  51. <Box
  52. display="flex"
  53. flexDirection="column"
  54. alignItems="center"
  55. py={4}
  56. sx={{
  57. backgroundColor: "grey.50",
  58. borderRadius: 2,
  59. border: "1px dashed",
  60. borderColor: "grey.300",
  61. }}
  62. >
  63. <FormatListNumbered
  64. sx={{ fontSize: 40, color: "grey.400", mb: 1 }}
  65. />
  66. <Typography variant="body2" color="text.secondary">
  67. {t("Select a QC template to view items")}
  68. </Typography>
  69. </Box>
  70. );
  71. }
  72. if (sortedItems.length === 0) {
  73. return (
  74. <Box
  75. display="flex"
  76. flexDirection="column"
  77. alignItems="center"
  78. py={4}
  79. sx={{
  80. backgroundColor: "grey.50",
  81. borderRadius: 2,
  82. border: "1px dashed",
  83. borderColor: "grey.300",
  84. }}
  85. >
  86. <CheckCircleOutline
  87. sx={{ fontSize: 40, color: "grey.400", mb: 1 }}
  88. />
  89. <Typography variant="body2" color="text.secondary">
  90. {t("No QC items in this template")}
  91. </Typography>
  92. </Box>
  93. );
  94. }
  95. return (
  96. <Card
  97. variant="outlined"
  98. sx={{
  99. borderRadius: 2,
  100. backgroundColor: "background.paper",
  101. overflow: "hidden",
  102. }}
  103. >
  104. <Box
  105. sx={{
  106. px: 2,
  107. py: 1.5,
  108. backgroundColor: "primary.main",
  109. color: "primary.contrastText",
  110. }}
  111. >
  112. <Stack direction="row" alignItems="center" spacing={1}>
  113. <FormatListNumbered fontSize="small" />
  114. <Typography variant="subtitle2" fontWeight={600}>
  115. {t("QC Checklist")} ({sortedItems.length})
  116. </Typography>
  117. </Stack>
  118. </Box>
  119. <List disablePadding>
  120. {sortedItems.map((item, index) => (
  121. <Box key={item.id}>
  122. {index > 0 && <Divider />}
  123. <ListItem
  124. sx={{
  125. py: 1.5,
  126. px: 2,
  127. "&:hover": {
  128. backgroundColor: "action.hover",
  129. },
  130. }}
  131. >
  132. <Stack
  133. direction="row"
  134. spacing={2}
  135. alignItems="flex-start"
  136. width="100%"
  137. >
  138. {/* Order Number */}
  139. <Typography
  140. variant="body1"
  141. fontWeight={600}
  142. color="text.secondary"
  143. sx={{ minWidth: 24 }}
  144. >
  145. {item.order}.
  146. </Typography>
  147. {/* Content */}
  148. <Stack
  149. direction="row"
  150. alignItems="center"
  151. spacing={2}
  152. flex={1}
  153. minWidth={0}
  154. >
  155. <Typography
  156. variant="body1"
  157. fontWeight={500}
  158. sx={{
  159. overflow: "hidden",
  160. textOverflow: "ellipsis",
  161. whiteSpace: "nowrap",
  162. flexShrink: 0,
  163. }}
  164. >
  165. {item.name || item.code}
  166. </Typography>
  167. {item.description && (
  168. <Typography
  169. variant="body2"
  170. color="text.secondary"
  171. sx={{
  172. overflow: "hidden",
  173. textOverflow: "ellipsis",
  174. whiteSpace: "nowrap",
  175. }}
  176. >
  177. {item.description}
  178. </Typography>
  179. )}
  180. </Stack>
  181. </Stack>
  182. </ListItem>
  183. </Box>
  184. ))}
  185. </List>
  186. </Card>
  187. );
  188. };
  189. export default QcItemsList;