浏览代码

fix in register add empresa info

amenpunk 2 年之前
父节点
当前提交
4d34f12f27
共有 4 个文件被更改,包括 283 次插入169 次删除
  1. 1 1
      src/Components/Footer.js
  2. 94 0
      src/Components/Register/Company.jsx
  3. 165 165
      src/Components/Register/PersonalInfo.js
  4. 23 3
      src/Pages/Register.jsx

+ 1 - 1
src/Components/Footer.js

@@ -17,7 +17,7 @@ export function Copyright(props){
17 17
     return (
18 18
         <Typography variant="body2" color="text.secondary" align="center" {...props}>
19 19
             {'Copyright © '}
20
-            <Link color="inherit" href="https://mui.com/">
20
+            <Link color="inherit" href="#">
21 21
                 GrupoDIT
22 22
             </Link>{' '}
23 23
             {new Date().getFullYear()}

+ 94 - 0
src/Components/Register/Company.jsx

@@ -0,0 +1,94 @@
1
+import React from 'react'
2
+import * as Yup from 'yup';
3
+import { useFormik, Form, FormikProvider } from 'formik';
4
+
5
+import {
6
+  Box, Button,
7
+  Stack, TextField,
8
+} from '@mui/material';
9
+
10
+
11
+export function Company(props) {
12
+
13
+  const RegisterSchema = Yup.object().shape({
14
+    nombrecpmercial: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nombre es requerido'),
15
+    telefono: Yup.number().min(10000000, 'El telefono es requerido').max(99999999, 'El telefono debe ser valido').required('El telefono es requerido'),
16
+    decription: Yup.string().min(5, 'Ingresa una descripcion valida').required('Ingresa una descripcion valida'),
17
+  });
18
+
19
+  let { client, setClient, handleNext, handleBack } = props
20
+
21
+  const formik = useFormik({
22
+    initialValues: {
23
+      nombrecpmercial: client?.empresa?.nombrecpmercial,
24
+      telefono: client?.empresa?.telefono,
25
+      decription: client?.empresa?.decription
26
+    },
27
+    onSubmit: (fields) => {
28
+      setClient({
29
+        ...client,
30
+        empresa : fields
31
+      })
32
+      handleNext()
33
+    },
34
+    validationSchema: RegisterSchema,
35
+  });
36
+
37
+  const { errors, touched, handleSubmit, getFieldProps } = formik;
38
+
39
+  return (
40
+    <FormikProvider style={{ padding: 15 }} value={formik}>
41
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
42
+        <Stack spacing={3}>
43
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
44
+
45
+            <TextField
46
+              label="Nombre Comercial"
47
+              fullWidth
48
+              {...getFieldProps('nombrecpmercial')}
49
+              error={Boolean(touched.nombrecpmercial && errors.nombrecpmercial)}
50
+              helperText={touched.nombrecpmercial && errors.nombrecpmercial}
51
+            />
52
+
53
+            <TextField
54
+              label="Telefono"
55
+              fullWidth
56
+              {...getFieldProps('telefono')}
57
+              error={Boolean(touched.telefono && errors.telefono)}
58
+              helperText={touched.telefono && errors.telefono}
59
+            />
60
+
61
+          </Stack>
62
+
63
+          <TextField
64
+            label="Descripcion"
65
+            fullWidth
66
+            autoComplete="Descripcion"
67
+            {...getFieldProps('decription')}
68
+            error={Boolean(touched.decription && errors.decription)}
69
+            helperText={touched.decription && errors.decription}
70
+          />
71
+          <Box sx={{ mb: 2 }}>
72
+            <div style={{ paddingTop: 15 }}>
73
+              <Button
74
+                type="submit"
75
+                className="registerBtn"
76
+                variant="contained"
77
+                sx={{ mt: 1, mr: 1 }}
78
+              >
79
+                {'Siguiente'}
80
+              </Button>
81
+              <Button
82
+                onClick={handleBack}
83
+                sx={{ mt: 1, mr: 1 }}
84
+              >
85
+                Regresar
86
+              </Button>
87
+            </div>
88
+          </Box>
89
+
90
+        </Stack>
91
+      </Form>
92
+    </FormikProvider>
93
+  );
94
+}

+ 165 - 165
src/Components/Register/PersonalInfo.js

@@ -1,9 +1,9 @@
1
-import  { useState } from 'react'
2
-import { useFormik, Form, FormikProvider } from 'formik'; 
1
+import { useState } from 'react'
2
+import { useFormik, Form, FormikProvider } from 'formik';
3 3
 import { useNavigate } from 'react-router-dom';
4
-import { 
5
-    Stack, TextField,Box, Button,
6
-    Backdrop, CircularProgress,
4
+import {
5
+  Stack, TextField, Box, Button,
6
+  Backdrop, CircularProgress,
7 7
 } from '@mui/material';
8 8
 import toast, { Toaster } from 'react-hot-toast';
9 9
 import * as Yup from 'yup';
@@ -13,165 +13,165 @@ import { Service } from '../../Utils/HTTP';
13 13
 
14 14
 export function PersonalInfo(props) {
15 15
 
16
-    let { handleBack, setClient, client } = props
17
-
18
-    let navigate = useNavigate()
19
-
20
-    const RegisterSchema = Yup.object().shape({
21
-        nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
22
-        cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
23
-        direccion: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('La direccion es requerida'),
24
-        nacimiento: Yup.date().required('Tu fecha  nacimiento es requerida'),
25
-        telefono: Yup.number('Ingresa únicamente números').required('Tu numero de telefono es requerido')
26
-    });
27
-
28
-    let [open, setOpen] = useState(false);
29
-
30
-    const formik = useFormik({
31
-        initialValues: {
32
-            nit: client.nit,
33
-            cui: client.cui,
34
-            direccion: client.direccion,
35
-            nacimiento: client.nacimiento,
36
-            telefono: client.telefono
37
-        },
38
-        validationSchema: RegisterSchema,
39
-        onSubmit: (values) => {
40
-            setOpen(true);
41
-
42
-            let new_client = {
43
-                ...client, ...values
44
-            }
45
-            setClient(new_client)
46
-
47
-            let body = {
48
-                "nombre" : new_client.firstName,
49
-                "apelidos" : new_client.lastName,
50
-                "telefono" : new_client.telefono,
51
-                "direccio": new_client.direccion,
52
-                "fechacumple": new_client.nacimiento,
53
-                "nit": new_client.nit,
54
-                "cui": new_client.cui,
55
-                "email": new_client.email,
56
-                "username": new_client.email,
57
-                "pwd": new_client.password
58
-            }
59
-
60
-
61
-            let req =  new Service('/registro');
62
-
63
-            req
64
-            .post(body)
65
-            .then( data => {
66
-
67
-                setTimeout(() => {
68
-                    setOpen(false);
69
-                    return navigate('/')
70
-                }, 2000)
71
-
72
-                console.log("DATA ::", data)
73
-                let nombre = client.firstName +  " " + client.lastName
74
-                toast.success(`Bienvenido ${nombre} !!`)
75
-
76
-
77
-            })
78
-            .catch(error => {
79
-                console.log("ERROR ::", error)
80
-                toast.error(`Ups ocurrió un error puede que tu usuario yo exista o sea un error interno, intenta nuevamente más tarde o ponte en contacto con nosotros`)
81
-                return setOpen(false);
82
-            })
83
-
84
-        }
85
-    });
86
-
87
-
88
-    const { errors, touched, handleSubmit, getFieldProps } = formik;
89
-
90
-    return(
91
-        <FormikProvider style={{ padding : 15}} value={formik}>
92
-            <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
93
-                <Stack spacing={3}>
94
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
95
-                        <TextField
96
-                            label="Numero de Nit"
97
-                            fullWidth
98
-                            {...getFieldProps('nit')}
99
-                            error={Boolean(touched.nit && errors.nit)}
100
-                            helperText={touched.nit && errors.nit}
101
-                        />
102
-
103
-                        <TextField
104
-                            label="CUI/DPI"
105
-                            fullWidth
106
-                            {...getFieldProps('cui')}
107
-                            error={Boolean(touched.cui && errors.cui)}
108
-                            helperText={touched.cui && errors.cui}
109
-                        />
110
-                    </Stack>
111
-
112
-                    <TextField
113
-                        fullWidth
114
-                        type="text"
115
-                        label="Dirección"
116
-                        {...getFieldProps('direccion')}
117
-                        error={Boolean(touched.direccion && errors.direccion)}
118
-                        helperText={touched.direccion && errors.direccion}
119
-                    />
120
-                    
121
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
122
-                        <TextField
123
-                            type="date"
124
-                            label="Fecha de nacimiento"
125
-                            fullWidth
126
-                            InputLabelProps={{  required: true }}
127
-                            {...getFieldProps('nacimiento')}
128
-                            error={Boolean(touched.nacimiento && errors.nacimiento)}
129
-                            helperText={touched.nacimiento && errors.nacimiento}
130
-                        />
131
-
132
-                        <TextField
133
-                            label="Telefono"
134
-                            fullWidth
135
-                            {...getFieldProps('telefono')}
136
-                            error={Boolean(touched.telefono && errors.telefono)}
137
-                            helperText={touched.telefono && errors.telefono}
138
-                        />
139
-                    </Stack>
140
-
141
-                    <Box sx={{ mb: 2 }}>
142
-                        <div style={{ paddingTop: 15 }}>
143
-                            <Button
144
-                                type="submit"
145
-                                className="registerBtn"
146
-                                variant="contained"
147
-                                // onClick={handleNext}
148
-                                sx={{ mt: 1, mr: 1 }}
149
-                            >
150
-                                {'Registrarme'}
151
-                            </Button>
152
-                            <Button
153
-                                onClick={handleBack}
154
-                                sx={{ mt: 1, mr: 1 }}
155
-                            >
156
-                                Regresar
157
-                            </Button>
158
-                        </div>
159
-                    </Box>
160
-
161
-                </Stack>
162
-
163
-            </Form>
164
-            <Toaster
165
-                position="top-center"
166
-                reverseOrder={false}
16
+  let { handleBack, setClient, client } = props
17
+
18
+  let navigate = useNavigate()
19
+
20
+  const RegisterSchema = Yup.object().shape({
21
+    nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
22
+    cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
23
+    direccion: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('La direccion es requerida'),
24
+    nacimiento: Yup.date().required('Tu fecha  nacimiento es requerida'),
25
+    telefono: Yup.number('Ingresa únicamente números').required('Tu numero de telefono es requerido')
26
+  });
27
+
28
+  let [open, setOpen] = useState(false);
29
+
30
+  const formik = useFormik({
31
+    initialValues: {
32
+      nit: client.nit,
33
+      cui: client.cui,
34
+      direccion: client.direccion,
35
+      nacimiento: client.nacimiento,
36
+      telefono: client.telefono
37
+    },
38
+    validationSchema: RegisterSchema,
39
+    onSubmit: (values) => {
40
+      setOpen(true);
41
+
42
+      let new_client = {
43
+        ...client, ...values
44
+      }
45
+      setClient(new_client)
46
+
47
+      let body = {
48
+        "nombre": new_client.firstName,
49
+        "apelidos": new_client.lastName,
50
+        "telefono": new_client.telefono,
51
+        "direccio": new_client.direccion,
52
+        "fechacumple": new_client.nacimiento,
53
+        "nit": new_client.nit,
54
+        "cui": new_client.cui,
55
+        "email": new_client.email,
56
+        "username": new_client.email,
57
+        "pwd": new_client.password,
58
+        "empresa": new_client.empresa
59
+      }
60
+
61
+      let req = new Service('/registro');
62
+
63
+      req
64
+        .post(body)
65
+        .then(data => {
66
+
67
+          setTimeout(() => {
68
+            setOpen(false);
69
+            return navigate('/')
70
+          }, 2000)
71
+
72
+          console.log("DATA ::", data)
73
+          let nombre = client.firstName + " " + client.lastName
74
+          toast.success(`Bienvenido ${nombre} !!`)
75
+
76
+
77
+        })
78
+        .catch(error => {
79
+          console.log("ERROR ::", error)
80
+          toast.error(`Ups ocurrió un error puede que tu usuario yo exista o sea un error interno, intenta nuevamente más tarde o ponte en contacto con nosotros`)
81
+          return setOpen(false);
82
+        })
83
+
84
+    }
85
+  });
86
+
87
+
88
+  const { errors, touched, handleSubmit, getFieldProps } = formik;
89
+
90
+  return (
91
+    <FormikProvider style={{ padding: 15 }} value={formik}>
92
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
93
+        <Stack spacing={3}>
94
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
95
+            <TextField
96
+              label="Numero de Nit"
97
+              fullWidth
98
+              {...getFieldProps('nit')}
99
+              error={Boolean(touched.nit && errors.nit)}
100
+              helperText={touched.nit && errors.nit}
167 101
             />
168
-            <Backdrop
169
-                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
170
-                open={open}
171
-                onClick={() => false}
172
-            >
173
-                <CircularProgress color="inherit" />
174
-            </Backdrop>
175
-        </FormikProvider>
176
-    )
102
+
103
+            <TextField
104
+              label="CUI/DPI"
105
+              fullWidth
106
+              {...getFieldProps('cui')}
107
+              error={Boolean(touched.cui && errors.cui)}
108
+              helperText={touched.cui && errors.cui}
109
+            />
110
+          </Stack>
111
+
112
+          <TextField
113
+            fullWidth
114
+            type="text"
115
+            label="Dirección"
116
+            {...getFieldProps('direccion')}
117
+            error={Boolean(touched.direccion && errors.direccion)}
118
+            helperText={touched.direccion && errors.direccion}
119
+          />
120
+
121
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
122
+            <TextField
123
+              type="date"
124
+              label="Fecha de nacimiento"
125
+              fullWidth
126
+              InputLabelProps={{ required: true }}
127
+              {...getFieldProps('nacimiento')}
128
+              error={Boolean(touched.nacimiento && errors.nacimiento)}
129
+              helperText={touched.nacimiento && errors.nacimiento}
130
+            />
131
+
132
+            <TextField
133
+              label="Telefono"
134
+              fullWidth
135
+              {...getFieldProps('telefono')}
136
+              error={Boolean(touched.telefono && errors.telefono)}
137
+              helperText={touched.telefono && errors.telefono}
138
+            />
139
+          </Stack>
140
+
141
+          <Box sx={{ mb: 2 }}>
142
+            <div style={{ paddingTop: 15 }}>
143
+              <Button
144
+                type="submit"
145
+                className="registerBtn"
146
+                variant="contained"
147
+                // onClick={handleNext}
148
+                sx={{ mt: 1, mr: 1 }}
149
+              >
150
+                {'Registrarme'}
151
+              </Button>
152
+              <Button
153
+                onClick={handleBack}
154
+                sx={{ mt: 1, mr: 1 }}
155
+              >
156
+                Regresar
157
+              </Button>
158
+            </div>
159
+          </Box>
160
+
161
+        </Stack>
162
+
163
+      </Form>
164
+      <Toaster
165
+        position="top-center"
166
+        reverseOrder={false}
167
+      />
168
+      <Backdrop
169
+        sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
170
+        open={open}
171
+        onClick={() => false}
172
+      >
173
+        <CircularProgress color="inherit" />
174
+      </Backdrop>
175
+    </FormikProvider>
176
+  )
177 177
 }

+ 23 - 3
src/Pages/Register.jsx

@@ -5,9 +5,11 @@ import {
5 5
   Box, Link, Container, Typography, Card,
6 6
   StepLabel, Step, Stepper, Button, Paper, StepContent
7 7
 } from '@mui/material';
8
+import jwt_decode from "jwt-decode";
8 9
 
9 10
 import { RegisterForm } from '../Components/Register/RegisterForm';
10
-import { PersonalInfo } from '../Components/Register/PersonalInfo.js';
11
+import { PersonalInfo } from '../Components/Register/PersonalInfo';
12
+import { Company  } from '../Components/Register/Company';
11 13
 import AuthLayout from '../Components/Register/AuthLayout';
12 14
 
13 15
 import Mock from '../Images/register_mok.png'
@@ -23,7 +25,10 @@ export function Register() {
23 25
 
24 26
   React.useEffect(() => {
25 27
     if (auth.token) {
26
-      return navigate('/dashboard/home')
28
+      let body_token = jwt_decode(auth.token);
29
+      if (body_token.authorities.includes("Reclutador")) {
30
+        return navigate('/dashboard/home')
31
+      }
27 32
     }
28 33
   }, [auth, navigate])
29 34
 
@@ -42,6 +47,11 @@ export function Register() {
42 47
     direccion: "",
43 48
     nacimiento: TODAY.getFullYear() + '-10-18',
44 49
     telefono: "",
50
+    empresa: {
51
+      nombrecpmercial:'',
52
+      telefono: '',
53
+      decription: '',
54
+    }
45 55
   });
46 56
 
47 57
   const handleNext = () => {
@@ -68,6 +78,16 @@ export function Register() {
68 78
         />
69 79
     },
70 80
     {
81
+      label: 'Empresa',
82
+      description: 
83
+      <Company 
84
+          client={client}
85
+          setClient={setClient}
86
+          handleBack={handleBack}
87
+          handleNext={handleNext}
88
+      />
89
+    },
90
+    {
71 91
       label: 'Datos Personales',
72 92
       description:
73 93
         <PersonalInfo
@@ -79,7 +99,7 @@ export function Register() {
79 99
   ];
80 100
 
81 101
   return (
82
-    <Container style={{paddingTop:40}}>
102
+    <Container style={{ paddingTop: 40 }}>
83 103
       <Row className="register_content">
84 104
         <Col md={4} className="d-none d-md-block">
85 105