瀏覽代碼

correct register behavior

amenpunk 3 年之前
父節點
當前提交
e24d824eb8
共有 4 個文件被更改,包括 117 次插入110 次删除
  1. 13 5
      src/App.css
  2. 25 3
      src/Components/Register/PersonalInfo.js
  3. 41 71
      src/Components/Register/RegisterForm.jsx
  4. 38 31
      src/Pages/Register.jsx

+ 13 - 5
src/App.css

@@ -149,19 +149,27 @@
149 149
     justify-content: flex-start;
150 150
 }
151 151
 
152
-.MuiButton-root:hover{
153
-    background-color : #fd4b4b !important;
154
-}
152
+/* .MuiButton-root:hover{ */
153
+    /* background-color : #fd4b4b !important; */
154
+/* } */
155
+
155 156
 .css-ghsjzk-MuiInputBase-root-MuiInput-root:before{
156 157
     border : none !important;
157 158
 }
158
-
159 159
 .login_link{
160 160
     color : #2ec5d3;
161 161
 }
162
-
162
+.registerBtn{
163
+    background-color: #fd4b4b !important;
164
+}
163 165
 .login_link:hover{
164 166
     font-weight : bold;
165 167
     color : #3ec5d3;
166 168
 }
169
+.MuiStepIcon-root.Mui-completed{
170
+    color: #fd4b4b !important;
171
+}
172
+.MuiStepIcon-root.Mui-active {
173
+    color: #fd4b4b !important;
174
+}
167 175
 

+ 25 - 3
src/Components/Register/PersonalInfo.js

@@ -2,13 +2,14 @@ import { useFormik, Form, FormikProvider } from 'formik'; // import { useNavigat
2 2
 import * as Yup from 'yup';
3 3
 
4 4
 import { 
5
-    Stack, TextField,
5
+    Stack, TextField,Box, Button
6 6
 } from '@mui/material';
7 7
 
