25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

Register.js 9.1 KiB

1 yıl önce
2 yıl önce
2 yıl önce
1 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // import { Link } from 'react-router-dom';
  2. import React, {
  3. useState
  4. // ,useEffect
  5. } from 'react';
  6. // material-ui
  7. import {
  8. Stepper,
  9. Step,
  10. StepButton,
  11. // Grid,
  12. Stack,
  13. Typography,
  14. Button, StepLabel,
  15. } from '@mui/material';
  16. import VisibilityIcon from '@mui/icons-material/Visibility';
  17. import { POST_USERNAME, POST_VERIFY_CAPTCHA } from "utils/ApiPathConst";
  18. // project import
  19. import Loadable from 'components/Loadable';
  20. import { lazy } from 'react';
  21. import { notifyActionError } from 'utils/CommonFunction';
  22. import axios from "axios";
  23. import {FormattedMessage, useIntl} from "react-intl";
  24. import usePageTitle from "components/usePageTitle";
  25. const CustomFormWizard = Loadable(lazy(() => import('./auth-forms/CustomFormWizard')));
  26. const AuthWrapper = Loadable(lazy(() => import('./AuthWrapperCustom')));
  27. // ================================|| REGISTER ||================================ //
  28. const Register = () => {
  29. const [activeStep, setActiveStep] = useState(0);
  30. const [completed, setCompleted] = useState([false]);
  31. const [updateValid, setUpdateValid] = useState(false);
  32. const [username, setUsername] = useState("");
  33. const [base64Url, setBase64Url] = useState("")
  34. const [checkCode, setCheckCode] = useState("")
  35. const intl = useIntl();
  36. // Localized document title/meta for register flow
  37. usePageTitle("register");
  38. const steps = [
  39. intl.formatMessage({id: 'personalInformation'}),
  40. intl.formatMessage({id: 'preview'}),
  41. intl.formatMessage({id: 'finishSubmission'})
  42. ];
  43. const stepStyle = {
  44. width: { lg: "40%", md: "70%", xs: "100%" },
  45. boxShadow: 1,
  46. backgroundColor: "#FFFFFF",
  47. padding: 2,
  48. /* Inactive (default) */
  49. "& .MuiStepIcon-root": { color: "#757575", fontSize: "2rem" }, // darker grey
  50. "& .MuiStepLabel-label": { color: "#424242" }, // label darker
  51. "& .MuiStepConnector-line": { borderColor: "#9E9E9E" }, // connector darker
  52. /* Active */
  53. "& .Mui-active": {
  54. "&.MuiStepIcon-root": { color: "warning.main", fontSize: "2rem" },
  55. "& .MuiStepConnector-line": { borderColor: "warning.main" }
  56. },
  57. /* Completed */
  58. "& .Mui-completed": {
  59. "&.MuiStepIcon-root": { color: "#0C489E", fontSize: "2rem" }, // use your strong blue
  60. "& .MuiStepConnector-line": { borderColor: "#0C489E" }
  61. }
  62. };
  63. const totalSteps = () => {
  64. return steps.length;
  65. };
  66. const completedSteps = () => {
  67. return Object.keys(completed).length;
  68. };
  69. const isLastStep = () => {
  70. return activeStep === totalSteps() - 1;
  71. };
  72. const allStepsCompleted = () => {
  73. return completedSteps() === totalSteps();
  74. };
  75. const handleCheckUsername = async () => {
  76. const response = await axios.post(`${POST_USERNAME}`, {
  77. u1: username,
  78. })
  79. return Number(response.data[0]) > 0
  80. }
  81. const handleCaptcha = async () => {
  82. const response = await axios.post(`${POST_VERIFY_CAPTCHA}`, {
  83. captcha: base64Url,
  84. checkCode: checkCode,
  85. })
  86. return Boolean(response.data["success"]);
  87. }
  88. const handleNext = async () => {
  89. const captchaTest = await handleCaptcha();
  90. if (!captchaTest) {
  91. notifyActionError(intl.formatMessage({id: 'validVerify'}))
  92. return;
  93. }
  94. const test = await handleCheckUsername()
  95. if (test) {
  96. notifyActionError(intl.formatMessage({id: 'usernameTaken'}))
  97. } else {
  98. const newActiveStep =
  99. isLastStep() && !allStepsCompleted()
  100. ? // It's the last step, but not all steps have been completed,
  101. // find the first step that has been completed
  102. steps.findIndex((step, i) => !(i in completed))
  103. : activeStep + 1;
  104. setActiveStep(newActiveStep);
  105. scrollToTop();
  106. }
  107. };
  108. const handleBack = () => {
  109. scrollToTop();
  110. setActiveStep((prevActiveStep) => prevActiveStep - 1);
  111. };
  112. const scrollToTop = () => {
  113. window.scrollTo(0, 0);
  114. };
  115. const handleReset = () => {
  116. setActiveStep(0);
  117. setCompleted({});
  118. };
  119. return (
  120. // <AuthWrapper>
  121. <Stack sx={{ width: '100%', fontSize: '2rem', paddingTop: '35px', bgcolor: 'backgroundColor.default' }} alignItems="center">
  122. <Stepper activeStep={activeStep} sx={stepStyle}>
  123. {steps.map((label, index) => (
  124. <Step key={label} completed={completed[index]} readOnly={true}>
  125. {index < 2 ? (
  126. <StepButton
  127. aria-current={activeStep === index ? 'step' : undefined}
  128. // onClick={handleStep(index)}
  129. >
  130. <StepLabel
  131. sx={{
  132. flexDirection: 'column',
  133. "& .MuiStepLabel-iconContainer": { paddingRight: 0 }
  134. }}
  135. >
  136. <Typography variant="step1">{label}</Typography>
  137. </StepLabel>
  138. </StepButton>
  139. ) : (
  140. <StepButton
  141. aria-current={activeStep === index ? 'step' : undefined}
  142. sx={
  143. activeStep === 2
  144. ? { "& .MuiSvgIcon-root": { color: "warning.main", fontSize: "2rem" } }
  145. : allStepsCompleted()
  146. ? { "& .MuiSvgIcon-root": { color: "#0C489E", fontSize: "2rem" } }
  147. : { color: "rgba(0,0,0,0.6)" }
  148. }
  149. icon={<VisibilityIcon />}
  150. // onClick={handleStep(index)}
  151. >
  152. <StepLabel
  153. sx={{
  154. flexDirection: 'column',
  155. "& .MuiStepLabel-iconContainer": { paddingRight: 0 }
  156. }}
  157. >
  158. <Typography variant="step1">{label}</Typography>
  159. </StepLabel>
  160. </StepButton>
  161. )}
  162. </Step>
  163. ))}
  164. </Stepper>
  165. {allStepsCompleted() ? (
  166. <React.Fragment>
  167. <Typography variant="h4" sx={{ mt: 2, mb: 1 }}>
  168. All steps completed - you&apos;re finished
  169. </Typography>
  170. <Stack direction="row" sx={{ pt: 2 }}>
  171. <Stack sx={{ flex: '1 1 auto' }} />
  172. <Button onClick={handleReset}><Typography variant="h5">Reset</Typography></Button>
  173. </Stack>
  174. </React.Fragment>
  175. ) : (
  176. <React.Fragment>
  177. <AuthWrapper>
  178. <CustomFormWizard
  179. setUpdateValid={setUpdateValid}
  180. step={activeStep}
  181. setUsername={setUsername}
  182. setBase64Url={setBase64Url}
  183. setCheckCode={setCheckCode}
  184. />
  185. {/* <CustomFormWizard step={activeStep} /> */}
  186. </AuthWrapper>
  187. <Stack direction="row" sx={{ pb: 2, mt:-4, mb:2 }}>
  188. {activeStep === 2 || activeStep === 0 ? (
  189. <Button
  190. color="inherit"
  191. disabled={true}
  192. onClick={handleBack}
  193. sx={{ mr: 1 }}
  194. variant="h5"
  195. >
  196. <Typography variant="h5">
  197. <FormattedMessage id="back"/>
  198. </Typography>
  199. </Button>
  200. ) : (
  201. <Button
  202. color="inherit"
  203. disabled={activeStep === 0}
  204. onClick={handleBack}
  205. sx={{ mr: 1 }}
  206. variant="h5"
  207. >
  208. <Typography variant="h5">
  209. <FormattedMessage id="back"/>
  210. </Typography>
  211. </Button>
  212. )
  213. }
  214. <Stack sx={{ flex: '1 1 auto' }} />
  215. {activeStep === totalSteps() - 2 ?
  216. (
  217. <Button variant="outlined" onClick={handleNext} sx={{ mr: 1 }}>
  218. <Typography variant="h5">
  219. <FormattedMessage id="submit"/>
  220. </Typography>
  221. </Button>
  222. ) : (activeStep === totalSteps() - 1 ?
  223. (
  224. <Button variant="outlined" color="inherit"
  225. disabled={true} sx={{ mr: 1 }}>
  226. <Typography variant="h5">
  227. <FormattedMessage id="submit"/>
  228. </Typography>
  229. </Button>
  230. ) :
  231. (
  232. // <Button disabled={updateValid} variant="outlined" onClick={handleNext} sx={{ mr: 1 }}>
  233. <Button disabled={!updateValid} variant="outlined" onClick={handleNext} sx={{ mr: 1 }}>
  234. <Typography variant="h5">
  235. <FormattedMessage id="continue"/>
  236. </Typography>
  237. </Button>
  238. )
  239. )}
  240. {/* {activeStep !== steps.length &&
  241. (completed[activeStep] ? (
  242. <Typography variant="caption" sx={{ display: 'inline-block' }}>
  243. Step {activeStep + 1} already completed
  244. </Typography>
  245. ) : (
  246. <Button onClick={handleComplete}>
  247. {completedSteps() === totalSteps() - 1
  248. ? 'Finish'
  249. : 'Complete Step'}
  250. </Button>
  251. ))} */}
  252. </Stack>
  253. </React.Fragment>
  254. )}
  255. </Stack >
  256. // </AuthWrapper>
  257. );
  258. };
  259. export default Register;