import React, { memo, useEffect, useState } from 'react'; import { Switch, View } from 'react-native'; import * as List from '../../../containers/List'; import styles from '../../../views/RoomsListView/styles'; import { SWITCH_TRACK_COLOR, themes } from '../../../lib/constants'; import { useTheme } from '../../../theme'; import UnreadBadge from '../../../presentation/UnreadBadge'; import RocketChat from '../../../lib/rocketchat'; import { changeLivechatStatus, isOmnichannelStatusAvailable } from '../lib'; import { IUser } from '../../../definitions/IUser'; import Touch from '../../../utils/touch'; interface IOmnichannelStatus { searching: boolean; goQueue: () => void; queueSize: number; inquiryEnabled: boolean; user: IUser; } const OmnichannelStatus = memo(({ searching, goQueue, queueSize, inquiryEnabled, user }: IOmnichannelStatus) => { const { theme } = useTheme(); const [status, setStatus] = useState(false); const canUseOmnichannel = RocketChat.isOmnichannelModuleAvailable() && user?.roles?.includes('livechat-agent'); useEffect(() => { if (canUseOmnichannel) { setStatus(isOmnichannelStatusAvailable(user)); } }, [user.statusLivechat]); if (searching || !canUseOmnichannel) { return null; } const toggleLivechat = async () => { try { setStatus(v => !v); await changeLivechatStatus(); } catch { setStatus(v => !v); } }; return ( <> } color={themes[theme].auxiliaryText} onPress={goQueue} right={() => ( {inquiryEnabled ? : null} )} /> ); }); export default OmnichannelStatus;