8
-export function PersonalInfo() {
8
+export function PersonalInfo(props) {
9 9
 
10 10
     // let navigate = useNavigate()
11 11
 
12
+    const steplen = 2
12 13
     const RegisterSchema = Yup.object().shape({
13 14
         nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
14 15
         cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
@@ -83,7 +84,6 @@ export function PersonalInfo() {
83 84
                             type="date"
84 85
                             label="Fecha de nacimiento"
85 86
                             fullWidth
86
-                            defaultValue={'2021-01-10'}
87 87
                             InputLabelProps={{ shrink: true, required: true }}
88 88
                             {...getFieldProps('nacimiento')}
89 89
                             error={Boolean(touched.nacimiento && errors.nacimiento)}
@@ -99,6 +99,28 @@ export function PersonalInfo() {
99 99
                         />
100 100
                     </Stack>
101 101
 
102
+                  <Box sx={{ mb: 2 }}>
103
+                    <div style={{ paddingTop  : 15}}>
104
+                      <Button
105
+                        type="submit"
106
+                        className="registerBtn" 
107
+                        variant="contained"
108
+                        // onClick={handleNext}
109
+                        sx={{ mt: 1, mr: 1 }}
110
+                      >
111
+                        {props.index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
112
+                      </Button>
113
+                      <Button
114
+                        onClick={props.handleBack}
115
+                        sx={{ mt: 1, mr: 1 }}
116
+                      >
117
+                        Regresar
118
+                      </Button>
119
+                    </div>
120
+                  </Box>
121
+
122
+
123
+
102 124
 
103 125
                 </Stack>
104 126
             </Form>

+ 41 - 71
src/Components/Register/RegisterForm.jsx

@@ -2,78 +2,50 @@ import React from 'react'
2 2
 import * as Yup from 'yup';
3 3
 import { useState } from 'react';
4 4
 import { useFormik, Form, FormikProvider } from 'formik';
5
-// import { useNavigate } from 'react-router-dom';
6 5
 import { Icon } from '@iconify/react';
7 6
 
8
-import { 
7
+import {  
8
+    Box, Button,
9 9
     Stack, TextField, IconButton, InputAdornment, 
10
-    Backdrop, CircularProgress,
11 10
 } from '@mui/material';
12 11
 
13 12
 import eyeFill from '@iconify/icons-eva/eye-fill';
14 13
 import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
15
-import { Toaster } from 'react-hot-toast';
16 14
 // import { V1, V2 } from '../../Utils/HTTP'
17 15
 
18
-export function RegisterForm() {
16
+export function RegisterForm(props) {
17
+
18
+    const steplen = 2;
19 19
 
20
-    // const navigate = useNavigate();
21 20
     const [showPassword, setShowPassword] = useState(false);
22
-    const [open, setOpen] = React.useState(false);
23
-    const handleClose = () => {
24
-        setOpen(false);
25
-    };
26
-    
27
-    // let navigate = useNavigate()
21
+    const [showPasswordTwo, setShowPasswordTwo] = useState(false);
28 22
 
29 23
     const RegisterSchema = Yup.object().shape({
30
-        firstName: Yup.string()
31
-        .min(2, 'Demasiado corto!')
32
-        .max(50, 'Demasiado largo!')
33
-        .required('Tu nombre es requerido'),
24
+        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
34 25
         lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
35 26
         email: Yup.string().email('El correo no es valido').required('Email es requerido'),
36 27
         password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
37 28
         password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
38 29
     });
39 30
 
40
-    const formik = useFormik({
31
+    let {client, setClient } = props
41 32
 
33
+    const formik = useFormik({
42 34
         initialValues: {
43
-            firstName: '',
44
-            lastName: '',
45
-            email: '',
46
-            password: '',
47
-            password_confirm: ''
35
+            firstName: client.firstName,
36
+            lastName: client.lastName,
37
+            email: client.email,
38
+            password: client.password,
39
+            password_confirm: client.password_confirm
40
+        },
41
+        onSubmit: (fields) => {
42
+            setClient({ ...fields })
43
+            props.handleNext()
48 44
         },
49 45
         validationSchema: RegisterSchema,
50
-        onSubmit: async (values) => {
51
-            // setOpen(true);
52
-            let body = {
53
-                nombre : values.firstName,
54
-                apelidos : values.lastName,
55
-                email : values.email,
56
-                username : values.email,
57
-                pwd : values.password,
58
-                "nit": "5345435",
59
-                "cui": "555555",
60
-                "direccio": "4 calle zona 1",
61
-                "fechacumple": "2021-01-01",
62
-                "telefono" : "45435345",
63
-            }
64
-
65
-            let url = 'http://204.48.25.93:8081/registro'
66
-            console.log(body, url)
67
-            // let url = 'http://psicoadmin.ditca.org:8081/registro'
68
-            // V1(url, body);
69
-            // V2(url, body);
70
-            setOpen(false)
71
-            //
72
-        }
73
-
74 46
     });
75 47
 
76
-    const { errors, touched, handleSubmit, getFieldProps } = formik;
48
+    const {errors, touched, handleSubmit, getFieldProps } = formik;
77 49
 
78 50
     return (
79 51
         <FormikProvider style={{ padding : 15 }} value={formik}>
@@ -128,14 +100,14 @@ export function RegisterForm() {
128 100
 
129 101
                     <TextField
130 102
                         fullWidth
131
-                        type={showPassword ? 'text' : 'password'}
103
+                        type={showPasswordTwo ? 'text' : 'password'}
132 104
                         label="Confirma contraseña"
133 105
                         {...getFieldProps('password_confirm')}
134 106
                         InputProps={{
135 107
                             endAdornment: (
136 108
                                 <InputAdornment position="end">
137
-                                    <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
138
-                                        <Icon icon={showPassword ? eyeFill : eyeOffFill} />
109
+                                    <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
110
+                                        <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
139 111
                                     </IconButton>
140 112
                                 </InputAdornment>
141 113
                             )
@@ -145,30 +117,28 @@ export function RegisterForm() {
145 117
                     />
146 118
 
147 119
 
148
-        {/*
149
-            <Button 
150
-            type="submit"
151
-            size="large"
152
-            style={{ backgroundColor : '#d32f2f'}}
153
-            variant="contained" >
154
-            Registrarme
155
-            </Button>
156
-            */
157
-        }
120
+                  <Box sx={{ mb: 2 }}>
121
+                    <div style={{ paddingTop  : 15}}>
122
+                      <Button
123
+                        type="submit"
124
+                        className="registerBtn" 
125
+                        variant="contained"
126
+                        // onClick={handleNext}
127
+                        sx={{ mt: 1, mr: 1 }}
128
+                      >
129
+                        {props.index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
130
+                      </Button>
131
+                      <Button
132
+                        onClick={props.handleBack}
133
+                        sx={{ mt: 1, mr: 1 }}
134
+                      >
135
+                        Regresar
136
+                      </Button>
137
+                    </div>
138
+                  </Box>
158 139
 
159 140
                 </Stack>
160 141
             </Form>
161
-            <Toaster
162
-                position="top-left"
163
-                reverseOrder={false}
164
-            />
165
-            <Backdrop
166
-                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
167
-                open={open}
168
-                onClick={handleClose}
169
-            >
170
-                <CircularProgress color="inherit" />
171
-            </Backdrop>
172 142
         </FormikProvider>
173 143
     );
174 144
 }

+ 38 - 31
src/Pages/Register.jsx

@@ -41,15 +41,6 @@ const ContentStyle = styled('div')(({ theme }) => ({
41 41
     padding: theme.spacing(12, 0)
42 42
 }));
43 43
 
44
-const steps = [
45
-    {
46
-        label: 'Información de tu cuenta',
47
-        description: <RegisterForm/>
48
-    }, {
49
-        label: 'Datos Personales',
50
-        description: <PersonalInfo/>
51
-    },
52
-];
53 44
 
54 45
 export function Register() {
55 46
 
@@ -63,6 +54,18 @@ export function Register() {
63 54
     }, [auth,navigate])
64 55
 
65 56
     const [activeStep, setActiveStep] = React.useState(0);
57
+    const [client, setClient] = React.useState({
58
+        firstName: 'Ming',
59
+        lastName: '',
60
+        email: '',
61
+        password: '',
62
+        password_confirm: '',
63
+        nit: "5345435",
64
+        cui: "555555",
65
+        direccion: "4 calle zona 1",
66
+        fechacumple: "2021-01-01",
67
+        telefono : "45435345",
68
+    });
66 69
 
67 70
     const handleNext = () => {
68 71
         setActiveStep((prevActiveStep) => prevActiveStep + 1);
@@ -76,6 +79,28 @@ export function Register() {
76 79
         setActiveStep(0);
77 80
     };
78 81
 
82
+    const steps = [
83
+        {
84
+            label: 'Información de tu cuenta',
85
+            description: 
86
+            <RegisterForm 
87
+            client={client} 
88
+            setClient={setClient} 
89
+            handleBack={handleBack}
90
+            handleNext={handleNext}
91
+            />
92
+        }, 
93
+        {
94
+            label: 'Datos Personales',
95
+            description: 
96
+            <PersonalInfo 
97
+            client={client} 
98
+            setClient={setClient} 
99
+            handleBack={handleBack}
100
+            />
101
+        },
102
+    ];
103
+
79 104
     return (
80 105
         <RootStyle title="Register | Minimal-UI">
81 106
 
@@ -117,28 +142,10 @@ export function Register() {
117 142
             >
118 143
               {step.label}
119 144
             </StepLabel>
120
-        <StepContent style={{ padding : 25}}>
121
-              {step.description}
122
-              <Box sx={{ mb: 2 }}>
123
-                <div style={{ paddingTop  : 15}}>
124
-                  <Button
125
-                    variant="contained"
126
-                    onClick={handleNext}
127
-                    sx={{ mt: 1, mr: 1 }}
128
-                  >
129
-                    {index === steps.length - 1 ? 'Registrarme' : 'Siguiente'}
130
-                  </Button>
131
-                  <Button
132
-                    disabled={index === 0}
133
-                    onClick={handleBack}
134
-                    sx={{ mt: 1, mr: 1 }}
135
-                  >
136
-                    Regresar
137
-                  </Button>
138
-                </div>
139
-              </Box>
140
-            </StepContent>
141
-          </Step>
145
+            <StepContent style={{ padding : 25}}>
146
+                  {step.description}
147
+                </StepContent>
148
+              </Step>
142 149
         ))}                    
143 150
                     </Stepper>
144 151
  {activeStep === steps.length && (