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

183 行
7.3 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid,
  5. TextField,
  6. Autocomplete,
  7. Typography
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import { useForm } from "react-hook-form";
  11. import * as React from "react";
  12. // import * as DateUtils from "utils/DateUtils";
  13. import {PNSPS_BUTTON_THEME} from "themes/buttonConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. import { GeneralConfirmWindow } from "utils/CommonFunction";
  16. import { isGrantedAny } from "auth/utils";
  17. // import * as ComboData from "utils/ComboData";
  18. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const SearchHolidayForm = ({ applySearch, comboData, searchCriteria, onGridReady, onDeleteYear, waitDelete }) => {
  20. const [selectedYear, setSelectedYear] = React.useState(null);
  21. // const [defaultYear, setDefaultYear] = React.useState(searchCriteria.year);
  22. const [comboList, setComboList] = React.useState([]);
  23. const [isConfirmOpen, setIsConfirmOpen] = React.useState(false);
  24. // const [onReady, setOnReady] = React.useState(false);
  25. const {
  26. // register,
  27. handleSubmit } = useForm()
  28. const onSubmit = () => {
  29. if (selectedYear != null) {
  30. const temp = {
  31. year: selectedYear.label,
  32. };
  33. applySearch(temp);
  34. }
  35. };
  36. React.useEffect(() => {
  37. const nextCombo = Array.isArray(comboData) ? [...comboData] : [];
  38. setComboList(nextCombo);
  39. if (nextCombo.length === 0) {
  40. setSelectedYear(null);
  41. return;
  42. }
  43. const criteriaYear = searchCriteria?.year;
  44. const matchedByCriteria = criteriaYear != null
  45. ? nextCombo.find((obj) => String(obj.label) === String(criteriaYear))
  46. : null;
  47. if (matchedByCriteria) {
  48. setSelectedYear(matchedByCriteria);
  49. return;
  50. }
  51. const matchedBySelected = selectedYear
  52. ? nextCombo.find((obj) => String(obj.label) === String(selectedYear.label))
  53. : null;
  54. setSelectedYear(matchedBySelected || nextCombo[0]);
  55. }, [comboData, searchCriteria]);
  56. return (
  57. <MainCard xs={12} md={12} lg={12}
  58. border={false}
  59. content={false}
  60. >
  61. <form onSubmit={handleSubmit(onSubmit)} >
  62. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  63. {/*row 1*/}
  64. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:1}}>
  65. <Typography variant="h5" >
  66. Year
  67. </Typography>
  68. </Grid>
  69. {/*row 2*/}
  70. <Grid container display="flex" alignItems={"center"}>
  71. <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}>
  72. <Autocomplete
  73. disablePortal
  74. id="year-combo"
  75. value={selectedYear}
  76. // defaultValue={selectedYear}
  77. options={comboList}
  78. // disabled={checkCountry}
  79. getOptionLabel={(option) =>
  80. option != null && typeof option === "object" && option.label != null
  81. ? String(option.label)
  82. : ""
  83. }
  84. isOptionEqualToValue={(option, value) =>
  85. String(option?.label) === String(value?.label)
  86. }
  87. onChange={(event, newValue) => {
  88. setSelectedYear(newValue);
  89. }}
  90. sx={{
  91. '& .MuiInputBase-root': { alignItems: 'center' },
  92. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  93. '& .MuiOutlinedInput-root': { height: 40 }
  94. }}
  95. renderInput={(params) => <TextField {...params} placeholder={""}/>}
  96. />
  97. </Grid>
  98. {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ?
  99. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  100. <Grid item sx={{ mb: 3, mr: 3 }}>
  101. <Button
  102. color="delete"
  103. variant="contained"
  104. disabled={!selectedYear || waitDelete || onGridReady}
  105. onClick={() => setIsConfirmOpen(true)}
  106. >
  107. Delete
  108. </Button>
  109. </Grid>
  110. </ThemeProvider>
  111. : null
  112. }
  113. <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}>
  114. {/* <TextField
  115. fullWidth
  116. InputLabelProps={{
  117. shrink: true
  118. }}
  119. {...register("dateTo")}
  120. InputProps={{ inputProps: { min: minDate } }}
  121. onChange={(newValue) => {
  122. setMaxDate(DateUtils.dateValue(newValue));
  123. }}
  124. id="dateTo"
  125. type="date"
  126. label="To"
  127. defaultValue={searchCriteria.dateTo}
  128. /> */}
  129. </Grid>
  130. {/* <Grid item xs={9} s={6} md={4} lg={3}>
  131. </Grid> */}
  132. </Grid>
  133. <Grid container justifyContent="flex-end" direction="row" alignItems="center" spacing={3}>
  134. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  135. <Grid item sx={{ ml: 3, mb: 3, }} >
  136. <Button
  137. variant="contained"
  138. type="submit"
  139. disabled={onGridReady}
  140. >
  141. Search
  142. </Button>
  143. </Grid>
  144. </ThemeProvider>
  145. </Grid>
  146. </Grid>
  147. </form>
  148. <GeneralConfirmWindow
  149. isWindowOpen={isConfirmOpen}
  150. title="Confirm Delete"
  151. content={selectedYear
  152. ? `Confirm to delete all holidays of year ${selectedYear.label}?`
  153. : "Confirm to delete all holidays of the selected year?"}
  154. onNormalClose={() => setIsConfirmOpen(false)}
  155. onConfirmClose={() => {
  156. setIsConfirmOpen(false);
  157. if (selectedYear != null && onDeleteYear) {
  158. onDeleteYear(selectedYear.label);
  159. }
  160. }}
  161. />
  162. </MainCard>
  163. );
  164. };
  165. export default SearchHolidayForm;