2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
import { useState, useEffect} from 'react';
|
|
|
|
import MaterialTable from 'material-table';
|
|
|
|
import Modal from '../Modal'
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
import React from 'react';
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
const MTable = (props) => {
|
|
|
|
|
2022-01-25 21:54:46 +00:00
|
|
|
const [selectedRow, setSelectedRow] = useState(null);
|
|
|
|
|
2022-01-25 15:09:27 +00:00
|
|
|
|
2022-02-04 15:31:08 +00:00
|
|
|
//const dataLoad = props.data.map((dt) => { return { ...dt }});
|
|
|
|
const dataLoad = props.data.map(({user, ...others})=>({...others, 'user': user ? user : {name: 'Aguardando atendente', email:''}}));
|
|
|
|
|
|
|
|
const columnsLoad = props.columns.map((column) => { return { ...column }});
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
console.log(`You have clicked the button ${selectedRow} times`)
|
|
|
|
|
|
|
|
},[selectedRow]);
|
|
|
|
|
2022-03-07 02:19:35 +00:00
|
|
|
return (
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
<MaterialTable
|
2022-01-26 12:47:52 +00:00
|
|
|
title= {props.table_title}
|
2022-01-25 15:09:27 +00:00
|
|
|
columns={columnsLoad}
|
2022-03-07 02:19:35 +00:00
|
|
|
data={dataLoad}
|
2022-01-25 21:54:46 +00:00
|
|
|
|
2022-03-07 02:19:35 +00:00
|
|
|
maxWidth={true}
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
onRowClick={(evt, selectedRow) => {
|
|
|
|
|
|
|
|
console.log(selectedRow.tableData.id);
|
|
|
|
console.log(selectedRow);
|
|
|
|
console.log(selectedRow.messages);
|
|
|
|
setSelectedRow(selectedRow.tableData.id)
|
2022-01-26 12:47:52 +00:00
|
|
|
|
|
|
|
if(props.hasChild) {
|
2022-01-26 23:56:57 +00:00
|
|
|
render(<Modal data={selectedRow.messages}
|
|
|
|
hasChild={false}
|
|
|
|
modal_header={'Chat do atendimento pelo Whatsapp'}
|
2022-02-04 15:31:08 +00:00
|
|
|
user={selectedRow.user.name}
|
2022-01-26 23:56:57 +00:00
|
|
|
clientContactNumber={selectedRow.contact.number}/>)
|
2022-01-26 12:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('props.hasChild: ', props.hasChild)
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
//evt.stopPropagation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
options={{
|
|
|
|
search: true,
|
|
|
|
selection: false,
|
2022-01-25 21:54:46 +00:00
|
|
|
paging: false,
|
|
|
|
padding: 'dense',
|
2022-01-26 12:47:52 +00:00
|
|
|
sorting: true ? props.hasChild: false,
|
2022-01-25 21:54:46 +00:00
|
|
|
//loadingType: 'linear',
|
2022-01-24 11:44:42 +00:00
|
|
|
searchFieldStyle: {
|
|
|
|
width: 300,
|
|
|
|
},
|
|
|
|
|
|
|
|
rowStyle: rowData => ({
|
|
|
|
fontSize: 12,
|
2022-01-26 12:47:52 +00:00
|
|
|
backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF'
|
2022-01-24 11:44:42 +00:00
|
|
|
})
|
|
|
|
}}
|
2022-03-07 02:19:35 +00:00
|
|
|
/>
|
2022-01-24 11:44:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
|
|
|
|
export default React.memo(MTable)
|