import React, { Component } from "react"; import { withRouter, } from "react-router-dom"; import { Row, Col, } from 'react-bootstrap' class EmailPage extends Component { constructor(props) { super(props); this.textInput1 = React.createRef(); this.textInput2 = React.createRef(); this.state = { inputEmail: '', inputAlias: '', inputMensaje: 'Hola ¿Me podrías dar más información?', editEmailStatus: false, indexInput: 0 } } componentDidMount() { const { formValidate } = this.props.initState; const { isValidate,input } = formValidate; if(isValidate){ if(input==="email"){ this.textInput2.current.focus(); } } } onChangeParentData(opt, event) { const { arrDatos } = this.props.initState const { email } = arrDatos if(opt === 'titulo') email.titulo = event.target.value; this.props.initsetState({ arrDatos }) } onAdd() { const { arrDatos } = this.props.initState const { email } = arrDatos const { inputEmail, inputAlias, inputMensaje } = this.state if(inputEmail === '' || inputAlias === '' || inputMensaje === '') { alert('Datos incompletos') return false } email.email.push({ email: inputEmail, mensaje: inputMensaje, titulo: inputAlias, }) this.props.initsetState({ arrDatos }) this.setState({ inputEmail: '', inputMensaje: '', inputAlias: '', }) this.checkMarkValues(); } onDeleteEmail(index) { let { arrDatos } = this.props.initState let { email } = arrDatos email.email.splice(index, 1); this.props.initsetState({ arrDatos }) } onEditEmail(index){ if(this.state.editEmailStatus==false){ this.state.indexInput = index this.setState({ editEmailStatus: true }) }else{ this.setState({ editEmailStatus: false }) } } checkMarkValues(){ const { arrDatos,arrCheck } = this.props.initState const { email,telefono,whatsapp } = arrDatos if(email.email.length > 0 && telefono.telefono.length > 0 && whatsapp.whatsapp.length > 0){ arrCheck[4].checkMark = true; }else{ arrCheck[4].checkMark = false; } } makeList(item, index) { const { arrDatos } = this.props.initState const { email } = arrDatos return (
{ ( this.state.editEmailStatus==true && this.state.indexInput==index ? { email.email[index]['titulo'] = event.target.value; this.props.initsetState({ arrDatos }); }} value={item.titulo} /> :

{item.titulo}

) }
{ ( this.state.editEmailStatus==true && this.state.indexInput==index ? { email.email[index]['email'] = event.target.value; this.props.initsetState({ arrDatos }); }} value={item.email} /> :

{item.email}

) } { ( this.state.editEmailStatus==true && this.state.indexInput==index ? { email.email[index]['mensaje'] = event.target.value; this.props.initsetState({ arrDatos }); }} value={item.mensaje} /> :

{item.mensaje}

) } {'Imagen'} { this.onEditEmail(index) } } /> {'Imagen'} { this.onDeleteEmail(index) } } style={{ width: 40, height: 40, }} src={'img/icons/trash.png'} />
) } render() { const { arrDatos } = this.props.initState const { email } = arrDatos const { inputEmail, inputAlias, inputMensaje } = this.state return (
{ /* Correo */ } {'Imagen'}

Correo electrónico


Leyenda del Botón

{ this.onChangeParentData('titulo', event) } } type={'text'} placeholder={ 'Ejemplo: Escríbeme' } value={email.titulo} />

Alias

{ this.setState({ inputAlias: event.target.value }) } } type={'text'} placeholder={ 'Ejemplo: Oficina' } value={ inputAlias } ref={this.textInput1} />

Mensaje

{ this.setState({ inputMensaje: event.target.value }) } } type={'email'} placeholder={ 'Ejemplo: Hola ¿Podrías dar más información?' } value={ inputMensaje } />

Dirección de correo electrónico *

{ this.setState({ inputEmail: event.target.value }) } } type={'text'} placeholder={ 'Ejemplo: usuario@correo.com' } value={ inputEmail } ref={this.textInput2} />

{ this.onAdd() } } >Agregar correo

{ email.email.length > 0 ? (
{ email.email.map((item, index) => this.makeList(item, index)) }
) : null }

); } initsetState(param) { this.props.initsetState(param) return true } }; export default withRouter(EmailPage)