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.
 
 

159 line
5.5 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Box,
  7. Button
  8. } from '@mui/material';
  9. import * as UrlUtils from "utils/ApiPathConst";
  10. import * as React from "react";
  11. import ForwardIcon from '@mui/icons-material/Forward';
  12. import Loadable from 'components/Loadable';
  13. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  14. const EmailTemplate = Loadable(React.lazy(() => import('pages/EmailTemplate/Detail_GLD/EmailTemplateDetails')))
  15. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  16. import { useParams } from 'react-router-dom';
  17. import { useNavigate } from 'react-router-dom';
  18. import axios from 'axios';
  19. import { notifyDeleteSuccess, notifySaveSuccess } from 'utils/CommonFunction';
  20. const BackgroundHead = {
  21. backgroundImage: `url(${titleBackgroundImg})`,
  22. width: '100%',
  23. height: '100%',
  24. backgroundSize: 'contain',
  25. backgroundRepeat: 'no-repeat',
  26. backgroundColor: '#0C489E',
  27. backgroundPosition: 'right'
  28. }
  29. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  30. const Index = () => {
  31. const [record, setRecord] = React.useState(null);
  32. const [onReady, setOnReady] = React.useState(false);
  33. const params = useParams()
  34. const navigate = useNavigate()
  35. React.useLayoutEffect(() => {
  36. loadForm();
  37. }, []);
  38. React.useLayoutEffect(() => {
  39. if(record !== null || params.id <= 0) setOnReady(true);
  40. }, [record]);
  41. const loadForm = () => {
  42. if (params.id > 0) {
  43. axios.get(`${UrlUtils.GET_EMAIL}/${params.id}`)
  44. .then((response) => {
  45. if (response.status === 200) {
  46. console.log(response)
  47. setRecord(response.data.data)
  48. }
  49. })
  50. .catch(error => {
  51. console.log(error);
  52. return false;
  53. });
  54. }
  55. // HttpUtils.get({
  56. // url: UrlUtils.GET_EMAIL,
  57. // params: {
  58. // id: params.id
  59. // },
  60. // onSuccess: (responseData) => {
  61. // setRecord(responseData);
  62. // }
  63. // });
  64. }
  65. const onSubmit = (data) => {
  66. axios.post(`${UrlUtils.POST_EMAIL_SAVE}`,
  67. {
  68. id: params.id > 0 ? params.id : null,
  69. contentChs: data?.contentChs,
  70. contentCht: data?.contentCht,
  71. contentEng: data?.contentEng,
  72. description: data?.description,
  73. tempKey: data?.tempKey,
  74. params: data?.params,
  75. subjectChs: data?.subjectChs,
  76. subjectCht: data?.subjectCht,
  77. subjectEng: data?.subjectEng
  78. }
  79. ).then((response) => {
  80. if (response.status === 200) {
  81. // location.reload();
  82. navigate('/emailTemplate')
  83. notifySaveSuccess()
  84. }
  85. })
  86. .catch(error => {
  87. console.log(error);
  88. return false;
  89. });
  90. console.log(data)
  91. }
  92. const handleDelete = () => {
  93. axios.delete(`${UrlUtils.DELETE_EMAIL}/${params.id}`,
  94. )
  95. .then((response) => {
  96. console.log(response)
  97. if (response.status === 204) {
  98. // location.reload();
  99. navigate('/emailTemplate');
  100. notifyDeleteSuccess()
  101. }
  102. })
  103. .catch(error => {
  104. console.log(error);
  105. return false;
  106. });
  107. }
  108. return (
  109. !onReady ?
  110. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  111. <Grid item>
  112. <LoadingComponent />
  113. </Grid>
  114. </Grid>
  115. :
  116. (
  117. <Grid container sx={{ minHeight: '110vh', backgroundColor: 'backgroundColor.default' }} direction="column" justifyContent="flex-start" alignItems="center" >
  118. <Grid item xs={12} width="100%">
  119. <div style={BackgroundHead} width="100%">
  120. <Stack direction="row" height='70px'>
  121. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>Email Template</Typography>
  122. </Stack>
  123. </div>
  124. </Grid>
  125. <Grid item xs={12} width="100%">
  126. <Button title="Back" sx={{ ml: 6, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}>
  127. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  128. </Button>
  129. </Grid>
  130. {/*row 1*/}
  131. <Grid item xs={12} md={12} width="100%">
  132. <Grid item xs={12} md={12} sx={{ pt: 2, ml: 6, mr: 6, mb: 6}}>
  133. <Box xs={12} md={12} sx={{ p: 4, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  134. <EmailTemplate
  135. formData={record}
  136. _onSubmit={onSubmit}
  137. handleDelete={handleDelete}
  138. />
  139. </Box>
  140. </Grid>
  141. </Grid>
  142. {/*row 2*/}
  143. </Grid >
  144. )
  145. );
  146. };
  147. export default Index;