Browse Source

correct register behavior

amenpunk 3 years ago
parent
commit
e24d824eb8
4 changed files with 117 additions and 110 deletions
  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
     justify-content: flex-start;
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
 .css-ghsjzk-MuiInputBase-root-MuiInput-root:before{
156
 .css-ghsjzk-MuiInputBase-root-MuiInput-root:before{
156
     border : none !important;
157
     border : none !important;
157
 }
158
 }
158
-
159
 .login_link{
159
 .login_link{
160
     color : #2ec5d3;
160
     color : #2ec5d3;
161
 }
161
 }
162
-
162
+.registerBtn{
163
+    background-color: #fd4b4b !important;
164
+}
163
 .login_link:hover{
165
 .login_link:hover{
164
     font-weight : bold;
166
     font-weight : bold;
165
     color : #3ec5d3;
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
 import * as Yup from 'yup';
2
 import * as Yup from 'yup';
3
 
3
 
4
 import { 
4
 import { 
5
-    Stack, TextField,
5
+    Stack, TextField,Box, Button
6
 } from '@mui/material';
6
 } from '@mui/material';
7
 
7
 
8
-export function PersonalInfo() {
8
+export function PersonalInfo(props) {
9
 
9
 
10
     // let navigate = useNavigate()
10
     // let navigate = useNavigate()
11
 
11
 
12
+    const steplen = 2
12
     const RegisterSchema = Yup.object().shape({
13
     const RegisterSchema = Yup.object().shape({
13
         nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
14
         nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
14
         cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
15
         cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
83
                             type="date"
84
                             type="date"
84
                             label="Fecha de nacimiento"
85
                             label="Fecha de nacimiento"
85
                             fullWidth
86
                             fullWidth
86
-                            defaultValue={'2021-01-10'}
87
                             InputLabelProps={{ shrink: true, required: true }}
87
                             InputLabelProps={{ shrink: true, required: true }}
88
                             {...getFieldProps('nacimiento')}
88
                             {...getFieldProps('nacimiento')}
89
                             error={Boolean(touched.nacimiento && errors.nacimiento)}
89
                             error={Boolean(touched.nacimiento && errors.nacimiento)}
99
                         />
99
                         />
100
                     </Stack>
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
                 </Stack>
125
                 </Stack>
104
             </Form>
126
             </Form>

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

2
 import * as Yup from 'yup';
2
 import * as Yup from 'yup';
3
 import { useState } from 'react';
3
 import { useState } from 'react';
4
 import { useFormik, Form, FormikProvider } from 'formik';
4
 import { useFormik, Form, FormikProvider } from 'formik';
5
-// import { useNavigate } from 'react-router-dom';
6
 import { Icon } from '@iconify/react';
5
 import { Icon } from '@iconify/react';
7
 
6
 
8
-import { 
7
+import {  
8
+    Box, Button,
9
     Stack, TextField, IconButton, InputAdornment, 
9
     Stack, TextField, IconButton, InputAdornment, 
10
-    Backdrop, CircularProgress,
11
 } from '@mui/material';
10
 } from '@mui/material';
12
 
11
 
13
 import eyeFill from '@iconify/icons-eva/eye-fill';
12
 import eyeFill from '@iconify/icons-eva/eye-fill';
14
 import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
13
 import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
15
-import { Toaster } from 'react-hot-toast';
16
 // import { V1, V2 } from '../../Utils/HTTP'
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
     const [showPassword, setShowPassword] = useState(false);
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
     const RegisterSchema = Yup.object().shape({
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
         lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
25
         lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
35
         email: Yup.string().email('El correo no es valido').required('Email es requerido'),
26
         email: Yup.string().email('El correo no es valido').required('Email es requerido'),
36
         password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
27
         password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
37
         password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
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
         initialValues: {
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
         validationSchema: RegisterSchema,
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
     return (
50
     return (
79
         <FormikProvider style={{ padding : 15 }} value={formik}>
51
         <FormikProvider style={{ padding : 15 }} value={formik}>
128
 
100
 
129
                     <TextField
101
                     <TextField
130
                         fullWidth
102
                         fullWidth
131
-                        type={showPassword ? 'text' : 'password'}
103
+                        type={showPasswordTwo ? 'text' : 'password'}
132
                         label="Confirma contraseña"
104
                         label="Confirma contraseña"
133
                         {...getFieldProps('password_confirm')}
105
                         {...getFieldProps('password_confirm')}
134
                         InputProps={{
106
                         InputProps={{
135
                             endAdornment: (
107
                             endAdornment: (
136
                                 <InputAdornment position="end">
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
                                     </IconButton>
111
                                     </IconButton>
140
                                 </InputAdornment>
112
                                 </InputAdornment>
141
                             )
113
                             )
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
                 </Stack>
140
                 </Stack>
160
             </Form>
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
         </FormikProvider>
142
         </FormikProvider>
173
     );
143
     );
174
 }
144
 }

+ 38 - 31
src/Pages/Register.jsx

41
     padding: theme.spacing(12, 0)
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
 export function Register() {
45
 export function Register() {
55
 
46
 
63
     }, [auth,navigate])
54
     }, [auth,navigate])
64
 
55
 
65
     const [activeStep, setActiveStep] = React.useState(0);
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
     const handleNext = () => {
70
     const handleNext = () => {
68
         setActiveStep((prevActiveStep) => prevActiveStep + 1);
71
         setActiveStep((prevActiveStep) => prevActiveStep + 1);
76
         setActiveStep(0);
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
     return (
104
     return (
80
         <RootStyle title="Register | Minimal-UI">
105
         <RootStyle title="Register | Minimal-UI">
81
 
106
 
117
             >
142
             >
118
               {step.label}
143
               {step.label}
119
             </StepLabel>
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
                     </Stepper>
150
                     </Stepper>
144
  {activeStep === steps.length && (
151
  {activeStep === steps.length && (