Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import PropTypes from 'prop-types';
- import KMBLoader from 'components/layout/KMBLoader';
- import Table from 'components/layout/Table';
- import Confirm from 'components/layout/Confirm';
- import { connect } from 'react-redux';
- import { hideModal, addNotification } from 'actions';
- import Confirmer from 'components/layout/Confirmer';
- import { OverlayTrigger, Tooltip } from 'react-bootstrap';
- import { getPresetEmails, deletePresetEmail, updatePresetEmailPublicStatus, deleteContact, updatePresetEmail, createPresetEmail, createCustomEmail } from "actions/presetEmails"
- import KMBEditor from 'components/layout/KMBEditor';
- class EmailHooks extends React.Component {
- constructor( props ) {
- super( props );
- this.state = {
- wordConfirmed: null,
- toggledCells: [],
- ready: false,
- disableSave: null,
- emailValue : "",
- contacts : this.props.mode === "edit" && this.props.emails.data[ 0 ].contacts,
- subjectEditPreset : this.props.isHook === false && this.props.emails.data[ 0 ] && this.props.emails.data[ 0 ].template.subject,
- newPresetSubject : ""
- }
- this.handleBody = this.handleBody.bind( this );
- this.onRender = this.onRender.bind( this );
- this.toggleActions = this.toggleActions.bind( this );
- this.deleteContact = this.deleteContact.bind( this );
- this.prepareVars = this.prepareVars.bind( this );
- this.prepareSpecificVars = this.prepareSpecificVars.bind( this );
- this.submitEmails = this.submitEmails.bind( this );
- this.cancelEdit = this.cancelEdit.bind( this );
- this.emailTemplateChanged = this.emailTemplateChanged.bind( this );
- this.createEmail = this.createEmail.bind( this );
- this.createDefaultEmail = this.createDefaultEmail.bind( this );
- this.createNewPresetEmail = this.createNewPresetEmail.bind( this )
- this.excludedArea = null;
- this.emails = null;
- this.array = [];
- }
- componentWillUnmount() {
- document.body.removeEventListener( 'click', this.handleBody );
- }
- componentDidMount() {
- document.body.addEventListener( 'click', this.handleBody );
- const { getHookEmails, event, hook } = this.props;
- if( this.props.isHook ){
- getHookEmails( event.id, hook.id )
- .then( ( emails ) => {
- this.emails= JSON.parse( JSON.stringify( emails ) );
- this.setState( {
- ready: true,
- disableSave: new Array( emails.data.length ).fill( true )
- } )
- } );
- }else{
- this.emails = this.props.emails
- this.setState( {
- ready: true,
- } )
- }
- }
- toggleActions( e, id ) {
- this.excludedArea = e.target.parentNode;
- let toggledCells = [ id ];
- this.setState( { toggledCells } );
- }
- handleBody( e ) {
- if( this.state.toggledCells.length > 0 && ! this.excludedArea.contains( e.target ) ) {
- this.setState( { toggledCells: [] } );
- }
- }
- deleteContact( emailId, contacts ) {
- if( this.props.mode ==="edit" ){
- this.editPresetEmail( this.props.orgId, this.props.hook.id, contacts )
- }else{
- this.props.saveEmail( this.props.eventId, this.props.hook.id, emailId, "edit", { data: { contacts, action: "deleteContact" } } )
- .then( email=>{
- const newData = this.emails.data.map( x => {
- if ( x.id === email.data.id ) {
- return email.data;
- }
- return x;
- } )
- this.emails.data = newData;
- } )
- }
- }
- onRender( col, item ) {
- switch( col.key ) {
- case 'cosmetic': {
- return(
- <span className="icon-users"></span>
- )
- }
- case 'actions': {
- if( this.props.mode === "edit" && this.props.isHook === false ){
- let editTt = <Tooltip id={`tooltip-edit-${item.id}`}>Edit</Tooltip>
- let tooltip = <Tooltip className="delete-tooltip" id={`tooltip-delete-${item.id}`}>Delete</Tooltip>;
- let deleteBody = (
- <div>
- <p>This action will permanently delete the contact with ID: <strong>{item.id}</strong></p>
- <p><span>{item.name}</span></p>
- <p>Are you sure that you want to delete this contact?</p>
- <p>If yes, then please type: CONFIRM DELETE</p>
- <Confirmer
- word="confirm delete"
- onSuccess={ () => {
- this.setState( { wordConfirmed: true } )
- }}
- onFail={ () => {
- if( this.state.wordConfirmed ) {
- this.setState( { wordConfirmed: false } );
- }
- }}
- />
- </div>
- );
- let deleteTd =
- <OverlayTrigger placement="top" overlay={tooltip}>
- <span className="confirm-holder">
- <Confirm
- onConfirm={ () => {
- this.setState( {
- wordConfirmed: false
- }, () => {
- let contacts = [];
- this.props.emails.data.map( email => {
- email.contacts.map( ( contact, index ) => {
- if( contact.id ===item.id ){
- email.contacts.splice( index, 1 )
- contacts = email.contacts
- }
- } )
- } )
- this.deleteContact( item.emailId, contacts );
- } )
- }}
- body={ deleteBody }
- className="delete-event"
- confirmText="Confirm Delete"
- disabled={ this.state.wordConfirmed ? false : true }
- title="Delete Action! Are you sure?"
- onClose={
- () => {
- this.setState( { wordConfirmed: false } );
- }
- }
- >
- <button type="button" className="btn circle">
- <span className="icon-delete"></span>
- </button>
- </Confirm>
- </span>
- </OverlayTrigger>
- const emails = this.emails.data;
- let index = emails.map( x => x.id ).indexOf( Number( item.emailId ) );
- const template = JSON.stringify( { html : this.state.emailValue } )
- let editTd = (
- <OverlayTrigger placement="top" overlay={editTt}>
- <button
- type="button"
- className="btn circle"
- onClick={ () => {return this.props.contactModal( this.props.orgId, this.props.hook.id, this.props.emails.data[ 0 ].id, { template, contacts :this.state.contacts }, "editContact", item, this.props.innerHook, false, "edit", null, null, null, item.id );} }
- >
- <span className="icon-edit">
- </span>
- </button>
- </OverlayTrigger>
- );
- return(
- <div className="clearfix">
- <div className="event-actions" onClick={ ( e ) => this.toggleActions( e, item.id ) }>
- <span className="toggle-actions"></span>
- </div>
- <div className={`actions-wrapper${this.state.toggledCells.includes( item.id ) ? '' : ' hidden'}`}>
- { editTd }
- { deleteTd }
- </div>
- </div>
- )
- }
- if( this.props.mode !== "create" && this.props.mode !== "custom" ){
- let editTt = <Tooltip id={`tooltip-edit-${item.id}`}>Edit</Tooltip>
- let tooltip = <Tooltip className="delete-tooltip" id={`tooltip-delete-${item.id}`}>Delete</Tooltip>;
- let deleteBody = (
- <div>
- <p>This action will permanently delete the contact with ID: <strong>{item.id}</strong></p>
- <p><span>{item.name}</span></p>
- <p>Are you sure that you want to delete this contact?</p>
- <p>If yes, then please type: CONFIRM DELETE</p>
- <Confirmer
- word="confirm delete"
- onSuccess={ () => {
- this.setState( { wordConfirmed: true } )
- }}
- onFail={ () => {
- if( this.state.wordConfirmed ) {
- this.setState( { wordConfirmed: false } );
- }
- }}
- />
- </div>
- );
- let deleteTd =
- <OverlayTrigger placement="top" overlay={tooltip}>
- <span className="confirm-holder">
- <Confirm
- onConfirm={ () => {
- this.setState( {
- wordConfirmed: false
- }, () => {
- let contacts = [];
- this.props.innerHook.emails.data.map( ( v/*, i*/ ) => {
- let index;
- if ( v.id == item.emailId ) {
- index = v.contacts.map( x => x.id ).indexOf( item.id )
- v.contacts.splice( index, 1 );
- contacts = v.contacts
- }
- } )
- this.deleteContact( item.emailId, contacts );
- } )
- }}
- body={ deleteBody }
- className="delete-event"
- confirmText="Confirm Delete"
- disabled={ this.state.wordConfirmed ? false : true }
- title="Delete Action! Are you sure?"
- onClose={
- () => {
- this.setState( { wordConfirmed: false } );
- }
- }
- >
- <button type="button" className="btn circle">
- <span className="icon-delete"></span>
- </button>
- </Confirm>
- </span>
- </OverlayTrigger>
- const emails = this.emails.data;
- let index = emails.map( x => x.id ).indexOf( Number( item.emailId ) );
- let editTd = (
- <OverlayTrigger placement="top" overlay={editTt}>
- <button
- type="button"
- className="btn circle"
- onClick={ () => {return this.props.contactModal( this.props.eventId, this.props.hook.id, Number( item.emailId ), this.emails.data[ index ], "editContact", item, this.props.innerHook );} }
- >
- <span className="icon-edit">
- </span>
- </button>
- </OverlayTrigger>
- );
- return(
- <div className="clearfix">
- <div className="event-actions" onClick={ ( e ) => this.toggleActions( e, item.id ) }>
- <span className="toggle-actions"></span>
- </div>
- <div className={`actions-wrapper${this.state.toggledCells.includes( item.id ) ? '' : ' hidden'}`}>
- { editTd }
- { deleteTd }
- </div>
- </div>
- )
- }else if( this.props.mode === "custom" ){
- let editTt = <Tooltip id={`tooltip-edit-${item.id}`}>Edit</Tooltip>
- let tooltip = <Tooltip className="delete-tooltip" id={`tooltip-delete-${item.id}`}>Delete</Tooltip>;
- let deleteBody = (
- <div>
- <p>This action will permanently delete the contact with ID: <strong>{item.id}</strong></p>
- <p><span>{item.name}</span></p>
- <p>Are you sure that you want to delete this contact?</p>
- <p>If yes, then please type: CONFIRM DELETE</p>
- <Confirmer
- word="confirm delete"
- onSuccess={ () => {
- this.setState( { wordConfirmed: true } )
- }}
- onFail={ () => {
- if( this.state.wordConfirmed ) {
- this.setState( { wordConfirmed: false } );
- }
- }}
- />
- </div>
- );
- let deleteTd =
- <OverlayTrigger placement="top" overlay={tooltip}>
- <span className="confirm-holder">
- <Confirm
- onConfirm={ () => {
- this.setState( {
- wordConfirmed: false
- }, () => {
- this.props.deleteContact( item.id, "custom" )
- } )
- }}
- body={ deleteBody }
- className="delete-event"
- confirmText="Confirm Delete"
- disabled={ this.state.wordConfirmed ? false : true }
- title="Delete Action! Are you sure?"
- onClose={
- () => {
- this.setState( { wordConfirmed: false } );
- }
- }
- >
- <button type="button" className="btn circle">
- <span className="icon-delete"></span>
- </button>
- </Confirm>
- </span>
- </OverlayTrigger>
- let editTd = (
- <OverlayTrigger placement="top" overlay={editTt}>
- <button
- type="button"
- className="btn circle"
- onClick={ () => {return this.props.contactModal( this.props.eventId, 1, item.id, { id :1, contacts:[] }, "editContact", item, this.props.innerHook, false, "create", this.props.eventId, this.props.mode );} }
- >
- <span className="icon-edit">
- </span>
- </button>
- </OverlayTrigger>
- );
- return(
- <div className="clearfix">
- <div className="event-actions" onClick={ ( e ) => this.toggleActions( e, item.id ) }>
- <span className="toggle-actions"></span>
- </div>
- <div className={`actions-wrapper${this.state.toggledCells.includes( item.id ) ? '' : ' hidden'}`}>
- { editTd }
- { deleteTd }
- </div>
- </div>
- )
- }else if( this.props.mode === "create" ){
- let editTt = <Tooltip id={`tooltip-edit-${item.id}`}>Edit</Tooltip>
- let tooltip = <Tooltip className="delete-tooltip" id={`tooltip-delete-${item.id}`}>Delete</Tooltip>;
- let deleteBody = (
- <div>
- <p>This action will permanently delete the contact with ID: <strong>{item.id}</strong></p>
- <p><span>{item.name}</span></p>
- <p>Are you sure that you want to delete this contact?</p>
- <p>If yes, then please type: CONFIRM DELETE</p>
- <Confirmer
- word="confirm delete"
- onSuccess={ () => {
- this.setState( { wordConfirmed: true } )
- }}
- onFail={ () => {
- if( this.state.wordConfirmed ) {
- this.setState( { wordConfirmed: false } );
- }
- }}
- />
- </div>
- );
- let deleteTd =
- <OverlayTrigger placement="top" overlay={tooltip}>
- <span className="confirm-holder">
- <Confirm
- onConfirm={ () => {
- this.setState( {
- wordConfirmed: false
- }, () => {
- this.props.deleteContact( item.id, "create" )
- } )
- }}
- body={ deleteBody }
- className="delete-event"
- confirmText="Confirm Delete"
- disabled={ this.state.wordConfirmed ? false : true }
- title="Delete Action! Are you sure?"
- onClose={
- () => {
- this.setState( { wordConfirmed: false } );
- }
- }
- >
- <button type="button" className="btn circle">
- <span className="icon-delete"></span>
- </button>
- </Confirm>
- </span>
- </OverlayTrigger>
- let editTd = (
- <OverlayTrigger placement="top" overlay={editTt}>
- <button
- type="button"
- className="btn circle"
- onClick={ () => {return this.props.contactModal( this.props.eventId, 1, item.id, { id :1, contacts:[] }, "editContact", item, this.props.innerHook, false, "create", this.props.eventId, this.props.mode );} }
- >
- <span className="icon-edit">
- </span>
- </button>
- </OverlayTrigger>
- );
- return(
- <div className="clearfix">
- <div className="event-actions" onClick={ ( e ) => this.toggleActions( e, item.id ) }>
- <span className="toggle-actions"></span>
- </div>
- <div className={`actions-wrapper${this.state.toggledCells.includes( item.id ) ? '' : ' hidden'}`}>
- { editTd }
- { deleteTd }
- </div>
- </div>
- )
- }
- }
- }
- }
- prepareVars() {
- const { hook } = this.props;
- let _r = '';
- hook.available_vars.forEach( v => _r += `${ v.value }, ` );
- return _r.trim().slice( 0, -1 );
- }
- prepareVarsFromProps() {
- const { globalVars } = this.props;
- let _r = '';
- globalVars.forEach( v => _r += `${ v.value }, ` );
- return _r.trim().slice( 0, -1 );
- }
- prepareSpecificVars( e ){
- if ( e.available_vars.length ) {
- let _r = '';
- e.available_vars.forEach( v => _r += `${ v.value }, ` );
- return <p>Specific Variables: <span className="kmb-hooks-actions-available-variables">{_r.trim().slice( 0, -1 )}</span></p>;
- }
- }
- cancelEdit() {
- this.props.cancelEdit();
- }
- deleteEmail( item, index ) {
- let deleteSpan = <Tooltip id={`tooltip-deleteemail-${item.id}`}>Delete Email</Tooltip>
- const deleteBody = (
- <div>
- <p>This action will permanently delete the email with ID: <strong>{item.id}</strong></p>
- <p>Are you sure that you want to delete this email?</p>
- <p>If yes, then please type: CONFIRM DELETE</p>
- <Confirmer
- word="confirm delete"
- onSuccess={ () => {
- this.setState( { wordConfirmed: true } )
- }}
- onFail={ () => {
- if( this.state.wordConfirmed ) {
- this.setState( { wordConfirmed: false } );
- }
- }}
- />
- </div>
- );
- const deletedItem =
- <OverlayTrigger
- placement="top"
- overlay={deleteSpan}
- >
- <span className="confirm-holder">
- <Confirm
- onConfirm={ () => {
- this.setState( {
- wordConfirmed: false
- }, () => {
- this.props.deleteItem( {
- emailId: item.id,
- hookId: this.props.hook.id,
- eventId: this.props.eventId
- }
- , "hookEmails" ).then( () => {
- const newState = this.state.disableSave;
- newState.splice( index, 1 );
- this.emails.data.splice( index, 1 );
- const el = document.querySelector( `#tooltip-deleteemail-${item.id}` ) || {};
- ( el.style ||{} ).display="none";
- this.setState( { disableSave: newState } );
- } )
- } )
- }}
- body={ deleteBody }
- className="delete-event"
- confirmText="Confirm Delete"
- disabled={ this.state.wordConfirmed ? false : true }
- title="Delete Action! Are you sure?"
- onClose={
- () => {
- this.setState( { wordConfirmed: false } );
- const el = document.querySelector( `#tooltip-deleteemail-${item.id}` ) || {};
- ( el.style ||{} ).display="none";
- }
- }
- >
- <span className="icon-close"
- onMouseOver={() => {
- if ( !document.querySelector( `#tooltip-deleteemail-${item.id}` ) ){
- return false;
- }
- const el = document.querySelector( `#tooltip-deleteemail-${item.id}` ) || {};
- ( el.style ||{} ).display="block";
- }}></span>
- </Confirm>
- </span>
- </OverlayTrigger>
- return deletedItem;
- }
- submitEmails( emailId, index ) {
- this.props.saveEmail( this.props.eventId, this.props.hook.id, emailId, "edit", { data: { template:JSON.stringify( this.emails.data[ index ].template ) } } )
- .then( () => {
- const newState = this.state.disableSave
- newState[ index ] = true;
- this.setState( { disableSave: newState } );
- } );
- }
- handleChange = ( event, e ) => {
- this.setState( prevState => ( {
- emailSubject: {
- ...prevState.emailSubject,
- [ e.id ]: event.target.value,
- },
- } ) );
- }
- reseToDefault( emailId, index ) {
- this.props.resetEmail( this.props.eventId, this.props.hook.id, emailId, "edit", { data: { resetTemplate: true } } )
- .then( ( email ) => {
- this.emails.data[ index ] = JSON.parse( JSON.stringify( email.data ) );
- const newState = this.state.disableSave
- newState[ index ] = true;
- this.setState( { disableSave: newState } );
- } );
- }
- presetEmailChanged( data ){
- this.setState( { emailValue : data } )
- }
- emailTemplateChanged( index, data ){
- if( !this.state.ready ) return;
- let expectedEmail = this.props.innerHook.emails.data[ index ].template.html
- .replace( /\n/gm, "" )
- .replace( /(\s*style=\s*"[^"]+"\s*)|(\s*style=\s*'[^']+'\s*)/gm, "" )
- // .replace( /(?<=<)\s+|\s+(?=>)|((?<=>)\s+\s+(?=<))|(?<=<\/)\s+|((?<=<)\s+\s+(?=\/))/gm, "" )
- .trim();
- let actualEmail = data
- .replace( /\n/gm, "" )
- .replace( /(\s*style=\s*"[^"]+"\s*)|(\s*style=\s*'[^']+'\s*)/gm, "" )
- // .replace( /(?<=<)\s+|\s+(?=>)|((?<=>)\s+\s+(?=<))|(?<=<\/)\s+|((?<=<)\s+\s+(?=\/))/gm, "" )
- .trim();
- if ( expectedEmail !== actualEmail ){
- const newState = this.state.disableSave
- newState[ index ] = false;
- this.emails.data[ index ].template.html = data;
- this.setState( { disableSave: newState } )
- } else {
- const newState = this.state.disableSave
- newState[ index ] = true;
- this.emails.data[ index ].template.html = data;
- this.setState( { disableSave: newState } )
- }
- }
- createEmail() {
- this.setState( { ready: false } );
- this.props.createEmail( this.props.eventId, this.props.hook.id )
- .then( r => {
- const newState = [ ...this.state.disableSave ];
- newState.unshift( true );
- this.emails.data.unshift( JSON.parse( JSON.stringify( r.data ) ) );
- this.setState( { disableSave: newState, ready:true } )
- } )
- }
- createNewPresetEmail() {
- const template = JSON.stringify( { subject : this.state.newPresetSubject, html : this.state.emailValue } )
- const data = {
- public : 1,
- name : this.state.titleValue,
- template,
- contacts : this.props.tempContacts
- }
- this.props.createPresetEmail( this.props.orgId, data )
- }
- createCustomEmail( ) {
- const template = JSON.stringify( { subject : this.state.newPresetSubject, html : this.state.emailValue } )
- const data = {
- template,
- contacts : this.props.tempCustomContacts
- }
- this.props.createCustomEmail( this.props.eventId, data )
- }
- editPresetEmail( orgId, emailId, contacts ){
- const template = JSON.stringify( { subject : this.state.subjectEditPreset, html : this.state.emailValue } )
- let data ={}
- if( contacts ){
- data = {
- template,
- contacts
- }
- }else{
- data = {
- template,
- }
- }
- this.props.updateEmail( orgId, emailId, data )
- .then( ( email ) => {
- this.setState( { contacts : email.data.contacts } )
- } );
- }
- createDefaultEmail() {
- this.setState( { ready: false } );
- this.props.createEmail( this.props.eventId, this.props.hook.id, true )
- .then( r => {
- const newState = [ ...this.state.disableSave ];
- newState.unshift( true );
- this.emails.data.unshift( JSON.parse( JSON.stringify( r.data ) ) );
- this.setState( { disableSave: newState, ready:true } )
- } )
- }
- render() {
- console.log( this.state )
- const { ready } = this.state;
- if( !ready ) return <KMBLoader rows={ 20 } />
- const emails = this.emails.data;
- const { hook } = this.props;
- let columns = {
- cosmetic: {
- name: ''
- },
- label: {
- name: 'Contact'
- },
- actions: {
- name: ''
- }
- };
- return(
- <div className="form-container">
- <div className="form-container-header">
- {this.props.isHook ?
- // ITS A HOOK
- <React.Fragment>
- <h3 className="left-area col-sm-6"><span>Hook:</span> { hook.hookLabel }</h3>
- <div className="right-area col-sm-6 text-right">
- <button type="button" className="btn dark create-blank-email" onClick={ this.createEmail }><span className="icon-add-1"></span>Create Blank Email</button>
- <button type="button" className="btn dark create-default-email" onClick={ this.createDefaultEmail }><span className="icon-add-1"></span>Create Default Email</button>
- </div>
- </React.Fragment>:
- <React.Fragment>
- {this.props.mode === "edit" ?
- <h3 className="left-area col-sm-6"><span>Preset Email:</span> { hook.name}</h3> :
- this.props.mode === "create" ?
- <div>
- <h2 className="left-area col-sm-12" style={{ paddingTop : 20 }}><span>Title</span> </h2>
- <div className = "left-area col-sm-12" >
- <div className="form-group">
- <div className="kmb-text" style={{ paddingBottom : 30 }}>
- <input
- className={ `form-control` }
- type="text"
- placeholder = "Enter Preset Email's title"
- onChange = {( e ) => this.setState( { titleValue : e.target.value } )}
- />
- </div>
- </div>
- </div>
- </div> :
- null
- }
- </React.Fragment>
- }
- </div>
- {this.props.isHook ?
- // IS A HOOK
- <React.Fragment>
- { emails.map( ( e, i ) => {
- const pos = this.props.innerHook.emails.data.map( x=>x.id === e.id ).indexOf( true )
- const stateEmail = this.props.innerHook.emails.data[ pos ];
- if( !stateEmail ) {return ;}// email has been deleted
- const contacts = stateEmail.contacts;
- let subjectValue = e.template.subject
- return (
- <div key={ i } className="kmb-hooks-actions-row">
- <div className="email-header">
- <h4>Email ID: { e.id }</h4>
- {this.deleteEmail( e, i )}
- </div>
- <div>
- <h2 style={{ paddingTop : 20 }}><span>Subject</span> </h2>
- <div style={{ width : "100%" }} >
- <div className="form-group">
- <div className="kmb-text" style={{ paddingBottom : 30 }}>
- <input
- className={ `form-control` }
- type="text"
- value= {subjectValue|| ""}
- placeholder = "Enter Preset Email's subject"
- onChange={event => this.handleChange( event, e )}
- />
- </div>
- </div>
- </div>
- </div>
- <p>Global Variables: <span className="kmb-hooks-actions-available-variables">{this.prepareVars()}</span></p>
- {this.prepareSpecificVars( e )}
- <KMBEditor
- placeholder={ `Type the content of the email. Use any variables you want, for dynamic injection.` }
- rows={ 50 }
- value={ e.template.html }
- onChange={( data ) =>this.emailTemplateChanged( i, data )}
- />
- <div className="hook-contacts">
- <div className="hook-contacts-header tab-header" style={{ marginTop:15 }}>
- <div className="left-area col-sm-6">
- </div>
- <div className="right-area col-sm-6">
- <button type="button" className="btn dark rounded" onClick={ () => this.props.contactModal( this.props.eventId, hook.id, e.id, e, "createContact", false, this.props.innerHook, true, false ) }><span className="icon-add-1"></span>Add Contact</button>
- <button type="submit" style={{ marginLeft:10 }} disabled={this.state.disableSave[ i ]} className="btn save rounded" onClick={()=>this.submitEmails( e.id, i )}>Save Email</button>
- </div>
- </div>
- <Table
- id={ 'sd' }
- columns={ columns }
- items={ contacts }
- onRender={ this.onRender}
- containerClassName={ `table-container table-responsive` }
- />
- </div>
- </div>
- )
- } ) }
- </React.Fragment> :
- // ITS NOT A HOOK AND IS EDIT PRESET EMAIL
- <React.Fragment>
- {this.props.mode === "edit" ?
- <div key={ this.props.emails.data[ 0 ] } className="kmb-hooks-actions-row">
- <div className="email-header">
- <h4>Email ID: { this.props.emails.data[ 0 ].id }</h4>
- </div>
- <div>
- <h2 style={{ paddingTop : 20 }}><span>Subject</span> </h2>
- <div style={{ width : "100%" }}>
- <div className="form-group">
- <div className="kmb-text" style={{ paddingBottom : 30 }}>
- <input
- className={ `form-control` }
- type="text"
- value = {this.state.subjectEditPreset || ""}
- placeholder = "Enter Preset Email's subject"
- onChange = {( e ) => this.setState( { subjectEditPreset : e.target.value } )}
- />
- </div>
- </div>
- </div>
- </div>
- <p>Global Variables: <span className="kmb-hooks-actions-available-variables">{this.prepareVarsFromProps()}</span></p>
- {/* {this.prepareSpecificVars( this.props.emails.data[ 0 ] )} */}
- <KMBEditor
- placeholder={ `Type the content of the email. Use any variables you want, for dynamic injection.` }
- rows={ 50 }
- value={ this.props.emails.data[ 0 ].template.html }
- onChange={( data ) =>this.presetEmailChanged( data )}
- />
- <div className="hook-contacts">
- <div className="hook-contacts-header tab-header" style={{ marginTop:15 }}>
- <div className="left-area col-sm-6">
- </div>
- <div className="right-area col-sm-6">
- <button type="button" className="btn dark rounded" onClick={ () => this.props.contactModal( this.props.orgId, hook.id, this.props.emails.data[ 0 ].id, this.props.emails.data[ 0 ], "createContact", false, this.props.innerHook, false, "edit" ) }><span className="icon-add-1"></span>Add Contact</button>
- <button type="submit" style={{ marginLeft:10 }} disabled={false} className="btn save rounded" onClick={()=> this.editPresetEmail( this.props.orgId, this.props.emails.data[ 0 ].id )}>Save Email</button>
- </div>
- </div>
- <Table
- id={ 'contacts' }
- columns={ columns }
- items={ this.state.contacts || [] }
- onRender={ this.onRender}
- containerClassName={ `table-container table-responsive` }
- />
- </div>
- </div> :
- // ITS CREATE PRESET EMAIL OR CUSTOM EMAIL
- <div>
- <React.Fragment>
- <div key={ 1 } className="kmb-hooks-actions-row">
- <div>
- <h2 style={{ paddingTop : 20 }}><span>Subject</span> </h2>
- <div style={{ width : "100%" }} >
- <div className="form-group">
- <div className="kmb-text" style={{ paddingBottom : 30 }}>
- <input
- className={ `form-control` }
- type="text"
- placeholder = "Enter Preset Email's subject"
- onChange = {( e ) => this.setState( { newPresetSubject : e.target.value } )}
- />
- </div>
- </div>
- </div>
- </div>
- <p>Global Variables: <span className="kmb-hooks-actions-available-variables">{this.prepareVarsFromProps()}</span></p>
- <KMBEditor
- placeholder={ `Type the content of the email. Use any variables you want, for dynamic injection.` }
- rows={ 50 }
- onChange={( data ) =>this.setState( { emailValue : data } )}
- value= {this.state.emailValue}
- />
- <div className="hook-contacts">
- <div className="hook-contacts-header tab-header" style={{ marginTop:15 }}>
- <div className="left-area col-sm-6">
- </div>
- <div className="right-area col-sm-6">
- <button type="button" className="btn dark rounded" onClick={ () => this.props.contactModal( this.props.orgId, 1, 1, { id :1, contacts:[] }, "createContact", false, this.props.innerHook, false, "create", this.props.eventId, this.props.mode ) }><span className="icon-add-1"></span>Add Contact</button>
- {this.props.mode !== "custom" && <button type="submit" style={{ marginLeft:10 }} disabled={false} className="btn save rounded"
- onClick={() =>this.createNewPresetEmail()} >
- Save Email
- </button>
- }
- </div>
- </div>
- <Table
- id={ 'contacts' }
- columns={ columns }
- items={ this.props.mode === "custom" ? this.props.tempCustomContacts :this.props.tempContacts }
- onRender={ this.onRender}
- containerClassName={ `table-container table-responsive` }
- />
- </div>
- </div>
- </React.Fragment>
- </div>
- }
- </React.Fragment>
- }
- <div className="form-group text-right submit-container" style={{ marginTop: 30 }}>
- {this.props.mode === "custom" ?
- <button type="submit" style={{ marginLeft:10 }} disabled={false} className="btn save rounded"
- onClick={() => this.props.mode=== "custom" ? this.createCustomEmail( ):this.createNewPresetEmail()} >
- Send Email
- </button>:
- <button type="button" className="btn cancel" onClick={this.cancelEdit}>Go back</button>
- }
- </div>
- </div>
- )
- }
- }
- EmailHooks.propTypes = {
- emails : PropTypes.object,
- event: PropTypes.object,
- getHookEmails: PropTypes.func,
- hook: PropTypes.object,
- contactModal: PropTypes.func,
- eventId: PropTypes.number,
- saveEmail: PropTypes.func,
- createEmail: PropTypes.func,
- action: PropTypes.string,
- innerHook: PropTypes.object,
- cancelEdit: PropTypes.func,
- deleteItem: PropTypes.func,
- resetEmail : PropTypes.func,
- isHook : PropTypes.bool,
- mode : PropTypes.string,
- globalVars : PropTypes.any,
- orgId: PropTypes.any,
- createPresetEmail : PropTypes.func,
- tempContacts : PropTypes.any,
- updateEmail : PropTypes.func,
- accessEvents :PropTypes.any,
- loadPresetEmails :PropTypes.func,
- createCustomEmail : PropTypes.func,
- tempCustomContacts : PropTypes.any,
- deleteContact : PropTypes.func,
- presetEmailId : PropTypes.any
- }
- const mapStateToProps = ( state, ownProps ) => {
- return {
- accessEvents: state.appuser.data.accessEvents,
- presetList : state.api.events.presetEmails.data,
- globalVars : state.api.events.presetEmails.meta.available_vars,
- tempContacts : state.api.events.tempContacts,
- tempCustomContacts : state.api.events.tempCustomContacts
- }
- }
- const mapDispatchToProps = ( dispatch ) => {
- return {
- loadPresetEmails : ( eventId ) => {
- dispatch( getPresetEmails( eventId ) );
- },
- createPresetEmail: ( orgId, data ) => {
- dispatch( createPresetEmail( orgId, data ) )
- },
- updateEmail : ( orgId, presetEmailId, data ) => {
- return dispatch( updatePresetEmail( orgId, presetEmailId, data ) )
- },
- deleteContact : ( key, mode ) => {
- dispatch( deleteContact ( key, mode ) )
- },
- createCustomEmail : ( eventId, data )=>{
- return dispatch ( createCustomEmail( eventId, data ) )
- .then( ( ) => {
- dispatch( addNotification( "Email has been sent", "success" ) );
- return null;
- } )
- }
- }
- }
- export default connect( mapStateToProps, mapDispatchToProps )( EmailHooks )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement