import React, { useState, useRef, useEffect, Fragment } from 'react'; import axios from 'axios'; import { AiFillEye } from "react-icons/ai"; import { AiFillEyeInvisible } from "react-icons/ai"; import { Botonbase } from "@components/botonbase"; import { SelectorInput } from "@components/selectorInput"; import { ModalCnae } from "@components/modalCnae"; const ModalRegistroInscripcion = (props) => { const [valorSteep, setValorsteep] = useState(1); const terminosRef = useRef(); const nombreFiscalRef = useRef(); const residenteEspanaRef = useRef(); const [usuarioRegistrado, setusuarioRegistrado] = useState(false); const [formIsInvalid, setformIsInvalid] = useState(false); const [quitarPaso, setQuitarPaso] = useState(false); const [errorPaso3, setErrorPaso3] = useState(false); const [messageLogin, setmessageLogin] = useState(''); const messageLoginChange = (val) => { setmessageLogin(val) } const [showPass, setshowPass] = useState(false); function showPassword() { if (showPass) { setshowPass(false) } else { setshowPass(true) } } const [sectores, setSectores] = useState(false) const [intereses, setIntereses] = useState([]) const [cleanIntereses, setCleanIntereses] = useState([]) const [errorIntereses, setErrorIntereses] = useState(false) const marcarIntereses = async (action, idEtiqueta) => { console.log('ETIQUETAS ACTION:::', action) let string = [] if (intereses.length >= 1) { string = intereses.split(',') } if (action == 'add') { cleanIntereses.push(idEtiqueta) console.log(cleanIntereses); string.push(idEtiqueta) string = string.join() } if (action == 'del') { const index = string.indexOf("" + idEtiqueta); let i = cleanIntereses.indexOf(idEtiqueta); if (i !== -1) { cleanIntereses.splice(i, 1); console.log(cleanIntereses); } if (index > -1) { string.splice(index, 1); string = string.join() } } setIntereses(string) console.log('ETIQUETAS:::', string) } const fetchSectores = async () => { let dataFormEventos = { "tipoCategoria": "intereses" } let axiosConfig = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }; axios.post(`${process.env.NEXT_PUBLIC_URL_API}formatos/ObtenerCategorias`, dataFormEventos, axiosConfig) .then((res) => { let cleanSectores = []; console.log("sectores", res.data.data) setSectores(res.data.data) }) .catch((err) => { }) } useEffect(() => { fetchSectores(); }, []) const limpiaFormulario = () => { setValorsteep(1) setValorEmail('') setErrorMail(false) setCnaeCode('') setshowCnaeModal("none") setErrorExisteMail(false) setValornombre('') setValorApellidos('') setValorDNI('') setValorEmpresa('') setValorTelefono('') setValorMovil('') setValorCp('') setValorPuesto('') setErrorNombre(false) setErrorDni(false) setErrorCnae(false) setErrorapellidos(false) setErrorTelefono(false) setErrorMovil(false) setErrorCP(false) setErrorPuesto(false) setErrorFacturacion(false) setErrorEmpleados(false) setErrorEmpresa(false) setIntereses([]) setCleanIntereses([]) setErrorIntereses(false) setErrorPaso3(false) setmessageLogin('') } const CerrarModal = () => { limpiaFormulario() setusuarioRegistrado(false) props.setMostrarModal(false) } const [errorMail, setErrorMail] = useState(false); const [errorExisteMail, setErrorExisteMail] = useState(false); const [existeMail, setExisteMail] = useState(); const [valorEmail, setValorEmail] = useState(''); const emailChange = (val) => { setValorEmail(val.target.value) setErrorMail(false) setErrorExisteMail(false) } const [errorPass, setErrorPass] = useState(false) const [valorPass, setValorPass] = useState(''); const passChange = (val) => { setValorPass(val.target.value) setErrorPass(false) } const [errorAviso, setErrorAviso] = useState(false) const [errorNombre, setErrorNombre] = useState(false) const [valorNombre, setValornombre] = useState(''); const nombreChange = (val) => { if (nombreFiscalRef.current.checked) { setValornombre(val.target.value) setValorEmpresa(val.target.value + ' ' + valorApellidos) setErrorNombre(false) } else { setValornombre(val.target.value) setErrorNombre(false) } } const [errorApellidos, setErrorapellidos] = useState(false) const [valorApellidos, setValorApellidos] = useState(''); const apellidosChange = (val) => { if (nombreFiscalRef.current.checked) { setValorApellidos(val.target.value) setValorEmpresa(valorNombre + ' ' + val.target.value) setErrorapellidos(false) } else { setValorApellidos(val.target.value) setErrorapellidos(false) } } const [errorDni, setErrorDni] = useState(false) const [valorDNI, setValorDNI] = useState(''); const dniChange = (val) => { console.log('dni change') setValorDNI(val.target.value) setErrorDni(false) let dataFormDNI = { "Cif": val.target.value } let axiosConfig = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }; axios.post(`${process.env.NEXT_PUBLIC_URL_API}plataformas/ObtenerClientePorCIF`, dataFormDNI, axiosConfig) .then((res) => { console.log("datos POR NIF", res.data.data) setValorEmpresa(res.data.data.nombre) setCnaeCode(res.data.data.cnae) setValorFacturacion(res.data.data.facturacion) setValorEmpleados(res.data.data.empleados) }) .catch((err) => { console.log(err); }) } const [errorEmpresa, setErrorEmpresa] = useState(false) const [valorEmpresa, setValorEmpresa] = useState(''); const empresaChange = (val) => { if (nombreFiscalRef.current.checked) { setValorEmpresa(valorNombre + ' ' + valorApellidos) } else { setValorEmpresa(val.target.value) setErrorEmpresa(false) setErrorPaso3(false) } } function handleAutonomo() { if (nombreFiscalRef.current.checked) { setValorEmpresa(valorNombre + ' ' + valorApellidos) setErrorEmpresa(false) setErrorPaso3(false) } if (!nombreFiscalRef.current.checked) { setValorEmpresa('') setErrorEmpresa(false) setErrorPaso3(false) } } const [errorCnae, setErrorCnae] = useState(false) const [cnaeCode, setCnaeCode] = useState(''); const [cnaeDescription, setCnaeDescription] = useState(''); const [showCnaeModal, setshowCnaeModal] = useState("none"); const cnaeChange = (val) => { setErrorCnae(false) setErrorPaso3(false) } const openModalCnae = () => { setshowCnaeModal("block") } const pickCnae = (cnae, cnaeD) => { setCnaeCode(cnae); setCnaeDescription(cnaeD); setshowCnaeModal("none"); } const [errorFacturacion, setErrorFacturacion] = useState(false) const [valorFacturacion, setValorFacturacion] = useState('- Elige una opción -'); const [errorEmpleados, setErrorEmpleados] = useState(false) const [valorEmpleados, setValorEmpleados] = useState('- Elige una opción -'); const [errorPuesto, setErrorPuesto] = useState(false) const [valorPuesto, setValorPuesto] = useState(''); const puestoChange = (val) => { setValorPuesto(val.target.value) setErrorPuesto(false) setErrorPaso3(false) } const [errorTelefono, setErrorTelefono] = useState(false) const [valorTelefono, setValorTelefono] = useState(''); const telefonoChange = (val) => { setValorTelefono(val.target.value) setErrorTelefono(false) setErrorPaso3(false) } const [errorMovil, setErrorMovil] = useState(false) const [valorMovil, setValorMovil] = useState(''); const movilChange = (val) => { setValorMovil(val.target.value) setErrorMovil(false) setErrorPaso3(false) } const [errorCP, setErrorCP] = useState(false) const [valorCp, setValorCp] = useState(''); const cpChange = (val) => { if (residenteEspanaRef.current.checked) { setValorCp('00000') setErrorCP(false) setErrorPaso3(false) } if (!residenteEspanaRef.current.checked) { setValorCp(val.target.value) setErrorCP(false) setErrorPaso3(false) } } function handleResidente() { if (residenteEspanaRef.current.checked) { setValorCp('00000') setErrorCP(false) setErrorPaso3(false) } if (!residenteEspanaRef.current.checked) { setValorCp('') setErrorCP(false) setErrorPaso3(false) } } const validaPasoUno = async () => { var regex = /^[-\w.%+]{1,64}@(?:[A-Z0-9-]{1,63}\.){1,125}[A-Z]{2,63}$/i; let dataForm = { "email": valorEmail.toLowerCase(), } let axiosConfig = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, } await axios.post(`${process.env.NEXT_PUBLIC_URL_API}auth/ExisteUsuarioRegistro`, dataForm, axiosConfig) .then((res) => { console.log(res) setExisteMail(false) console.log("existeMailFalse:", existeMail); if (!regex.test(valorEmail)) { setErrorMail(true) } if (!existeMail && regex.test(valorEmail)) { setValorsteep(valorSteep + 1) } }) .catch((err) => { console.log(err) setExisteMail(true) setErrorExisteMail(true) console.log("existeMailTrue:", existeMail); }) } const validaPasoDos = () => { let formHasError = false var regex = /^(?=.*[0-9])(?=.*[!@#$%^&-_*])[a-zA-Z0-9!@#$%^&-_*]{6,16}$/; var regexchar = /^(?=.*[!@#$%^&-_*])[a-zA-Z0-9!@#$%^&-_*]{6,16}$/; if (regex.test(valorPass) || regexchar.test(valorPass)) { setErrorPass(false) } else { setErrorPass(true) formHasError = true } if (!terminosRef.current.checked) { formHasError = true setErrorAviso(true) } else { setErrorAviso(false) } !formHasError && setValorsteep(valorSteep + 1) } function titleCase(str) { var splitStr = str.toLowerCase().split(' '); for (var i = 0; i < splitStr.length; i++) { splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1); } return splitStr.join(' '); } function findWordInCargo(str) { let cleanCargo = []; var words = str.split(' '); words.map(word => { if (word === 'De') { word = 'de'; } if (word === 'Y') { word = 'y'; } cleanCargo.push(word) }) cleanCargo = cleanCargo.join(' ') return cleanCargo; } const FinalizaInscripcion = async () => { let formHasError = false; const telefonoRegex = /^[0-9]*$/; if (valorNombre.length == 0) { formHasError = true setErrorNombre(true) setErrorPaso3(true) } else { setErrorNombre(false) } if (valorApellidos.length == 0) { formHasError = true setErrorapellidos(true) setErrorPaso3(true) } else { setErrorapellidos(false) } if (valorDNI.length != 9) { formHasError = true setErrorDni(true) setErrorPaso3(true) } else { setErrorDni(false) } if (valorEmpresa.length == 0) { formHasError = true setErrorEmpresa(true) setErrorPaso3(true) } else { setErrorEmpresa(false) } if (cnaeCode != null && cnaeCode.length == 0) { //formHasError = true //setErrorCnae(true) //setErrorPaso3(true) setErrorCnae(false) //cnae ahora no es obligatorio } else { setErrorCnae(false) } if (valorFacturacion === '- Elige una opción -') { // formHasError = true //setErrorFacturacion(true) //setErrorPaso3(true) setErrorFacturacion(false) //facturacion ahora no es obligatorio } else { setErrorFacturacion(false) } if (valorEmpleados === '- Elige una opción -') { //formHasError = true //setErrorEmpleados(true) //setErrorPaso3(true) setErrorEmpleados(false) //empleados ahora no es obligatorio } else { setErrorEmpleados(false) } if (valorFacturacion === 'sin determinar') { formHasError = true setErrorFacturacion(true) setErrorPaso3(true) } else { setErrorFacturacion(false) } if (valorEmpleados === 'sin determinar') { formHasError = true setErrorEmpleados(true) setErrorPaso3(true) } else { setErrorEmpleados(false) } if (valorTelefono.length <= 7 || valorTelefono.length >= 14 || !telefonoRegex.test(valorTelefono)) { formHasError = true setErrorTelefono(true) setErrorPaso3(true) } else { setErrorTelefono(false) } if (valorMovil.length >= 14 || !telefonoRegex.test(valorMovil)) { formHasError = true setErrorMovil(true) setErrorPaso3(true) } else { setErrorMovil(false) } if (valorPuesto.length == 0) { formHasError = true setErrorPuesto(true) setErrorPaso3(true) } else { setErrorPuesto(false) } if (valorCp.length != 5) { formHasError = true setErrorCP(true) setErrorPaso3(true) } else { setErrorCP(false) } console.log('intereses::', intereses) console.log('intereses::', intereses.length) if (intereses.length <= 0) { formHasError = true setErrorIntereses(true) setErrorPaso3(true) } else { setErrorIntereses(false) } if (formHasError) return try { var dataForm = { "Email": valorEmail.toLowerCase(), "usuario": titleCase(valorNombre), "Password": valorPass, "Nombre": titleCase(valorNombre), "Apellidos": titleCase(valorApellidos), "CifEmpresa": valorDNI, "NombreEmpresa": valorEmpresa.toUpperCase(), "Puesto": findWordInCargo(titleCase(valorPuesto)), "Intereses": intereses, "TelefonoEmpresa": valorTelefono.split(" ").join(""), "movil": valorMovil.split(" ").join(""), "CPEmpresa": valorCp, "Cnae": cnaeCode, "DescripcionCnae": cnaeDescription, "Facturacion": valorFacturacion, "Empleados": valorEmpleados, "enlaceReturn": window.location.pathname, "CodigoEvento": props.idEvento } let axiosConfig = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, }; await axios.post(`${process.env.NEXT_PUBLIC_URL_API}auth/RegistroWebBotonInscribirse`, dataForm, axiosConfig) .then(resLogin => { if (resLogin.status === 200) { if (resLogin.data === 'error') { console.log(resLogin.data) setformIsInvalid(true) messageLoginChange('Email ya existe') setValorsteep(1) } else { console.log('registrado:: form',dataForm) console.log('registrado:: 01',resLogin.data) setErrorPaso3(false) setformIsInvalid(false) setusuarioRegistrado(true) setQuitarPaso(true) } } else { console.log(resLogin) setformIsInvalid(true) messageLoginChange('Email ya existe') setValorsteep(1) } }) console.log(dataForm) } catch (error) { messageLoginChange('Ha habido un error, intentelo de nuevo más tarde') setformIsInvalid(true) } } if (!sectores) { return (
) } return (CerrarModal()}> cerrar x
Te hemos enviado un email para verificar tu cuenta de usuario en nuestra plataforma y finalizar tu inscripción. Por favor, revisa tu bandeja de entrada, correo no deseado o spam
Si tienes alguna duda o problema con la recepción de nuestros correos, puedes ponerte en contacto con nosotros escribiendo a incidencias@businessplus.esSi no conoces tu CNAE, puedes usar nuestro buscador de actividades para localizarlo. Para activarlo pincha en la lupa