All files / src/form/fields/PhoneField PhoneField.js

67.74% Statements 21/31
41.66% Branches 10/24
42.85% Functions 3/7
67.74% Lines 21/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178                                  1x 1x     1x 1x 1x 1x 1x                 1x 1x 1x                                                                                                     1x 1x 1x 1x 1x           1x 1x     1x     1x                                                                                                                               1x 1x                
/**** Libraries ****/
import React, { PureComponent } from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
 
/**** Components ****/
import { Icon } from '@zohodesk/icons';
import { Container, Box } from '@zohodesk/components/lib/Layout';
import TextBoxField from '../TextBoxField/TextBoxField';
import Link from '../../../Link/Link';
 
/**** CSS ****/
import style from '../Fields.module.css';
import { formatPhoneUrl } from '../../../utils/General';
 
export default class PhoneField extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      isActive: false
    };
    this.handleChange = this.handleChange.bind(this);
    this.handleGetRef = this.handleGetRef.bind(this);
    this.focusInput = this.focusInput.bind(this);
    this.onFocus = this.onFocus.bind(this);
    this.onBlur = this.onBlur.bind(this);
  }
 
  handleChange(id, value) {
    let { onChange } = this.props;
    onChange && onChange(id, value);
  }
 
  handleGetRef(el) {
    let { getRef, id } = this.props;
    this.textBoxElem = el;
    getRef && getRef(el, id);
  }
 
  focusInput(e) {
    this.textBoxElem.focus();
  }
 
  onFocus() {
    let { onFocus } = this.props;
    this.setState({ isActive: true });
    onFocus && onFocus();
  }
  onBlur() {
    let { onBlur } = this.props;
    this.setState({ isActive: false });
    onBlur && onBlur();
  }
 
  render() {
    let {
      labelName,
      id,
      textBoxSize,
      textBoxVariant,
      textBoxType,
      isMandatory,
      validationMessage,
      maxLength,
      isReadOnly,
      value,
      errorType,
      isDisabled,
      title,
      dataId,
      dataSelectorId,
      onKeyDown,
      placeHolder,
      infoText,
      isTelephony,
      providerName,
      ticketId,
      contactId,
      borderColor,
      fieldSize,
      labelPalette,
      labelCustomClass,
      i18nKeys,
      onCall,
      ePhiData,
      type,
      customProps
    } = this.props;
    const { TextBoxFieldProps = {}, LinkProps = {} } = customProps;
    let { isActive } = this.state;
    let { callTitle } = i18nKeys;
    let callBackparam = {
      contact_id: contactId ? contactId : '',
      request_id: ticketId,
      activity_id: '',
      entity_module: 'Requests'
    };
    let phoneValue = value;
    Iif (isActive) {
      phoneValue = value;
    } else {
      phoneValue = formatPhoneUrl(value);
    }
 
    return (
      <Container
        alignBox='row'
        className={`${style.container} ${isDisabled ? style.disabled : ''}`}
        data-title={isDisabled ? title : null}
        dataSelectorId={dataSelectorId}
      >
        <Box flexible>
          <TextBoxField
            labelName={labelName}
            id={id}
            palette={isMandatory ? 'mandatory' : 'default'}
            onClick={this.focusInput}
            infoText={infoText}
            type={textBoxType}
            textBoxVariant={textBoxVariant}
            size={textBoxSize}
            maxLength={maxLength}
            isReadOnly={isReadOnly}
            getRef={this.handleGetRef}
            value={phoneValue}
            onChange={this.handleChange}
            dataId={dataId}
            onBlur={this.onBlur}
            onFocus={this.onFocus}
            onKeyDown={onKeyDown}
            placeHolder={placeHolder}
            validationMessage={validationMessage}
            borderColor={borderColor}
            isDisabled={isDisabled}
            fieldSize={fieldSize}
            isMandatory={isMandatory}
            labelPalette={labelPalette}
            labelCustomClass={labelCustomClass}
            errorType={errorType}
            ePhiData={ePhiData}
            {...TextBoxFieldProps}
          />
        </Box>
        <Box>
          {isTelephony && value ? (
            <Link
              className={style.phoneIcon}
              callfrom='phone'
              pbxname={providerName}
              phonenum={value}
              module='RequestDetailsView'
              title={callTitle}
              callBackParam={JSON.stringify(callBackparam)}
              callto={'RequestPhoneNumber'}
              href={true}
              onClick={onCall}
              type={type}
              {...LinkProps}
            >
              <Icon name='ZD-GN-phone' size='14' />
            </Link>
          ) : null}
        </Box>
      </Container>
    );
  }
}
 
PhoneField.propTypes = propTypes;
PhoneField.defaultProps = defaultProps;
 
// if (__DOCS__) {
//   PhoneField.docs = {
//     componentGroup: 'Form Fields',
//     folderName: 'General'
//   };
// }