import { RcListItemSecondaryAction, RcListItemText, RcMenu, } from '@ringcentral/juno'; import { Send } from '@ringcentral/juno-icon'; import type { FunctionComponent } from 'react'; import React, { useState, MouseEvent } from 'react'; import type { ReplyWithPattern } from '../../modules/ReplyWithMessageUI'; import BackHeader from '../BackHeaderV2'; import type { OptionsItem, ReplyWithMessageProps, } from './ReplyWithMessagePanel.interface'; import i18n from './i18n'; import { ReplyWithMessagePage, ReplyOptionsList, ReplyOptionItem, SendIcon, StyledCustomMessage, TimeOptionItem, TimeSendIcon, } from './style'; export const ReplyWithMessagePanel: FunctionComponent< ReplyWithMessageProps > = ({ onBackClick, displayCustomMessage, reply, currentLocale, children, options, }) => { const [anchorEl, setAnchorEl] = useState(null); const [selectedIndex, setSelectedIndex] = useState(null); const [popKey, setPopKey] = useState(null); const handleClose = () => { setAnchorEl(null); setPopKey(null); }; const renderMenu = ( { options, pattern }: { options: OptionsItem[]; pattern: ReplyWithPattern }, index: number, ) => { return ( {options.map((item: any, subIndex: number) => { return ( { reply({ replyWithPattern: { pattern, time: item.timeValue, timeUnit: item.timeUnits, }, }); onBackClick(); }} key={`time-${item.timeValue}-${index}`} > ); })} ); }; return ( {options.map((item, index) => { return item.options ? (
) => { setAnchorEl(event.currentTarget); setPopKey(`pop-${index}`); }} onMouseOver={() => { setSelectedIndex(index); }} > {renderMenu(item, index)}
) : ( { setSelectedIndex(index); }} key={item.pattern} selected={index === selectedIndex} onClick={() => { reply({ replyWithPattern: { pattern: item.pattern, }, }); onBackClick(); }} > ); })}
{displayCustomMessage && ( { const reg = /([^\s])/g; if (event.key === 'Enter') { event.preventDefault(); } if (event.key === 'Enter' && reg.test(event.target?.value)) { reply({ replyWithText: event.target.value }); onBackClick(); } }} /> )} {children}
); };