import { RcLink, RcMenuItem, RcMenuList, RcPopover, styled, } from '@ringcentral/juno'; import { Ignore, Voicemail } from '@ringcentral/juno-icon'; import clsx from 'clsx'; import type { FunctionComponent } from 'react'; import React, { useEffect, useState } from 'react'; import AnswerIcon from '../../assets/images/Answer.svg'; import EndAnswerIcon from '../../assets/images/EndAnswer.svg'; import ForwardIcon from '../../assets/images/Forward_white.svg'; import HoldAnswerIcon from '../../assets/images/HoldAnswer.svg'; import { MoreActionWithIncomingCall } from '../CallLogCallCtrlComponent/MoreActionWithIncomingCall'; import CircleButton from '../CircleButton'; import type { WebRTCNotificationProps } from './WebRTCNotificationSection.interface'; import i18n from './i18n'; import styles from './styles.scss'; const ForwardActiveList = styled.div` max-width: 170px; `; export const WebRTCNotificationSection: FunctionComponent< WebRTCNotificationProps > = ({ call, onCloseNotification, currentNotificationIdentify, logName, subContactNameDisplay, currentLocale, isWide, onIgnore, endAndAnswer, holdAndAnswer, showToVoicemail, toVoicemail, hasActiveSession, answer, forwardingNumbers, onForward, clickForwardTrack = () => {}, renderCallNotificationAvatar, displayEntity, entityType, getAvatarUrl, entityDetailLinkId, openEntityDetailLinkTrack, openEntityDetailLink, reply, enableReply, disableLinks = false, }) => { const [anchorEl, setAnchorEl] = useState(null); const [avatarUrl, setAvatarUrl] = useState(displayEntity?.profileImageUrl); useEffect(() => { if (currentNotificationIdentify) { const { result } = call; if (result) { onCloseNotification(); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [call.result]); useEffect(() => { if (displayEntity && displayEntity.hasProfileImage) { getAvatarUrl(displayEntity).then((url: string) => { setAvatarUrl(url); }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [displayEntity]); const displayMatchedEntity = displayEntity ? { ...displayEntity, profileImageUrl: avatarUrl, } : null; const renderLogSection = () => { const { telephonySessionId } = call; const handleClick = (event: React.MouseEvent) => { clickForwardTrack(); // @ts-expect-error TS(2345): Argument of type 'EventTarget & HTMLButtonElement'... Remove this comment to see the full error message setAnchorEl(event.currentTarget); }; return (
{renderCallNotificationAvatar?.(displayMatchedEntity, entityType)}
{entityDetailLinkId ? ( { openEntityDetailLink?.(entityDetailLinkId); openEntityDetailLinkTrack?.(); }} > {logName} ) : ( logName )}
{subContactNameDisplay && (
{subContactNameDisplay}
)}
  • onIgnore(telephonySessionId)} /> {i18n.getString('ignore', currentLocale)}
  • {enableReply ? ( <> onForward(phoneNumber, telephonySessionId) } enableReply reply={() => reply?.(telephonySessionId)} clickForwardTrack={clickForwardTrack} isWebRTCNotification /> {i18n.getString('more', currentLocale)} ) : ( <> {i18n.getString('forward', currentLocale)} )}
  • {showToVoicemail && !isWide && hasActiveSession && (
  • toVoicemail(telephonySessionId)} /> {i18n.getString('toVoicemail', currentLocale)}
  • )}
    {!hasActiveSession && (
  • answer(telephonySessionId)} /> {i18n.getString('answer', currentLocale)}
  • )} {hasActiveSession && (
  • endAndAnswer(telephonySessionId)} /> {i18n.getString('endAndAnswer', currentLocale)}
  • )} {(isWide || !hasActiveSession) && showToVoicemail && (
  • toVoicemail(telephonySessionId)} /> {i18n.getString('toVoicemail', currentLocale)}
  • )} {hasActiveSession && (
  • holdAndAnswer(telephonySessionId)} /> {i18n.getString('holdAndAnswer', currentLocale)}
  • )}
); }; const renderForwardList = () => { const handleClose = () => { setAnchorEl(null); }; const forward = (e: React.MouseEvent) => { e.stopPropagation(); handleClose(); // TODO: check that type, should switch to getAttribute // @ts-expect-error TS(7015): Element implicitly has an 'any' type because index... Remove this comment to see the full error message const selectedValue = e.currentTarget.attributes['data-value'].value; onForward(selectedValue, call?.telephonySessionId); }; const forwardList = forwardingNumbers.map((phoneNumber) => { return { key: phoneNumber.phoneNumber, text: phoneNumber.label, subText: phoneNumber.phoneNumber, onClick: forward, }; }); forwardList.push({ key: 'custom', text: i18n.getString('custom', currentLocale), subText: null, onClick: forward, }); return ( handleClose()} classes={{ paper: styles.forwardPopover }} > {forwardList.map(({ text, subText, onClick, key }) => (
{text && {text}} {subText && ( {subText} )}
))}
); }; return ( <> {renderLogSection()} {renderForwardList()} ); };