All files / src/Message Message.js

56.52% Statements 13/23
26.66% Branches 4/15
44.44% Functions 4/9
56.52% Lines 13/23

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                  1x 1x                             1x 1x 1x             1x     1x 1x                           1x 1x 1x                                                             1x             1x
import React from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes, MessageUI_propTypes, MessageNew_propTypes} from './props/propTypes';
import { Icon } from '@zohodesk/icons';
import AutoClose from '../actions/AutoClose';
import style from './Message.module.css';
 
export default class Message extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hideMessage: false };
  }
 
  componentWillReceiveProps(nextProps) {
    let { showMessage, hideMessage } = this.props;
    if (showMessage !== nextProps.showMessage) {
      if (nextProps.type != 'alert') {
        setTimeout(() => {
          hideMessage();
        }, 3000);
      }
    }
  }
 
  componentDidMount() {
    let { type, hideMessage } = this.props;
    Eif (type != 'alert') {
      setTimeout(() => {
        hideMessage();
      }, 3000);
    }
  }
 
  render() {
    return <MessageUI {...this.props} />;
  }
}
Message.propTypes = propTypes;
Message.defaultProps = defaultProps;
 
// if (__DOCS__) {
//   Message.docs = {
//     componentGroup: 'Atom'
//   };
// }
 
export function MessageUI(props) {
  function onClose(e) {
    let { hideMessage, onClose } = props;
    hideMessage && hideMessage(e);
    onClose && onClose(e);
  }
  let { type, message, onClick, i18nKeys, dataSelectorId } = props;
  let { closeTitle = 'Close' } = i18nKeys;
  return (
    <div className={style.message} data-id={`show_${type}_message`} data-test-id={`show_${type}_message`} data-selector-id={dataSelectorId}>
      <div className={style.container}>
        <div className={style[type]}>
          <span className={style.tickIcn}>
            <Icon
              name={type == 'alert' ? 'ZD-notifiExclamation' : type == 'info' ? 'ZD-info31' : 'ZD-check'}
              isBold
              size='10'
            />
          </span>
        </div>
 
        <span
          className={style.text}
          onClick={onClick}
          data-id='infoMessage'
          data-test-id='infoMessage'
          dangerouslySetInnerHTML={{
            __html: message
          }}
        />
 
        <span className={style.close} data-title={closeTitle} onClick={onClose} data-id={`close_${type}_message`} data-test-id={`close_${type}_message`}>
          <Icon name='ZD-closee' isBold size='10' />
        </span>
      </div>
    </div>
  );
}
 
MessageUI.propTypes = MessageUI_propTypes;
 
export function MessageNew(props) {
  return <AutoClose {...props} Element={MessageUI} />;
}
 
 
MessageNew.propTypes = MessageNew_propTypes;