2022-03-21 05:06:56 +00:00
|
|
|
|
|
|
|
import { useState, useEffect } from 'react';
|
|
|
|
import MaterialTable from 'material-table';
|
|
|
|
import Modal from '../Modal'
|
2022-01-24 11:44:42 +00:00
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
import chat from '@material-ui/icons/Chat';
|
|
|
|
|
|
|
|
// import Button from "@material-ui/core/Button";
|
|
|
|
|
2022-03-21 05:06:56 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
const MTable = (props) => {
|
2022-01-24 11:44:42 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
const tableRef = React.useRef();
|
|
|
|
|
|
|
|
const openInNewTab = url => {
|
|
|
|
window.open(url, '_blank', 'noopener,noreferrer');
|
|
|
|
};
|
|
|
|
|
|
|
|
const [selectedRow, setSelectedRow] = useState(null);
|
2022-08-29 13:55:07 +00:00
|
|
|
|
2022-03-21 05:06:56 +00:00
|
|
|
const dataLoad = props.data.map(({ user, ...others }) => ({ ...others, 'user': user ? user : { name: 'Aguardando atendente', email: '' } }));
|
|
|
|
|
|
|
|
const columnsLoad = props.columns.map((column) => { return { ...column } });
|
2022-07-28 17:55:23 +00:00
|
|
|
|
2022-02-04 15:31:08 +00:00
|
|
|
|
2022-08-29 13:55:07 +00:00
|
|
|
// useEffect(() => {
|
2022-03-21 05:06:56 +00:00
|
|
|
|
2022-10-25 14:16:36 +00:00
|
|
|
//
|
2022-07-28 17:55:23 +00:00
|
|
|
|
2022-08-29 13:55:07 +00:00
|
|
|
// }, [selectedRow]);
|
2022-03-21 05:06:56 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
if (!tableRef.current) return
|
|
|
|
|
|
|
|
const element = tableRef.current.tableContainerDiv.current;
|
|
|
|
|
|
|
|
element.addEventListener('scroll', props.handleScroll);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
element.removeEventListener('scroll', props.handleScroll);
|
|
|
|
};
|
|
|
|
|
|
|
|
}, [props]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-21 05:06:56 +00:00
|
|
|
return (
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
<>
|
|
|
|
{/* <Button onClick={handleTest}>Toggle</Button> */}
|
|
|
|
|
|
|
|
{/* <CircularProgress /> */}
|
|
|
|
|
|
|
|
<MaterialTable
|
|
|
|
title={props.table_title}
|
|
|
|
columns={columnsLoad}
|
|
|
|
data={dataLoad}
|
|
|
|
maxWidth={true}
|
2022-03-21 05:06:56 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
tableRef={tableRef}
|
2022-03-21 05:06:56 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
localization={{ header: { actions: props.hasChild ? 'Ticket' : null },}}
|
|
|
|
|
|
|
|
onRowClick={(evt, selectedRow) => {
|
|
|
|
|
|
|
|
if (props.removeClickRow) {
|
|
|
|
return
|
|
|
|
}
|
2022-08-29 13:55:07 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
setSelectedRow(selectedRow.tableData.id)
|
|
|
|
|
|
|
|
if (props.hasChild) {
|
|
|
|
render(<Modal data={selectedRow.messages}
|
|
|
|
hasChild={false}
|
|
|
|
modal_header={'Chat do atendimento pelo Whatsapp'}
|
|
|
|
user={selectedRow.user.name}
|
|
|
|
clientContactNumber={selectedRow.contact.number} />)
|
|
|
|
}
|
2022-08-29 13:55:07 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
|
|
|
|
//evt.stopPropagation()
|
2022-03-21 05:06:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
|
|
|
|
actions={[
|
|
|
|
(rowData) => {
|
|
|
|
|
|
|
|
if(props.hasChild){
|
|
|
|
return {
|
|
|
|
icon: chat,
|
|
|
|
tooltip: `Ticket id ${rowData.id}`,
|
|
|
|
disable: false,
|
|
|
|
onClick: (event, rowData) => {
|
|
|
|
|
|
|
|
openInNewTab(`/tickets/${rowData.id}`)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
|
|
|
|
options={{
|
|
|
|
search: true,
|
|
|
|
selection: false,
|
|
|
|
paging: false,
|
|
|
|
padding: 'dense',
|
|
|
|
|
|
|
|
exportButton: props.hasChild ? true : null,
|
|
|
|
exportAllData: true,
|
|
|
|
|
|
|
|
sorting: true ? props.hasChild : false,
|
2022-07-28 21:21:14 +00:00
|
|
|
// loadingType: 'circular',
|
2022-07-28 17:55:23 +00:00
|
|
|
searchFieldStyle: {
|
|
|
|
width: 300,
|
|
|
|
},
|
|
|
|
|
|
|
|
pageSize: 20,
|
|
|
|
|
|
|
|
headerStyle: {
|
|
|
|
position: "sticky",
|
|
|
|
top: "0"
|
|
|
|
},
|
|
|
|
|
|
|
|
maxBodyHeight: "400px",
|
|
|
|
// minBodyHeight: "85vh", //FIXME to calculate dynamic height, needed for correct scroll position identification
|
|
|
|
// maxBodyHeight: "85vh",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rowStyle: rowData => ({
|
|
|
|
fontSize: 12,
|
|
|
|
backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF'
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
|
|
|
|
|
2022-03-21 05:06:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-03-21 05:06:56 +00:00
|
|
|
export default React.memo(MTable)
|