FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

179 lines
6.1 KiB

  1. import React, { useState, ChangeEvent, FormEvent, Dispatch } from 'react';
  2. import {
  3. Box,
  4. Button,
  5. Collapse,
  6. FormControl,
  7. InputLabel,
  8. Select,
  9. MenuItem,
  10. TextField,
  11. Checkbox,
  12. FormControlLabel,
  13. Paper,
  14. Typography,
  15. RadioGroup,
  16. Radio,
  17. Stack,
  18. Autocomplete,
  19. } from '@mui/material';
  20. import { SelectChangeEvent } from '@mui/material/Select';
  21. import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
  22. import ExpandLessIcon from '@mui/icons-material/ExpandLess';
  23. import { useTranslation } from 'react-i18next';
  24. interface NameOption {
  25. value: string;
  26. label: string;
  27. }
  28. interface FormData {
  29. name: string;
  30. quantity: string;
  31. message: string;
  32. }
  33. interface Props {
  34. forSupervisor: boolean
  35. isCollapsed: boolean
  36. setIsCollapsed: Dispatch<React.SetStateAction<boolean>>
  37. }
  38. const EscalationComponent: React.FC<Props> = ({
  39. forSupervisor,
  40. isCollapsed,
  41. setIsCollapsed
  42. }) => {
  43. const { t } = useTranslation("purchaseOrder");
  44. const [formData, setFormData] = useState<FormData>({
  45. name: '',
  46. quantity: '',
  47. message: '',
  48. });
  49. const nameOptions: NameOption[] = [
  50. { value: '', label: '請選擇姓名...' },
  51. { value: 'john', label: '張大明' },
  52. { value: 'jane', label: '李小美' },
  53. { value: 'mike', label: '王志強' },
  54. { value: 'sarah', label: '陳淑華' },
  55. { value: 'david', label: '林建國' },
  56. ];
  57. const handleInputChange = (
  58. event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | SelectChangeEvent<string>
  59. ): void => {
  60. const { name, value } = event.target;
  61. setFormData((prev) => ({
  62. ...prev,
  63. [name]: value,
  64. }));
  65. };
  66. const handleSubmit = (e: FormEvent<HTMLFormElement>): void => {
  67. e.preventDefault();
  68. console.log('表單已提交:', formData);
  69. // 處理表單提交
  70. };
  71. const handleCollapseToggle = (e: ChangeEvent<HTMLInputElement>): void => {
  72. setIsCollapsed(e.target.checked);
  73. };
  74. return (
  75. // <Paper elevation={3} sx={{ maxWidth: 400, mx: 'auto', p: 3 }}>
  76. <>
  77. <Paper>
  78. {/* <Paper elevation={3} sx={{ mx: 'auto', p: 3 }}> */}
  79. <Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
  80. <FormControlLabel
  81. control={
  82. <Checkbox
  83. checked={isCollapsed}
  84. onChange={handleCollapseToggle}
  85. color="primary"
  86. />
  87. }
  88. label={
  89. <Box sx={{ display: 'flex', alignItems: 'center' }}>
  90. <Typography variant="body1">上報結果</Typography>
  91. {isCollapsed ? (
  92. <ExpandLessIcon sx={{ ml: 1 }} />
  93. ) : (
  94. <ExpandMoreIcon sx={{ ml: 1 }} />
  95. )}
  96. </Box>
  97. }
  98. />
  99. </Box>
  100. <Collapse in={isCollapsed}>
  101. <Box component="form" onSubmit={handleSubmit} sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
  102. {forSupervisor ? (
  103. <FormControl>
  104. <RadioGroup
  105. row
  106. aria-labelledby="demo-radio-buttons-group-label"
  107. defaultValue="pass"
  108. name="radio-buttons-group"
  109. >
  110. <FormControlLabel value="pass" control={<Radio />} label="合格" />
  111. <FormControlLabel value="fail" control={<Radio />} label="不合格" />
  112. </RadioGroup>
  113. </FormControl>
  114. ): undefined}
  115. <FormControl fullWidth>
  116. <select
  117. id="name"
  118. name="name"
  119. value={formData.name}
  120. onChange={handleInputChange}
  121. className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white"
  122. >
  123. {nameOptions.map((option: NameOption) => (
  124. <option key={option.value} value={option.value}>
  125. {option.label}
  126. </option>
  127. ))}
  128. </select>
  129. </FormControl>
  130. <TextField
  131. fullWidth
  132. id="quantity"
  133. name="quantity"
  134. label="數量"
  135. type="number"
  136. value={formData.quantity}
  137. onChange={handleInputChange}
  138. InputProps={{ inputProps: { min: 1 } }}
  139. placeholder="請輸入數量"
  140. />
  141. <TextField
  142. fullWidth
  143. id="message"
  144. name="message"
  145. label="備註"
  146. multiline
  147. rows={4}
  148. value={formData.message}
  149. onChange={handleInputChange}
  150. placeholder="請輸入您的備註"
  151. />
  152. <Stack direction="row" justifyContent="flex-end" gap={1}>
  153. <Button
  154. type="submit"
  155. variant="contained"
  156. color="primary"
  157. >
  158. {t("update qc info")}
  159. </Button>
  160. </Stack>
  161. </Box>
  162. </Collapse>
  163. </Paper>
  164. </>
  165. );
  166. }
  167. export default EscalationComponent;