25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

200 lines
6.1 KiB

  1. // import { Link } from 'react-router-dom';
  2. import React,{useState
  3. // ,useEffect
  4. } from 'react';
  5. // material-ui
  6. import {
  7. Stepper,
  8. Step,
  9. StepButton,
  10. // Grid,
  11. Stack,
  12. Typography,
  13. Button,
  14. } from '@mui/material';
  15. import VisibilityIcon from '@mui/icons-material/Visibility';
  16. // project import
  17. import Loadable from 'components/Loadable';
  18. import { lazy } from 'react';
  19. const CustomFormWizard = Loadable(lazy(() => import('./auth-forms/CustomFormWizard')));
  20. const AuthWrapper = Loadable(lazy(() => import('./AuthWrapperCustom')));
  21. // ================================|| REGISTER ||================================ //
  22. const stepStyle = {
  23. width:"40%",
  24. boxShadow: 1,
  25. backgroundColor: "#FFFFFF",
  26. padding: 2,
  27. "& .Mui-active": {
  28. "&.MuiStepIcon-root": {
  29. color: "warning.main",
  30. fontSize: "2rem",
  31. },
  32. "& .MuiStepConnector-line": {
  33. borderColor: "warning.main"
  34. }
  35. },
  36. "& .Mui-completed": {
  37. "&.MuiStepIcon-root": {
  38. color: "secondary.main",
  39. fontSize: "2rem",
  40. },
  41. "& .MuiStepConnector-line": {
  42. borderColor: "secondary.main"
  43. }
  44. }
  45. }
  46. const steps = ['個人資料', '預覽', '完成提交'];
  47. const Register = () => {
  48. const [activeStep, setActiveStep] = useState(0);
  49. const [completed, setCompleted] = useState([false]);
  50. const [updateValid, setUpdateValid] = useState(false);
  51. const totalSteps = () => {
  52. return steps.length;
  53. };
  54. const completedSteps = () => {
  55. return Object.keys(completed).length;
  56. };
  57. const isLastStep = () => {
  58. return activeStep === totalSteps() - 1;
  59. };
  60. const allStepsCompleted = () => {
  61. return completedSteps() === totalSteps();
  62. };
  63. const handleNext = () => {
  64. const newActiveStep =
  65. isLastStep() && !allStepsCompleted()
  66. ? // It's the last step, but not all steps have been completed,
  67. // find the first step that has been completed
  68. steps.findIndex((step, i) => !(i in completed))
  69. : activeStep + 1;
  70. setActiveStep(newActiveStep);
  71. scrollToTop();
  72. };
  73. const handleBack = () => {
  74. scrollToTop();
  75. setActiveStep((prevActiveStep) => prevActiveStep - 1);
  76. };
  77. const scrollToTop = () => {
  78. window.scrollTo(0,0);
  79. };
  80. const handleReset = () => {
  81. setActiveStep(0);
  82. setCompleted({});
  83. };
  84. return(
  85. // <AuthWrapper>
  86. <Stack sx={{ width: '100%',fontSize: '2rem',paddingTop: '65px'}} alignItems="center">
  87. <Stepper activeStep={activeStep} sx={stepStyle}>
  88. {steps.map((label, index) => (
  89. <Step key={label} completed={completed[index]} readOnly={true}>
  90. {
  91. index < 2 ?
  92. (<StepButton
  93. // onClick={handleStep(index)}
  94. >
  95. {label}
  96. </StepButton>) :
  97. (<StepButton
  98. sx={activeStep === 2 ? { "& .MuiSvgIcon-root": { color: "warning.main", fontSize: "2rem" } } : allStepsCompleted() ? { "& .MuiSvgIcon-root": { color: "secondary.main", fontSize: "2rem" } } : { color: "rgba(0, 0, 0, 0.38)" }}
  99. icon={<VisibilityIcon />}
  100. // onClick={handleStep(index)}
  101. >
  102. {label}
  103. </StepButton>)
  104. }
  105. </Step>
  106. ))}
  107. </Stepper>
  108. {allStepsCompleted() ? (
  109. <React.Fragment>
  110. <Typography sx={{ mt: 2, mb: 1 }}>
  111. All steps completed - you&apos;re finished
  112. </Typography>
  113. <Stack direction="row" sx={{ pt: 2 }}>
  114. <Stack sx={{ flex: '1 1 auto' }} />
  115. <Button onClick={handleReset}>Reset</Button>
  116. </Stack>
  117. </React.Fragment>
  118. ) : (
  119. <React.Fragment>
  120. <AuthWrapper>
  121. <CustomFormWizard setUpdateValid={setUpdateValid} step={activeStep} />
  122. {/* <CustomFormWizard step={activeStep} /> */}
  123. </AuthWrapper>
  124. <Stack direction="row" sx={{ pb: 2 }}>
  125. { activeStep === 2|| activeStep === 0? (
  126. <Button
  127. color="inherit"
  128. disabled={true}
  129. onClick={handleBack}
  130. sx={{ mr: 1 }}
  131. >
  132. 返回
  133. </Button>
  134. ):(
  135. <Button
  136. color="inherit"
  137. disabled={activeStep === 0}
  138. onClick={handleBack}
  139. sx={{ mr: 1 }}
  140. >
  141. 返回
  142. </Button>
  143. )
  144. }
  145. <Stack sx={{ flex: '1 1 auto' }} />
  146. {activeStep === totalSteps() - 2 ?
  147. (
  148. <Button variant="outlined" onClick={handleNext} sx={{ mr: 1 }}>
  149. 提交
  150. </Button>
  151. ) : ( activeStep === totalSteps() - 1 ?
  152. (
  153. <Button variant="outlined" color="inherit"
  154. disabled={true} sx={{ mr: 1 }}>
  155. 提交
  156. </Button>
  157. ):
  158. (
  159. // <Button disabled={updateValid} variant="outlined" onClick={handleNext} sx={{ mr: 1 }}>
  160. <Button disabled={!updateValid} variant="outlined" onClick={handleNext} sx={{ mr: 1 }}>
  161. 繼續
  162. </Button>
  163. )
  164. )}
  165. {/* {activeStep !== steps.length &&
  166. (completed[activeStep] ? (
  167. <Typography variant="caption" sx={{ display: 'inline-block' }}>
  168. Step {activeStep + 1} already completed
  169. </Typography>
  170. ) : (
  171. <Button onClick={handleComplete}>
  172. {completedSteps() === totalSteps() - 1
  173. ? 'Finish'
  174. : 'Complete Step'}
  175. </Button>
  176. ))} */}
  177. </Stack>
  178. </React.Fragment>
  179. )}
  180. </Stack >
  181. // </AuthWrapper>
  182. );
  183. };
  184. export default Register;