All files / src/version2/notification/DesktopNotification DesktopNotification.js

90.47% Statements 19/21
36.76% Branches 25/68
66.66% Functions 4/6
90.47% Lines 19/21

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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210                          1x                                                                                                               1x 1x 1x 1x 1x                   1x 1x   1x 1x   1x 1x     1x         1x               1x                                                                                                                                                                               1x     1x     1x 1x                
import React, { useState } from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes, DesktopNotificationUI_propTypes } from './props/propTypes';
import { Container, Box } from '@zohodesk/components/lib/Layout';
import { useZIndex } from '@zohodesk/components/lib/Provider/ZindexProvider';
import AutoClose from '../../../actions/AutoClose';
import Button from '@zohodesk/components/lib/Button/Button';
import FormAction from '../../../FormAction/FormAction';
import DesktopNotificationHeader from '../DesktopNotificationHeader/DesktopNotificationHeader';
import { ResponsiveReceiver } from '@zohodesk/components/lib/Responsive/CustomResponsive';
 
import style from './DesktopNotification.module.css';
 
let buttonPaletteObject = {
  success: {
    buttonPalette: 'successFilled'
  },
  error: {
    buttonPalette: 'dangerFilled'
  },
  danger: {
    buttonPalette: 'dangerFilled'
  },
  warning: {
    buttonPalette: 'dangerFilled'
  },
  info: {
    buttonPalette: 'primaryFilled'
  },
  notification: {
    buttonPalette: 'primaryFilled'
  },
  primary: {
    buttonPalette: 'primaryFilled'
  }
};
 
export function DesktopNotificationUI(props) {
  let {
    type = '',
    submitText,
    cancelText,
    submitType,
    isMore,
    message,
    isAnimate,
    getBottomContainer,
    getSubmitContainer,
    onSubmit,
    onCancel,
    dataId,
    dataSelectorId,
    isClose,
    needAutoZindex,
    title,
    subTitle,
    needIcon,
    info,
    secondaryInfo,
    titleVariant,
    getSectionContainer,
    isShrinkView,
    size,
    onClose,
    needClose,
    customClass = {},
    i18nKeys = {},
    customProps,
    responsiveId
  } = props;
  let { closeTitle = 'Close' } = i18nKeys;
  let { containerClass } = customClass;
  let { buttonPalette = 'dangerFilled' } = buttonPaletteObject[type] || {};
  let { ExtraProps = {} } = customProps;
 
  function onClickSubmit(e) {
    onSubmit && onSubmit();
  }
 
  function onClickCancel(e) {
    onCancel && onCancel();
  }
 
  let animateClass = isClose ? style.rightanimate : style.leftanimate;
  let animateRemoveClass = isClose ? style.rightanimate : style.leftnoanimate;
 
  let getNextIndex = useZIndex();
  let Zindex = isAnimate ? getNextIndex() : null;
 
  let uiVariantOne = title && (info || secondaryInfo);
  let uiVariantTwo = title && !(info || secondaryInfo) && !getSectionContainer;
 
  function responsiveFunc({ mediaQueryOR }) {
    return {
      uptoTablet: mediaQueryOR([{ maxWidth: 760 }])
    };
  }
 
  return (
    <div
      className={style.parentElement}
      style={needAutoZindex && isAnimate ? { zIndex: `${Zindex}` } : {}}
      data-selector-id={dataSelectorId}
    >
      <ResponsiveReceiver query={responsiveFunc} responsiveId={responsiveId}>
        {({ uptoTablet }) => (
          <Container
            className={`${style.container} ${isAnimate ? animateClass : animateRemoveClass}
            ${isShrinkView ? style.globalNotify : ''} ${containerClass}  ${
              uptoTablet ? style.tapWidth : style[`${size}`]
            }`}
            isCover={false}
            dataId={dataId}
            isInline={uiVariantTwo}
            {...ExtraProps}
          >
            <Box>
              <DesktopNotificationHeader
                type={type}
                title={title}
                variant={titleVariant}
                needIcon={needIcon}
                onClose={onClose}
                closeTitle={closeTitle}
                dataId={`${dataId}_close`}
                needClose={needClose}
              />
            </Box>
            <Box>
              <Container alignBox='column'>
                {uiVariantOne && (
                  <Box flexible>
                    <div className={`${style.section} ${style.infoText}`}>
                      {subTitle && (
                        <div className={`${style.subTitle} ${info || secondaryInfo ? style.subTitleMargin : ''}`}>
                          {subTitle}
                        </div>
                      )}
                      {info && <div>{info}</div>}
                      {secondaryInfo && <div className={`${info ? style.secondaryInfo : ''}`}>{secondaryInfo}</div>}
                    </div>
                  </Box>
                )}
                {getSectionContainer && <Box flexible>{getSectionContainer()}</Box>}
                {submitText || cancelText ? (
                  <Box>
                    <div className={style.footer}>
                      {isMore ? (
                        <div className={`${style.message}`} tagName='p'>
                          {message}
                        </div>
                      ) : null}
                      <FormAction size='small' paddingLeftSize='xmedium'>
                        {submitText ? (
                          <div
                            onClick={onClickSubmit}
                            data-id={`${dataId}_submitButton`}
                            data-test-id={`${dataId}_submitButton`}
                          >
                            <Container align='vertical' alignBox='row'>
                              {getSubmitContainer ? (
                                <Box flexible>{getSubmitContainer()}</Box>
                              ) : (
                                <Box flexible>
                                  <Button text={submitText} palette={submitType ? submitType : buttonPalette} />
                                </Box>
                              )}
                            </Container>
                          </div>
                        ) : null}
                        {cancelText ? (
                          <div>
                            <Button
                              text={cancelText}
                              palette='secondary'
                              dataId={`${dataId}_cancelButton`}
                              onClick={onClickCancel}
                            />
                          </div>
                        ) : null}
                      </FormAction>
                    </div>
                  </Box>
                ) : null}
              </Container>
            </Box>
            {getBottomContainer ? <Box>{getBottomContainer()}</Box> : null}
          </Container>
        )}
      </ResponsiveReceiver>
    </div>
  );
}
 
DesktopNotificationUI.propTypes = DesktopNotificationUI_propTypes;
 
export default function DesktopNotification(props) {
  return <AutoClose {...props} Element={DesktopNotificationUI} />;
}
 
DesktopNotification.propTypes = propTypes;
DesktopNotification.defaultProps = defaultProps;
 
// if (__DOCS__) {
//   DesktopNotification.docs = {
//     componentGroup: 'DesktopNotification',
//     folderName: 'Alert'
//   };
// }