您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

162 行
7.9 KiB

  1. // material-ui
  2. import {
  3. FormControl,
  4. Button,
  5. Grid,
  6. // InputAdornment,
  7. Typography, FormLabel,
  8. OutlinedInput,
  9. TextField,
  10. } from '@mui/material';
  11. import MainCard from "components/MainCard";
  12. import * as React from "react";
  13. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  14. const Form = ({ selectedItem, onSave }) => {
  15. const [data, setData] = React.useState({});
  16. const [value, setValue] = React.useState("");
  17. const [valueErr, setValueErr] = React.useState("");
  18. React.useEffect(() => {
  19. //if user data from parent are not null
  20. if (selectedItem !== undefined && Object.keys(selectedItem).length > 0) {
  21. setData(selectedItem);
  22. setValue(selectedItem.value)
  23. }
  24. }, [selectedItem]);
  25. return (
  26. <MainCard elevation={0}
  27. border={false}
  28. content={false}
  29. >
  30. {
  31. data?.name ?
  32. <>
  33. <Typography variant="h5" sx={{ mt: 3, ml: 3, mr: 3, borderBottom: "1px solid black" }}>
  34. Update
  35. </Typography>
  36. <form>
  37. <Grid container>
  38. <Grid item xs={12} s={12} md={12} lg={12} sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
  39. <Grid container alignItems={"center"}>
  40. <Grid item xs={2}
  41. sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}>
  42. <FormLabel>Name:</FormLabel>
  43. </Grid>
  44. <Grid item xs={8} >
  45. <Typography>
  46. {data?.name}
  47. </Typography>
  48. </Grid>
  49. </Grid>
  50. </Grid>
  51. <Grid item xs={12} s={12} md={12} lg={12} sx={{ ml: 3, mr: 3, mb: 3 }}>
  52. <Grid container alignItems={"center"}>
  53. <Grid item xs={2}
  54. sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}>
  55. <FormLabel >Type:</FormLabel>
  56. </Grid>
  57. <Grid item xs={8}>
  58. <Typography>
  59. {data?.type}
  60. </Typography>
  61. </Grid>
  62. </Grid>
  63. </Grid>
  64. <Grid item xs={12} s={12} md={12} lg={12} sx={{ ml: 3, mr: 3, mb: 3 }}>
  65. <Grid container alignItems={"center"}>
  66. <Grid item xs={2}
  67. sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}>
  68. <FormLabel>Category:</FormLabel>
  69. </Grid>
  70. <Grid item xs={8}>
  71. <Typography>
  72. {data?.category}
  73. </Typography>
  74. </Grid>
  75. </Grid>
  76. </Grid>
  77. <Grid item xs={12} s={12} md={12} lg={12} sx={{ ml: 3, mr: 3, mb: 3 }}>
  78. <Grid container alignItems={"center"}>
  79. <Grid item xs={12}
  80. sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'top' }}>
  81. <FormLabel>Value:</FormLabel>
  82. </Grid>
  83. <Grid item xs={12} sx={{ ml: 3, mr: 3 }}>
  84. <FormControl variant="outlined" fullWidth required>
  85. {
  86. data?.type != "HTML" ?
  87. <OutlinedInput
  88. fullWidth
  89. size="small"
  90. value={value}
  91. error={valueErr}
  92. onChange={(event) => {
  93. setValueErr("");
  94. setValue(event.target.value);
  95. }}
  96. />
  97. :
  98. <TextField
  99. variant="outlined"
  100. multiline
  101. rows={15}
  102. value={value}
  103. inputComponent='textarea'
  104. error={valueErr}
  105. onChange={(event) => {
  106. setValue(event.target.value);
  107. if (event.target.value.length >= 1000) {
  108. setValueErr("The number of characters cannot exceed 1000 words.");
  109. return;
  110. }
  111. setValueErr("");
  112. }}
  113. InputProps={
  114. {
  115. style: { minHeight: '42.5px', maxHeight: '50vh', height: 'auto' },
  116. }
  117. }
  118. />
  119. }
  120. <span style={{ color: "red" }}>{valueErr}</span>
  121. </FormControl>
  122. </Grid>
  123. </Grid>
  124. </Grid>
  125. </Grid>
  126. <Button onClick={() => {
  127. if (valueErr.length > 0) return;
  128. onSave({ name: data.name, value: value })
  129. }}>Save</Button>
  130. </form>
  131. </>
  132. :
  133. <Typography variant="h5" sx={{ mt: 3, ml: 3, mr: 3, borderBottom: "1px solid black" }}>
  134. Please select system params.
  135. </Typography>
  136. }
  137. </MainCard>
  138. );
  139. };
  140. export default Form;