Rev 6954 | Rev 7248 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useEffect, useRef, useState } from 'react'import { axios, scrollToBottom } from '../../utils'import { useDispatch } from 'react-redux'import { addNotification } from '../../redux/notification/notification.actions'import InboxIcon from '@mui/icons-material/Inbox'import Chat from './Chat'import EmptySection from '../UI/EmptySection'import ConferenceModal from '../modals/ConferenceModal'import useMessages from '../../hooks/useMessages'const CHAT_TABS = {CHAT: 'CHAT',DEFAULT: 'DEFAULT',GROUP_MEMBERS: 'GROUP_MEMBERS',ADD_GROUP_MEMBER: 'ADD_GROUP_MEMBER',}const ChatBox = ({ entity, changeTab }) => {const {url_get_all_messages,url_mark_received,not_received_messages,not_seen_messages,url_zoom,url_send,url_upload,url_mark_seen,// url_close,url_add_user_to_group, // Group urlurl_delete, // Group urlurl_get_contact_group_list, // Group urlurl_leave, // Group urlname,profile,type,} = entityconst { messages, loadMore, loading, reset } =useMessages(url_get_all_messages)const [isShowConferenceModal, setisShowConferenceModal] = useState(false)const dispatch = useDispatch()const scrollRef = useRef(null)const toggleConferenceModal = () => {setisShowConferenceModal(!isShowConferenceModal)}const deleteGroup = async (url) => {axios.post(url).then(({ data: response }) => {const { data, success } = responseif (!success) {const errorMessage =typeof data.data === 'string' ? data.data : 'Ha ocurrido un error'dispatch(addNotification({ style: 'danger', msg: errorMessage }))return}changeTab(CHAT_TABS.DEFAULT)})}const options = [{url: url_zoom,label: 'Crear Conferencia',action: toggleConferenceModal,},]const groupOptions = [{url: url_zoom,label: 'Crear Conferencia',action: toggleConferenceModal,},{url: url_get_contact_group_list,label: 'Integrantes',action: () => changeTab(CHAT_TABS.GROUP_MEMBERS),},{url: url_add_user_to_group,label: 'Agregar Contactos',action: () => changeTab(CHAT_TABS.ADD_GROUP_MEMBER),},{url: url_delete,label: 'Eliminar Grupo',action: () => deleteGroup(url_delete),},{url: url_leave,label: 'Dejar Grupo',action: () => deleteGroup(url_leave),},]useEffect(() => {if (not_seen_messages) axios.post(url_mark_seen)if (not_received_messages) axios.post(url_mark_received)reset()}, [entity])return (<><Chat><Chat.HeaderonClose={() => changeTab(CHAT_TABS.DEFAULT)}options={type === 'group' ? groupOptions : options}><Chat.Title url={profile}>{name}</Chat.Title></Chat.Header>{!messages.length ? (<EmptySectionIcon={<InboxIcon />}message="No hay mensajes en esta conversación"align="center"/>) : (<Chat.Listmessages={messages}onPagination={loadMore}loading={loading}scrollRef={scrollRef}/>)}<Chat.SubmitFormsendUrl={url_send}uploadUrl={url_upload}onSubmit={() => scrollToBottom(scrollRef)}/></Chat><ConferenceModalshow={isShowConferenceModal}zoomUrl={url_zoom}onClose={toggleConferenceModal}/></>)}export default ChatBox