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.

232 lines
11 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Button,
  6. // RadioGroup,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. Stack,
  9. InputLabel,
  10. // OutlinedInput,
  11. FormHelperText,
  12. TextField,
  13. // Box
  14. } from '@mui/material';
  15. import { useFormik } from 'formik';
  16. import * as yup from 'yup';
  17. import * as React from "react";
  18. import * as HttpUtils from "utils/HttpUtils";
  19. import * as UrlUtils from "utils/ApiPathConst";
  20. // import * as FieldUtils from "utils/FieldUtils";
  21. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  22. import ForwardIcon from '@mui/icons-material/Forward';
  23. import MainCard from 'components/MainCard';
  24. import { useNavigate } from "react-router-dom";
  25. // import { notifyActionSuccess } from 'utils/CommonFunction';
  26. import {PNSPS_LONG_BUTTON_THEME} from "themes/buttonConst";
  27. import {ThemeProvider} from "@emotion/react";
  28. import {FormattedMessage, useIntl} from "react-intl";
  29. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  30. const ForgotUsernameApplyForm = () => {
  31. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  32. const [isSubmitting, setIsSubmitting] = React.useState(false);
  33. const submittingRef = React.useRef(false);
  34. // const [warningText, setWarningText] = React.useState("");s
  35. // const [attachment, setAttachment] = React.useState({});
  36. const intl = useIntl();
  37. // const [issueId, setIssueId] = React.useState(loadedData.issueId);
  38. const navigate = useNavigate();
  39. const BackgroundHead = {
  40. backgroundImage: `url(${titleBackgroundImg})`,
  41. width: 'auto',
  42. height: 'auto',
  43. backgroundSize: 'contain',
  44. backgroundRepeat: 'no-repeat',
  45. backgroundColor: '#0C489E',
  46. backgroundPosition: 'right'
  47. }
  48. const formik = useFormik({
  49. enableReinitialize: true,
  50. initialValues: {
  51. // username: '',
  52. emailAddress: '',
  53. },
  54. validationSchema: yup.object().shape({
  55. // username: yup.string().required(intl.formatMessage({id: 'requireUsername'})),
  56. emailAddress: yup.string().email(intl.formatMessage({id: 'validEmailFormat'})).max(255).required(intl.formatMessage({id: 'requireEmail'})),
  57. }),
  58. onSubmit: values => {
  59. if (submittingRef.current) return;
  60. submittingRef.current = true;
  61. // console.log(values)
  62. setIsSubmitting(true);
  63. HttpUtils.post({
  64. url: UrlUtils.POST_FORGOT_USERNAME_EMAIL,
  65. params: {
  66. emailAddress: values.emailAddress,
  67. },
  68. // files: [attachment],
  69. onSuccess: function () {
  70. submittingRef.current = false;
  71. setIsSubmitting(false);
  72. // notifyActionSuccess(intl.formatMessage({id: 'submissionSuccess'}) + '!')
  73. navigate('/forgot/username/sent');
  74. // location.reload();
  75. },
  76. onError: function () {
  77. submittingRef.current = false;
  78. setIsSubmitting(false);
  79. navigate('/forgot/username/sent');
  80. }
  81. });
  82. }
  83. });
  84. return (
  85. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" alignItems="center">
  86. <Grid item xs={12} md={12} width="100%" >
  87. <div style={BackgroundHead}>
  88. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  89. <Typography component="h1" ml={15} color='#FFF' variant="h4" sx={{display: { xs: 'none', sm: 'none', md: 'block' }}}>
  90. <FormattedMessage id="forgotUsername"/>
  91. </Typography>
  92. </Stack>
  93. </div>
  94. </Grid>
  95. <Grid item xs={12} width={{xs:"90%", sm:"90%", md:"60%", lg:"60%"}}>
  96. <Button
  97. aria-label={intl.formatMessage({id: 'back'})}
  98. title={intl.formatMessage({id: 'back'})}
  99. sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}
  100. >
  101. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  102. </Button>
  103. </Grid>
  104. <Grid item xs={12} md={12} width={{ md: "60%", xs: "90%" }}>
  105. <MainCard
  106. sx={{
  107. maxWidth: { xs: 400, sm:600, md:800, lg: 1000 },
  108. margin: { sm: 2.5, md: 3 },
  109. '& > *': {
  110. flexGrow: 1,
  111. flexBasis: '50%'
  112. }
  113. }}
  114. content={false}
  115. border={false}
  116. boxShadow
  117. >
  118. <form onSubmit={formik.handleSubmit}>
  119. <Grid container spacing={2} sx={{ minHeight: '40vh' }} direction="column" justifyContent="flex-start" alignItems="center">
  120. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, mt:5, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  121. <InputLabel htmlFor="email-login-title">
  122. <Typography variant="h5" component="span">
  123. <FormattedMessage id="forgotUsernameSubTitle"/>
  124. </Typography>
  125. </InputLabel>
  126. </Grid>
  127. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, mt:5, display: { md: 'none', xl: 'none', lg: 'none' } }}>
  128. <InputLabel htmlFor="email-login-subtitle">
  129. <Typography variant="h6" component="span">
  130. <FormattedMessage id="forgotUsernameSubTitle1"/>
  131. </Typography>
  132. <Typography variant="h6" component="span">
  133. <FormattedMessage id="forgotPasswordSubTitle2"/>
  134. </Typography>
  135. </InputLabel>
  136. </Grid>
  137. <Grid item xs={12} md={12} lg={12} width={{xs:"70%", sm:"60%",md:"50%", lg:"50%"}}>
  138. <Grid container direction="row" justifyContent="flex-start">
  139. <Grid item xs={12} md={12} lg={12} sx={{ mb: 3}} >
  140. <TextField
  141. fullWidth
  142. autoFocus
  143. onChange={formik.handleChange}
  144. id="emailAddress"
  145. name="emailAddress"
  146. placeholder={intl.formatMessage({id: 'userContactEmail'})}
  147. label={intl.formatMessage({id: 'userContactEmail'}) + ":"}
  148. defaultValue={formik.values.emailAddress}
  149. value={formik.values.emailAddress}
  150. error={Boolean(formik.touched.emailAddress && formik.errors.emailAddress)}
  151. onBlur={formik.handleBlur}
  152. inputProps={{
  153. "aria-describedby" : 'standard-weight-helper-text-emailAddress-login',
  154. "aria-label": intl.formatMessage({id: 'userContactEmail'}),
  155. maxLength: 50,
  156. onKeyDown: (e) => {
  157. if (e.key === 'Enter') {
  158. e.preventDefault();
  159. }
  160. },
  161. }}
  162. InputLabelProps={{
  163. shrink: true
  164. }}
  165. />
  166. </Grid>
  167. {formik.touched.emailAddress && formik.errors.emailAddress && (
  168. <FormHelperText error id="standard-weight-helper-text-emailAddress-login">
  169. {formik.errors.emailAddress}
  170. </FormHelperText>
  171. )}
  172. </Grid>
  173. </Grid>
  174. <Grid item xs={12} md={12} lg={12} mt={1}>
  175. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  176. <Button
  177. aria-label={intl.formatMessage({id: 'continue'})}
  178. variant="contained"
  179. type="submit"
  180. disabled={isSubmitting}
  181. >
  182. {isSubmitting ? <FormattedMessage id="loading"/> : <FormattedMessage id="continue"/>}
  183. </Button>
  184. </ThemeProvider>
  185. </Grid>
  186. </Grid>
  187. </form>
  188. </MainCard>
  189. </Grid>
  190. <div>
  191. <Dialog
  192. open={isWarningPopUp}
  193. onClose={() => setIsWarningPopUp(false)}
  194. PaperProps={{
  195. sx: {
  196. minWidth: '40vw',
  197. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  198. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  199. }
  200. }}
  201. >
  202. <DialogTitle>
  203. <FormattedMessage id="attention"/>
  204. </DialogTitle>
  205. <DialogContent style={{ display: 'flex', }}>
  206. {/* <Typography variant="h5"component="span" style={{ padding: '16px' }}>{warningText}</Typography> */}
  207. </DialogContent>
  208. <DialogActions>
  209. <Button
  210. aria-label={intl.formatMessage({id: 'close'})}
  211. onClick={() => setIsWarningPopUp(false)}
  212. >
  213. <FormattedMessage id="close" />
  214. </Button>
  215. </DialogActions>
  216. </Dialog>
  217. </div>
  218. </Grid>
  219. );
  220. };
  221. export default ForgotUsernameApplyForm;