浏览代码

fix in register add empresa info

amenpunk 3 年之前
父节点
当前提交
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){
     return (
         <Typography variant="body2" color="text.secondary" align="center" {...props}>
             {'Copyright © '}
-            <Link color="inherit" href="https://mui.com/">
+            <Link color="inherit" href="#">
                 GrupoDIT
             </Link>{' '}
             {new Date().getFullYear()}

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

@@ -0,0 +1,94 @@
+import React from 'react'
+import * as Yup from 'yup';
+import { useFormik, Form, FormikProvider } from 'formik';
+
+import {
+  Box, Button,
+  Stack, TextField,
+} from '@mui/material';
+
+
+export function Company(props) {
+
+  const RegisterSchema = Yup.object().shape({
+    nombrecpmercial: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nombre es requerido'),
+    telefono: Yup.number().min(10000000, 'El telefono es requerido').max(99999999, 'El telefono debe ser valido').required('El telefono es requerido'),
+    decription: Yup.string().min(5, 'Ingresa una descripcion valida').required('Ingresa una descripcion valida'),
+  });
+
+  let { client, setClient, handleNext, handleBack } = props
+
+  const formik = useFormik({
+    initialValues: {
+      nombrecpmercial: client?.empresa?.nombrecpmercial,
+      telefono: client?.empresa?.telefono,
+      decription: client?.empresa?.decription
+    },
+    onSubmit: (fields) => {
+      setClient({
+        ...client,
+        empresa : fields
+      })
+      handleNext()
+    },
+    validationSchema: RegisterSchema,
+  });
+
+  const { errors, touched, handleSubmit, getFieldProps } = formik;
+
+  return (
+    <FormikProvider style={{ padding: 15 }} value={formik}>
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
+        <Stack spacing={3}>
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
+
+            <TextField
+              label="Nombre Comercial"
+              fullWidth
+              {...getFieldProps('nombrecpmercial')}
+              error={Boolean(touched.nombrecpmercial && errors.nombrecpmercial)}
+              helperText={touched.nombrecpmercial && errors.nombrecpmercial}
+            />
+
+            <TextField
+              label="Telefono"
+              fullWidth
+              {...getFieldProps('telefono')}
+              error={Boolean(touched.telefono && errors.telefono)}
+              helperText={touched.telefono && errors.telefono}
+            />
+
+          </Stack>
+
+          <TextField
+            label="Descripcion"
+            fullWidth
+            autoComplete="Descripcion"
+            {...getFieldProps('decription')}
+            error={Boolean(touched.decription && errors.decription)}
+            helperText={touched.decription && errors.decription}
+          />
+          <Box sx={{ mb: 2 }}>
+            <div style={{ paddingTop: 15 }}>
+              <Button
+                type="submit"
+                className="registerBtn"
+                variant="contained"
+                sx={{ mt: 1, mr: 1 }}
+              >
+                {'Siguiente'}
+              </Button>
+              <Button
+                onClick={handleBack}
+                sx={{ mt: 1, mr: 1 }}
+              >
+                Regresar
+              </Button>
+            </div>
+          </Box>
+
+        </Stack>
+      </Form>
+    </FormikProvider>
+  );
+}

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

@@ -1,9 +1,9 @@
-import  { useState } from 'react'
-import { useFormik, Form, FormikProvider } from 'formik'; 
+import { useState } from 'react'
+import { useFormik, Form, FormikProvider } from 'formik';
 import { useNavigate } from 'react-router-dom';
-import { 
-    Stack, TextField,Box, Button,
-    Backdrop, CircularProgress,
+import {
+  Stack, TextField, Box, Button,
+  Backdrop, CircularProgress,
 } from '@mui/material';
 import toast, { Toaster } from 'react-hot-toast';
 import * as Yup from 'yup';
@@ -13,165 +13,165 @@ import { Service } from '../../Utils/HTTP';
 
 export function PersonalInfo(props) {
 
-    let { handleBack, setClient, client } = props
-
-    let navigate = useNavigate()
-
-    const RegisterSchema = Yup.object().shape({
-        nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
-        cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
-        direccion: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('La direccion es requerida'),
-        nacimiento: Yup.date().required('Tu fecha  nacimiento es requerida'),
-        telefono: Yup.number('Ingresa únicamente números').required('Tu numero de telefono es requerido')
-    });
-
-    let [open, setOpen] = useState(false);
-
-    const formik = useFormik({
-        initialValues: {
-            nit: client.nit,
-            cui: client.cui,
-            direccion: client.direccion,
-            nacimiento: client.nacimiento,
-            telefono: client.telefono
-        },
-        validationSchema: RegisterSchema,
-        onSubmit: (values) => {
-            setOpen(true);
-
-            let new_client = {
-                ...client, ...values
-            }
-            setClient(new_client)
-
-            let body = {
-                "nombre" : new_client.firstName,
-                "apelidos" : new_client.lastName,
-                "telefono" : new_client.telefono,
-                "direccio": new_client.direccion,
-                "fechacumple": new_client.nacimiento,
-                "nit": new_client.nit,
-                "cui": new_client.cui,
-                "email": new_client.email,
-                "username": new_client.email,
-                "pwd": new_client.password
-            }
-
-
-            let req =  new Service('/registro');
-
-            req
-            .post(body)
-            .then( data => {
-
-                setTimeout(() => {
-                    setOpen(false);
-                    return navigate('/')
-                }, 2000)
-
-                console.log("DATA ::", data)
-                let nombre = client.firstName +  " " + client.lastName
-                toast.success(`Bienvenido ${nombre} !!`)
-
-
-            })
-            .catch(error => {
-                console.log("ERROR ::", error)
-                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`)
-                return setOpen(false);
-            })
-
-        }
-    });
-
-
-    const { errors, touched, handleSubmit, getFieldProps } = formik;
-
-    return(
-        <FormikProvider style={{ padding : 15}} value={formik}>
-            <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
-                <Stack spacing={3}>
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
-                        <TextField
-                            label="Numero de Nit"
-                            fullWidth
-                            {...getFieldProps('nit')}
-                            error={Boolean(touched.nit && errors.nit)}
-                            helperText={touched.nit && errors.nit}
-                        />
-
-                        <TextField
-                            label="CUI/DPI"
-                            fullWidth
-                            {...getFieldProps('cui')}
-                            error={Boolean(touched.cui && errors.cui)}
-                            helperText={touched.cui && errors.cui}
-                        />
-                    </Stack>
-
-                    <TextField
-                        fullWidth
-                        type="text"
-                        label="Dirección"
-                        {...getFieldProps('direccion')}
-                        error={Boolean(touched.direccion && errors.direccion)}
-                        helperText={touched.direccion && errors.direccion}
-                    />
-                    
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
-                        <TextField
-                            type="date"
-                            label="Fecha de nacimiento"
-                            fullWidth
-                            InputLabelProps={{  required: true }}
-                            {...getFieldProps('nacimiento')}
-                            error={Boolean(touched.nacimiento && errors.nacimiento)}
-                            helperText={touched.nacimiento && errors.nacimiento}
-                        />
-
-                        <TextField
-                            label="Telefono"
-                            fullWidth
-                            {...getFieldProps('telefono')}
-                            error={Boolean(touched.telefono && errors.telefono)}
-                            helperText={touched.telefono && errors.telefono}
-                        />
-                    </Stack>
-
-                    <Box sx={{ mb: 2 }}>
-                        <div style={{ paddingTop: 15 }}>
-                            <Button
-                                type="submit"
-                                className="registerBtn"
-                                variant="contained"
-                                // onClick={handleNext}
-                                sx={{ mt: 1, mr: 1 }}
-                            >
-                                {'Registrarme'}
-                            </Button>
-                            <Button
-                                onClick={handleBack}
-                                sx={{ mt: 1, mr: 1 }}
-                            >
-                                Regresar
-                            </Button>
-                        </div>
-                    </Box>
-
-                </Stack>
-
-            </Form>
-            <Toaster
-                position="top-center"
-                reverseOrder={false}
+  let { handleBack, setClient, client } = props
+
+  let navigate = useNavigate()
+
+  const RegisterSchema = Yup.object().shape({
+    nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
+    cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
+    direccion: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('La direccion es requerida'),
+    nacimiento: Yup.date().required('Tu fecha  nacimiento es requerida'),
+    telefono: Yup.number('Ingresa únicamente números').required('Tu numero de telefono es requerido')
+  });
+
+  let [open, setOpen] = useState(false);
+
+  const formik = useFormik({
+    initialValues: {
+      nit: client.nit,
+      cui: client.cui,
+      direccion: client.direccion,
+      nacimiento: client.nacimiento,
+      telefono: client.telefono
+    },
+    validationSchema: RegisterSchema,
+    onSubmit: (values) => {
+      setOpen(true);
+
+      let new_client = {
+        ...client, ...values
+      }
+      setClient(new_client)
+
+      let body = {
+        "nombre": new_client.firstName,
+        "apelidos": new_client.lastName,
+        "telefono": new_client.telefono,
+        "direccio": new_client.direccion,
+        "fechacumple": new_client.nacimiento,
+        "nit": new_client.nit,
+        "cui": new_client.cui,
+        "email": new_client.email,
+        "username": new_client.email,
+        "pwd": new_client.password,
+        "empresa": new_client.empresa
+      }
+
+      let req = new Service('/registro');
+
+      req
+        .post(body)
+        .then(data => {
+
+          setTimeout(() => {
+            setOpen(false);
+            return navigate('/')
+          }, 2000)
+
+          console.log("DATA ::", data)
+          let nombre = client.firstName + " " + client.lastName
+          toast.success(`Bienvenido ${nombre} !!`)
+
+
+        })
+        .catch(error => {
+          console.log("ERROR ::", error)
+          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`)
+          return setOpen(false);
+        })
+
+    }
+  });
+
+
+  const { errors, touched, handleSubmit, getFieldProps } = formik;
+
+  return (
+    <FormikProvider style={{ padding: 15 }} value={formik}>
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
+        <Stack spacing={3}>
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
+            <TextField
+              label="Numero de Nit"
+              fullWidth
+              {...getFieldProps('nit')}
+              error={Boolean(touched.nit && errors.nit)}
+              helperText={touched.nit && errors.nit}
             />
-            <Backdrop
-                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
-                open={open}
-                onClick={() => false}
-            >
-                <CircularProgress color="inherit" />
-            </Backdrop>
-        </FormikProvider>
-    )
+
+            <TextField
+              label="CUI/DPI"
+              fullWidth
+              {...getFieldProps('cui')}
+              error={Boolean(touched.cui && errors.cui)}
+              helperText={touched.cui && errors.cui}
+            />
+          </Stack>
+
+          <TextField
+            fullWidth
+            type="text"
+            label="Dirección"
+            {...getFieldProps('direccion')}
+            error={Boolean(touched.direccion && errors.direccion)}
+            helperText={touched.direccion && errors.direccion}
+          />
+
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
+            <TextField
+              type="date"
+              label="Fecha de nacimiento"
+              fullWidth
+              InputLabelProps={{ required: true }}
+              {...getFieldProps('nacimiento')}
+              error={Boolean(touched.nacimiento && errors.nacimiento)}
+              helperText={touched.nacimiento && errors.nacimiento}
+            />
+
+            <TextField
+              label="Telefono"
+              fullWidth
+              {...getFieldProps('telefono')}
+              error={Boolean(touched.telefono && errors.telefono)}
+              helperText={touched.telefono && errors.telefono}
+            />
+          </Stack>
+
+          <Box sx={{ mb: 2 }}>
+            <div style={{ paddingTop: 15 }}>
+              <Button
+                type="submit"
+                className="registerBtn"
+                variant="contained"
+                // onClick={handleNext}
+                sx={{ mt: 1, mr: 1 }}
+              >
+                {'Registrarme'}
+              </Button>
+              <Button
+                onClick={handleBack}
+                sx={{ mt: 1, mr: 1 }}
+              >
+                Regresar
+              </Button>
+            </div>
+          </Box>
+
+        </Stack>
+
+      </Form>
+      <Toaster
+        position="top-center"
+        reverseOrder={false}
+      />
+      <Backdrop
+        sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
+        open={open}
+        onClick={() => false}
+      >
+        <CircularProgress color="inherit" />
+      </Backdrop>
+    </FormikProvider>
+  )
 }

+ 23 - 3
src/Pages/Register.jsx

@@ -5,9 +5,11 @@ import {
   Box, Link, Container, Typography, Card,
   StepLabel, Step, Stepper, Button, Paper, StepContent
 } from '@mui/material';
+import jwt_decode from "jwt-decode";
 
 import { RegisterForm } from '../Components/Register/RegisterForm';
-import { PersonalInfo } from '../Components/Register/PersonalInfo.js';
+import { PersonalInfo } from '../Components/Register/PersonalInfo';
+import { Company  } from '../Components/Register/Company';
 import AuthLayout from '../Components/Register/AuthLayout';
 
 import Mock from '../Images/register_mok.png'
@@ -23,7 +25,10 @@ export function Register() {
 
   React.useEffect(() => {
     if (auth.token) {
-      return navigate('/dashboard/home')
+      let body_token = jwt_decode(auth.token);
+      if (body_token.authorities.includes("Reclutador")) {
+        return navigate('/dashboard/home')
+      }
     }
   }, [auth, navigate])
 
@@ -42,6 +47,11 @@ export function Register() {
     direccion: "",
     nacimiento: TODAY.getFullYear() + '-10-18',
     telefono: "",
+    empresa: {
+      nombrecpmercial:'',
+      telefono: '',
+      decription: '',
+    }
   });
 
   const handleNext = () => {
@@ -67,6 +77,16 @@ export function Register() {
           handleNext={handleNext}
         />
     },
+    {
+      label: 'Empresa',
+      description: 
+      <Company 
+          client={client}
+          setClient={setClient}
+          handleBack={handleBack}
+          handleNext={handleNext}
+      />
+    },
     {
       label: 'Datos Personales',
       description:
@@ -79,7 +99,7 @@ export function Register() {
   ];
 
   return (
-    <Container style={{paddingTop:40}}>
+    <Container style={{ paddingTop: 40 }}>
       <Row className="register_content">
         <Col md={4} className="d-none d-md-block">