import React, { Component } from "react"; import { withRouter, } from "react-router-dom"; import { Row, Col, } from 'react-bootstrap' class WhatsappPage extends Component { constructor(props) { super(props); this.state = { inputTel: '', inputAlias: '', inputMensaje: 'Hola ¿Me podrías dar mas información?', editWhatsappStatus: false, indexInput: 0 } } componentDidMount() { } onChangeParentData(opt, event) { const { arrDatos } = this.props.initState const { whatsapp } = arrDatos if(opt === 'titulo') whatsapp.titulo = event.target.value; this.props.initsetState({ arrDatos }) } onAdd() { const { arrDatos } = this.props.initState const { whatsapp } = arrDatos const { inputTel, inputAlias, inputMensaje } = this.state if(inputTel === '' || inputAlias === '' || inputMensaje === '') { alert('Datos incompletos') return false } whatsapp.whatsapp.push({ whatsapp: inputTel, titulo: inputAlias, mensaje: inputMensaje, }) this.props.initsetState({ arrDatos }) this.setState({ inputTel: '', inputAlias: '', inputMensaje: '', }) this.checkMarkValues(); } onDeleteEmail(index) { let { arrDatos } = this.props.initState let { whatsapp } = arrDatos whatsapp.whatsapp.splice(index, 1); this.props.initsetState({ arrDatos }) } onEditWhatsapp(index){ if(this.state.editWhatsappStatus==false){ this.state.indexInput = index this.setState({ editWhatsappStatus: true }) }else{ this.setState({ editWhatsappStatus: 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 { whatsapp } = arrDatos return (
{ ( this.state.editWhatsappStatus==true && this.state.indexInput==index ? { whatsapp.whatsapp[index]['titulo'] = event.target.value; this.props.initsetState({ arrDatos }); }} value={item.titulo} /> :

{item.titulo}

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

{item.whatsapp}

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

{item.mensaje}

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

Whatsapp


Leyenda del Botón

{ this.onChangeParentData('titulo', event) } } type={'text'} placeholder={ 'Ejemplo: ¡Llámame!' } value={whatsapp.titulo} />

Alias

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

Mensaje

{ this.setState({ inputMensaje: event.target.value }) } } type={'text'} placeholder={ 'Ejemplo: Hola ¿Me podrías dar mas información?' } value={ inputMensaje } />

Número de teléfono *

{ this.validatePhone(event) } } type={'text'} placeholder={ 'Ejemplo: (333) 123 - 24 - 56' } value={ inputTel } />

{ this.onAdd() } } >Agregar teléfono

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

); } validatePhone(event){ const val = event.target.value; let content = []; Array.from(val).map(letter=>{ if (/\D/g.test(letter)) letter = letter.replace(/\D/g, ''); if(!isNaN(letter)) { content.push(letter); } }); let string = content.join(""); this.setState({ inputTel: string.trim() }) } initsetState(param) { this.props.initsetState(param) return true } }; export default withRouter(WhatsappPage)