Finalização da funcionalidade de lembrete/agendameto com remoção das variáveis não usadas

pull/1/head
adriano 2022-03-30 11:09:20 -03:00
parent a36e05992b
commit 56fccf8414
6 changed files with 144 additions and 258 deletions

View File

@ -13,27 +13,14 @@ import DatePicker from '../../Report/DatePicker'
import TimerPickerSelect from '../TimerPickerSelect' import TimerPickerSelect from '../TimerPickerSelect'
import TextareaAutosize from '@mui/material/TextareaAutosize'; import TextareaAutosize from '@mui/material/TextareaAutosize';
import { subHours, addDays, isEqual, subDays} from "date-fns"; import { subHours, addDays, subDays} from "date-fns";
import TextFieldSelectHourBefore from '@mui/material/TextField'; import TextFieldSelectHourBefore from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
import {
IconButton,
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
} from "@material-ui/core";
import { DeleteOutline } from "@material-ui/icons";
import { toast } from "react-toastify";
import api from "../../../services/api"; import api from "../../../services/api";
import toastError from "../../../errors/toastError"; import toastError from "../../../errors/toastError";
import ConfirmationModal from "../../ConfirmationModal";
const reducer = (state, action) => { const reducer = (state, action) => {
@ -109,8 +96,7 @@ Item.propTypes = {
const Modal = (props) => { const Modal = (props) => {
// const [clientSchedules, dispatch] = useReducer(reducer, []); // const [clientSchedules, dispatch] = useReducer(reducer, []);
const [selectedSchedule, setSelectedSchedule] = useState(null); // const [selectedSchedule, setSelectedSchedule] = useState(null);
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
const [open, setOpen] = useState(true); const [open, setOpen] = useState(true);
const [scroll, /*setScroll*/] = useState('body'); const [scroll, /*setScroll*/] = useState('body');
const [statusChatEndId, setStatusChatEnd] = useState(null) const [statusChatEndId, setStatusChatEnd] = useState(null)
@ -161,23 +147,18 @@ const Modal = (props) => {
} }
const handleCloseConfirmationModal = () => { // const handleDeleteSchedule = async (scheduleId) => {
setConfirmModalOpen(false); // try {
setSelectedSchedule(null); // await api.delete(`/schedule/${scheduleId}`);
}; // toast.success(("Lembrete/Agendamento deletado com sucesso!"));
// dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId });
// } catch (err) {
const handleDeleteSchedule = async (scheduleId) => { // toastError(err);
try { // }
await api.delete(`/schedule/${scheduleId}`); // setSelectedSchedule(null);
toast.success(("Lembrete/Agendamento deletado com sucesso!")); // };
dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId });
} catch (err) {
toastError(err);
}
setSelectedSchedule(null);
};
// Get from child 2 // Get from child 2
const datePickerValue = (data) => { const datePickerValue = (data) => {
@ -225,7 +206,7 @@ const timerPickerValue = (data) => {
console.log('Entrou! textArea1: ', textArea1) console.log('Entrou! textArea1: ', textArea1)
if( startDate.trim().length==0){ if( startDate.trim().length === 0){
alert('Selecione uma data atual ou futura!') alert('Selecione uma data atual ou futura!')
@ -579,70 +560,9 @@ const handleChangeHourBefore = (event) => {
} }
{/* {schedulesContact.length>0 && {schedulesContact.length>0 &&
<div></div>
}
<Item>
<ConfirmationModal
title={selectedSchedule && `Deletar lembrete do dia ${selectedSchedule.schedulingTime.split(' ')[0]} ${selectedSchedule.schedulingTime.split(' ')[1]} ?`}
open={confirmModalOpen}
onClose={handleCloseConfirmationModal}
onConfirm={() => handleDeleteSchedule(selectedSchedule.id)}
>
<span>Deseja realmente deletar esse Lembrete? </span>
</ConfirmationModal>
<span>Lembretes</span>
<Paper variant="outlined">
<Table size="small">
<TableHead>
<TableRow>
<TableCell align="center">
Data
</TableCell>
<TableCell align="center">
Hora
</TableCell>
<TableCell align="center">
Mensagem
</TableCell>
<TableCell align="center">
Deletar
</TableCell>
</TableRow>
</TableHead>
<TableBody>
<>
{schedulesContact.map((scheduleData, index) => (
<TableRow key={scheduleData.id}>
<TableCell align="center">{scheduleData.schedulingDate.split(' ')[0]}</TableCell>
<TableCell align="center">{scheduleData.schedulingTime.split(' ')[1]}</TableCell>
<TableCell align="center">{scheduleData.message}</TableCell>
<TableCell align="center">
<IconButton
size="small"
onClick={() => {
setSelectedSchedule(scheduleData);
setConfirmModalOpen(true);
}}
>
<DeleteOutline />
</IconButton>
</TableCell>
</TableRow>
))}
</>
</TableBody>
</Table>
</Paper>
</Item>} */}
</Box> </Box>

View File

@ -30,9 +30,7 @@ function formatDate(strDate){
function ResponsiveDatePickers(props) { function ResponsiveDatePickers(props) {
console.log('schedulingDate schedulingDate schedulingDate2: ', (props.schedulingDate))
console.log('schedulingDate schedulingDate schedulingDate: ', formatDate(props.schedulingDate))
const [selectedDate, handleDateChange] = useState(new Date(formatDate(props.schedulingDate))); const [selectedDate, handleDateChange] = useState(new Date(formatDate(props.schedulingDate)));

View File

@ -14,30 +14,17 @@ import DatePicker from './DatePicker2'
import TimerPickerSelect from './TimerPickerSelect2' import TimerPickerSelect from './TimerPickerSelect2'
import TextareaAutosize from '@mui/material/TextareaAutosize'; import TextareaAutosize from '@mui/material/TextareaAutosize';
import { subHours, addDays, isEqual, subDays} from "date-fns"; import { subHours, addDays, subDays} from "date-fns";
import TextFieldSelectHourBefore from '@mui/material/TextField'; import TextFieldSelectHourBefore from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
import {
IconButton,
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
} from "@material-ui/core";
import { DeleteOutline } from "@material-ui/icons";
import { toast } from "react-toastify";
import api from "../../services/api"; import api from "../../services/api";
import toastError from "../../errors/toastError"; import toastError from "../../errors/toastError";
import ConfirmationModal from "../ConfirmationModal";
const reducer = (state, action) => { const reducer = (state, action) => {
@ -111,8 +98,8 @@ Item.propTypes = {
const Modal = (props) => { const Modal = (props) => {
const [selectedSchedule, setSelectedSchedule] = useState(null); // const [selectedSchedule, setSelectedSchedule] = useState(null);
const [confirmModalOpen, setConfirmModalOpen] = useState(false); // const [confirmModalOpen, setConfirmModalOpen] = useState(false);
const [open, setOpen] = useState(true); const [open, setOpen] = useState(true);
const [scroll, /*setScroll*/] = useState('body'); const [scroll, /*setScroll*/] = useState('body');
@ -124,11 +111,11 @@ const Modal = (props) => {
const [currencyHourBefore, setCurrency] = useState(props.rowData.schedulingTime.split(' ')[1].slice(0,5)); const [currencyHourBefore, setCurrency] = useState(props.rowData.schedulingTime.split(' ')[1].slice(0,5));
const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null); const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null);
const [contador, setCount] = useState(0)
const [currencyHourBeforeAux, ] = useState(props.rowData.schedulingTime.split(' ')[1].slice(0,5));
if(schedulesContact){}
const handleCancel = (event, reason) => { const handleCancel = (event, reason) => {
@ -170,26 +157,26 @@ const Modal = (props) => {
const handleCloseConfirmationModal = () => { // const handleCloseConfirmationModal = () => {
setConfirmModalOpen(false); // setConfirmModalOpen(false);
setSelectedSchedule(null); // setSelectedSchedule(null);
}; // };
const handleDeleteSchedule = async (scheduleId) => { // const handleDeleteSchedule = async (scheduleId) => {
try { // try {
await api.delete(`/schedule/${scheduleId}`); // await api.delete(`/schedule/${scheduleId}`);
toast.success(("Lembrete/Agendamento deletado com sucesso!")); // toast.success(("Lembrete/Agendamento deletado com sucesso!"));
dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); // dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId });
} catch (err) { // } catch (err) {
toastError(err); // toastError(err);
} // }
setSelectedSchedule(null); // setSelectedSchedule(null);
}; // };
// Get from child 2 // Get from child 2
const datePickerValue = (data) => { const datePickerValue = (data) => {
console.log('datePickerValue: ',(data));
setDatePicker(data) setDatePicker(data)
@ -197,7 +184,7 @@ const datePickerValue = (data) => {
// Get from child 3 // Get from child 3
const timerPickerValue = (data) => { const timerPickerValue = (data) => {
console.log('timerPickerValue: ',(data));
setTimerPicker(data) setTimerPicker(data)
@ -235,7 +222,7 @@ const dateCurrentFormated = (dateF=null) => {
if (statusChatEndId === '2'|| statusChatEndId === '3'){ if (statusChatEndId === '2'|| statusChatEndId === '3'){
console.log('Entrou! textArea1: ', textArea1)
if(textArea1 && textArea1.trim().length<5){ if(textArea1 && textArea1.trim().length<5){
@ -278,18 +265,17 @@ const dateCurrentFormated = (dateF=null) => {
if(sendMessageDayBefore.length > 0 && timeBefore === formatedTimeHour(timerPicker)) if(sendMessageDayBefore.length > 0 && timeBefore === formatedTimeHour(timerPicker))
{ {
console.log('ENVIAR MENSAGEM UM DIA ANTES!')
console.log('MENSAGEM SERÁ ENVIA NO DIA: ', dateCurrentFormated( new Date(subDays(new Date(startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`))), 1))))
dateSendMessage = dateCurrentFormated( new Date(subDays(new Date(startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`))), 1))) dateSendMessage = dateCurrentFormated( new Date(subDays(new Date(startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`))), 1)))
} }
console.log('AGENDAMENTO ENVIO MENSAGEM1: ', `${dateSendMessage} ${timeBefore}:00` )
} else if (statusChatEndId === '2'){ } else if (statusChatEndId === '2'){
console.log('AGENDAMENTO ENVIO MENSAGEM2: ', startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}`)) )
} }
@ -327,8 +313,19 @@ const dateCurrentFormated = (dateF=null) => {
useEffect(()=>{ useEffect(()=>{
const selectedTimeOld = (_hours) => {
setCount(contador+1) let selectedOld = _hours.filter((h)=>(h.value===currencyHourBeforeAux))[0]
if(selectedOld){
return selectedOld
}
return null
}
const hoursBeforeAvalible = (timer) =>{ const hoursBeforeAvalible = (timer) =>{
@ -338,25 +335,24 @@ const dateCurrentFormated = (dateF=null) => {
if(typeof(startDate)==='string' && startDate.trim().length>0 && startDate === dateCurrentFormated()){ if(typeof(startDate)==='string' && startDate.trim().length>0 && startDate === dateCurrentFormated()){
console.log('HOJE++++')
while(subHours(timer, hour).getHours()>=6 && while(subHours(timer, hour).getHours()>=6 &&
subHours(timer, hour).getHours()>=new Date().getHours() && subHours(timer, hour).getHours()>=new Date().getHours() &&
subHours(timer, hour).getHours()<=20){ subHours(timer, hour).getHours()<=20){
console.log('******** TIMER: ', formatedTimeHour(subHours(timer,hour)))
hours.push({value: formatedTimeHour(subHours(timer,hour)), label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`}) hours.push({value: formatedTimeHour(subHours(timer,hour)), label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`})
hour++; hour++;
} }
if(hours.length>1){ if(hours.length>1){
hours.pop() hours.pop()
if(contador>1) let selectedOld = selectedTimeOld(hours)
setCurrency( hours[0].value) setCurrency(selectedOld ? selectedOld.value : hours[0].value)
} }
else{ else{
setCurrency(null) setCurrency(null)
@ -365,9 +361,7 @@ const dateCurrentFormated = (dateF=null) => {
} }
else{ else{
while(subHours(timer, hour).getHours()>=6 && subHours(timer, hour).getHours()<=20){ while(subHours(timer, hour).getHours()>=6 && subHours(timer, hour).getHours()<=20){
console.log('******** another day TIMER: ', formatedTimeHour(subHours(timer,hour)))
hours.push( hours.push(
{value: formatedTimeHour(subHours(timer,hour)), {value: formatedTimeHour(subHours(timer,hour)),
@ -377,9 +371,13 @@ const dateCurrentFormated = (dateF=null) => {
} }
if(hours.length>0){ if(hours.length>0){
if(contador>1) let selectedOld = selectedTimeOld(hours)
setCurrency( hours[0].value) setCurrency(selectedOld ? selectedOld.value : hours[0].value)
//if(contador>1)
// setCurrency( hours[0].value)
} }
else{ else{
setCurrency(null) setCurrency(null)
@ -390,21 +388,21 @@ const dateCurrentFormated = (dateF=null) => {
if(new Date(startDate) > addDays(new Date(), 1) ){ if(new Date(startDate) > addDays(new Date(), 1) ){
hours.push({value: formatedTimeHour(timerPicker) , label: `24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO`}) hours.push({value: formatedTimeHour(timerPicker) , label: `24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO`})
console.log('#subDays: ', dateCurrentFormated( new Date(subDays(new Date(startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`))), 1)))) let selectedOld = selectedTimeOld(hours)
if(selectedOld)
setCurrency(selectedOld.value)
} }
return {time: hours, hour:hour} return {time: hours, hour:hour}
} }
console.log('CONTADOR 1: ', contador)
setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker).time) setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker).time)
},[timerPicker, startDate]) },[timerPicker, startDate, currencyHourBeforeAux])
@ -423,7 +421,7 @@ const dateCurrentFormated = (dateF=null) => {
// Get from child 1 // Get from child 1
const textFieldSelect = (data) => { const textFieldSelect = (data) => {
console.log('textFieldSelect: ',data);
setStatusChatEnd(data) setStatusChatEnd(data)
} }
@ -440,8 +438,7 @@ const handleChange = (event) => {
const handleChangeHourBefore = (event) => { const handleChangeHourBefore = (event) => {
setCurrency(event.target.value); setCurrency(event.target.value);
console.log('CONTADOR 2: ', contador)
}; };
@ -557,14 +554,14 @@ const handleChangeHourBefore = (event) => {
func={datePickerValue} func={datePickerValue}
minDate={true} minDate={true}
schedulingDate={props.rowData.schedulingDate} schedulingDate={props.rowData.schedulingDate}
title={'Data do lembrete'}/> title={'Data'}/>
</Item> </Item>
<Item> <Item>
<TimerPickerSelect <TimerPickerSelect
func={timerPickerValue} func={timerPickerValue}
schedulingDate={props.rowData.schedulingDate} schedulingDate={props.rowData.schedulingDate}
title={'Hora do lembrete'}/> title={'Hora'}/>
</Item> </Item>
</Box> </Box>

View File

@ -9,7 +9,7 @@ const SelectTextFields = (props) => {
// const [currency, setCurrency] = useState(props.emptyField ? '0' : '1'); // const [currency, setCurrency] = useState(props.emptyField ? '0' : '1');
console.log(':::::::::::::::::::::: props.textBoxFieldSelected: ', props.textBoxFieldSelected)
const [currency, setCurrency] = useState(props.textBoxFieldSelected ? props.textBoxFieldSelected: '0'); const [currency, setCurrency] = useState(props.textBoxFieldSelected ? props.textBoxFieldSelected: '0');

View File

@ -17,7 +17,7 @@ const reducerQ = (state, action) =>{
if(action.type === 'LOAD_QUERY'){ if(action.type === 'LOAD_QUERY'){
console.log('----------------action.payload: ', action.payload)
const queries = action.payload const queries = action.payload
const newQueries = [] const newQueries = []
@ -234,19 +234,19 @@ const Report = () => {
// Get from child 1 // Get from child 1
const datePicker1Value = (data) => { const datePicker1Value = (data) => {
console.log('DATE1: ',(data));
setDatePicker1(data) setDatePicker1(data)
} }
// Get from child 2 // Get from child 2
const datePicker2Value = (data) => { const datePicker2Value = (data) => {
console.log('DATE2: ',(data));
setDatePicker2(data) setDatePicker2(data)
} }
// Get from child 3 // Get from child 3
const textFieldSelectUser = (data) => { const textFieldSelectUser = (data) => {
console.log('textField: ',data);
setUser(data) setUser(data)
} }

View File

@ -1,16 +1,16 @@
import React, { useState, useEffect, useReducer, useContext} from "react"; import React, { useState, useEffect, useReducer} from "react";
import MainContainer from "../../components/MainContainer"; import MainContainer from "../../components/MainContainer";
import api from "../../services/api"; import api from "../../services/api";
import SelectField from "../../components/Report/SelectField";
//import { data } from '../../components/Report/MTable/data'; //import { data } from '../../components/Report/MTable/data';
import DatePicker1 from '../../components/Report/DatePicker' import DatePicker1 from '../../components/Report/DatePicker'
import DatePicker2 from '../../components/Report/DatePicker' import DatePicker2 from '../../components/Report/DatePicker'
//import { Button } from "@material-ui/core"; //import { Button } from "@material-ui/core";
import MTable from "../../components/Report/MTable";
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import { AuthContext } from "../../context/Auth/AuthContext";
import { Can } from "../../components/Can";
import SearchIcon from "@material-ui/icons/Search"; import SearchIcon from "@material-ui/icons/Search";
import TextField from "@material-ui/core/TextField"; import TextField from "@material-ui/core/TextField";
@ -20,29 +20,19 @@ import Button from "@material-ui/core/Button";
import MaterialTable from 'material-table'; import MaterialTable from 'material-table';
import Delete from '@material-ui/icons/Delete'; import Delete from '@material-ui/icons/Delete';
import Edit from '@material-ui/icons/Edit'; import Edit from '@material-ui/icons/Edit';
import Save from '@material-ui/icons/Save';
import Dialog from '@mui/material/Dialog';
import { render } from '@testing-library/react'; import { render } from '@testing-library/react';
// import Modal from "../../../..ChatEnd/ModalChatEnd"; // import Modal from "../../../..ChatEnd/ModalChatEnd";
import Modal from "../../components/ModalUpdateScheduleReminder"; import Modal from "../../components/ModalUpdateScheduleReminder";
import openSocket from "socket.io-client"; import openSocket from "socket.io-client";
import {
IconButton,
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
} from "@material-ui/core";
import { DeleteOutline } from "@material-ui/icons";
import { toast } from "react-toastify"; import { toast } from "react-toastify";
import toastError from "../../errors/toastError"; import toastError from "../../errors/toastError";
import ConfirmationModal from "../../components/ConfirmationModal"; import ConfirmationModal from "../../components/ConfirmationModal";
@ -53,7 +43,7 @@ const reducerQ = (state, action) =>{
if(action.type === 'LOAD_QUERY'){ if(action.type === 'LOAD_QUERY'){
console.log('----------------action.payload: ', action.payload)
const queries = action.payload const queries = action.payload
const newQueries = [] const newQueries = []
@ -80,7 +70,7 @@ const reducerQ = (state, action) =>{
// const scheduling = action.payload; // const scheduling = action.payload;
// const schedulingIndex = state.findIndex((u) => u.id === +scheduling.id); // const schedulingIndex = state.findIndex((u) => u.id === +scheduling.id);
// console.log('**************** UPDATE_SCHEDULING scheduleIndex: ', schedulingIndex) //
// if (schedulingIndex !== -1) { // if (schedulingIndex !== -1) {
// state[schedulingIndex] = scheduling; // state[schedulingIndex] = scheduling;
@ -95,7 +85,7 @@ const reducerQ = (state, action) =>{
const scheduleId = action.payload; const scheduleId = action.payload;
const scheduleIndex = state.findIndex((u) => u.id === scheduleId); const scheduleIndex = state.findIndex((u) => u.id === scheduleId);
console.log('**************** scheduleIndex: ', scheduleIndex)
if (scheduleIndex !== -1) { if (scheduleIndex !== -1) {
state.splice(scheduleIndex, 1); state.splice(scheduleIndex, 1);
} }
@ -199,7 +189,7 @@ Item.propTypes = {
const SchedulesReminder = () => { const SchedulesReminder = () => {
const { user: userA } = useContext(AuthContext);
//-------- //--------
const [searchParam] = useState(""); const [searchParam] = useState("");
@ -210,7 +200,7 @@ const SchedulesReminder = () => {
//const [columns, setColums] = useState([]) //const [columns, setColums] = useState([])
const [startDate, setDatePicker1] = useState(new Date()) const [startDate, setDatePicker1] = useState(new Date())
const [endDate, setDatePicker2] = useState(new Date()) const [endDate, setDatePicker2] = useState(new Date())
const [userId, setUser] = useState(null)
const [query, dispatchQ] = useReducer(reducerQ, []) const [query, dispatchQ] = useReducer(reducerQ, [])
const [contactNumber, setContactNumber] = useState(""); const [contactNumber, setContactNumber] = useState("");
@ -231,19 +221,19 @@ const SchedulesReminder = () => {
socket.on("schedulingNotify", (data) => { socket.on("schedulingNotify", (data) => {
console.log('SOCKET IO')
setLoading(true); setLoading(true);
// if (data.action === "update" || data.action === "create") { // if (data.action === "update" || data.action === "create") {
// console.log('UPDATE_SCHEDULING: ', data.schedulingNotifyCreate) //
// // dispatchQ({ type: "UPDATE_SCHEDULING", payload: data.schedulingNotifyCreate }); // // dispatchQ({ type: "UPDATE_SCHEDULING", payload: data.schedulingNotifyCreate });
// } // }
if (data.action === "delete") { if (data.action === "delete") {
console.log('DELETE_SCHEDULING id: ', data.schedulingNotifyId)
dispatchQ({ type: "DELETE_SCHEDULING", payload: +data.schedulingNotifyId }); dispatchQ({ type: "DELETE_SCHEDULING", payload: +data.schedulingNotifyId });
//handleDeleteRows(data.schedulingNotifyId) //handleDeleteRows(data.schedulingNotifyId)
} }
@ -281,10 +271,14 @@ const SchedulesReminder = () => {
// dispatch({ type: "LOAD_STATUS_CHAT_END", payload: statusChatEndLoad.data }); // dispatch({ type: "LOAD_STATUS_CHAT_END", payload: statusChatEndLoad.data });
console.log(':::::::::::::: statusChatEndLoad: ', statusChatEndLoad.data)
setStatusEndChat(statusChatEndLoad.data.filter(status => (status.id == '2' || status.id == '3'))) // setStatusEndChat(statusChatEndLoad.data.filter(status => (status.id == '2' || status.id == '3')))
setStatusEndChat(statusChatEndLoad.data.filter(status => (`${status.id}` === '2' || `${status.id}` === '3')))
//setHasMore(data.hasMore); //setHasMore(data.hasMore);
// setLoading(false); // setLoading(false);
} catch (err) { } catch (err) {
@ -331,41 +325,30 @@ const SchedulesReminder = () => {
useEffect(() => { useEffect(() => {
if(!loading){ if(!loading){
console.log('carregando table...')
// const dataLoad = query.map(({ scheduleReminder, ...others }) => (
// { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' }
// ));
// console.log('NEW DATA: ', dataLoad)
setData(query.map(({ scheduleReminder, ...others }) => ( setData(query.map(({ scheduleReminder, ...others }) => (
{ ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } { ...others, 'scheduleReminder': `${others.statusChatEndId}` === '3' ? 'Agendamento' : 'Lembrete' }
))) )))
} }
}, [loading]) }, [loading, query])
// Get from child 1 // Get from child 1
const datePicker1Value = (data) => { const datePicker1Value = (data) => {
console.log('DATE1: ',(data));
setDatePicker1(data) setDatePicker1(data)
} }
// Get from child 2 // Get from child 2
const datePicker2Value = (data) => { const datePicker2Value = (data) => {
console.log('DATE2: ',(data));
setDatePicker2(data) setDatePicker2(data)
} }
// Get from child 3
const textFieldSelectUser = (data) => {
console.log('textField: ',data);
setUser(data)
}
const handleSearch = (event) => { const handleSearch = (event) => {
setContactNumber(event.target.value.toLowerCase()); setContactNumber(event.target.value.toLowerCase());
@ -381,21 +364,21 @@ const handleClear = () => {
const handleCloseConfirmationModal = () => { const handleCloseConfirmationModal = () => {
setConfirmModalOpen(false); setConfirmModalOpen(false);
console.log('cancelou NULL 1')
setSelectedSchedule(null); setSelectedSchedule(null);
}; };
const handleDeleteRows = (id) => { // const handleDeleteRows = (id) => {
let _data = [...dataRows]; // let _data = [...dataRows];
_data.forEach(rd => { // _data.forEach(rd => {
_data = _data.filter(t => t.id !== id); // _data = _data.filter(t => t.id !== id);
}); // });
setData(_data); // setData(_data);
}; // };
const handleDeleteSchedule = async (scheduleId) => { const handleDeleteSchedule = async (scheduleId) => {
@ -406,7 +389,7 @@ const handleDeleteSchedule = async (scheduleId) => {
} catch (err) { } catch (err) {
toastError(err); toastError(err);
} }
console.log('cancelou NULL 2')
setSelectedSchedule(null); setSelectedSchedule(null);
}; };
@ -424,7 +407,7 @@ const handleUpdateSchedule = async (scheduleData, rowsDataNew) => {
dataUpdate[index] = rowsDataNew; dataUpdate[index] = rowsDataNew;
setData([...dataUpdate].map(({ scheduleReminder, ...others }) => ( setData([...dataUpdate].map(({ scheduleReminder, ...others }) => (
{ ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } { ...others, 'scheduleReminder': `${others.statusChatEndId}` === '3' ? 'Agendamento' : 'Lembrete' }
))); )));
@ -436,7 +419,7 @@ const handleUpdateSchedule = async (scheduleData, rowsDataNew) => {
} catch (err) { } catch (err) {
toastError(err); toastError(err);
} }
//console.log('cancelou NULL 3') //
setSelectedSchedule(null); setSelectedSchedule(null);
}; };
@ -445,10 +428,10 @@ const chatEndVal = (data, rowsDataNew) => {
if(data){ if(data){
console.log('DATA SCHECULE: ', data)
console.log(':::::::::::::::::::: ChatEnd2: ',(data));
console.log(':::::::::::::::::::: Rows data fro child: ',(rowsDataNew));
handleUpdateSchedule(data, rowsDataNew) handleUpdateSchedule(data, rowsDataNew)
@ -493,12 +476,7 @@ const handleModal = (rowData) => {
/> />
</Item> </Item>
{/* <Item>
<SelectField func={textFieldSelectUser} emptyField={true} header={'Usuário'} currencies={users.map((obj)=>{
return {'value': obj.id, 'label': obj.name}
})}/>
</Item> */}
<Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={true} reset={resetChild} setReset={setReset} title={'Data inicio'}/></Item> <Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={true} reset={resetChild} setReset={setReset} title={'Data inicio'}/></Item>
<Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={true} reset={resetChild} setReset={setReset} title={'Data fim'}/></Item> <Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={true} reset={resetChild} setReset={setReset} title={'Data fim'}/></Item>
@ -527,7 +505,7 @@ const handleModal = (rowData) => {
<ConfirmationModal <ConfirmationModal
title={selectedSchedule && `Deletar ${selectedSchedule.statusChatEndId=='2' ? 'lembrete' : 'agendamento'} do dia ${selectedSchedule.schedulingDate.split(' ')[0]} ${selectedSchedule.schedulingDate.split(' ')[1]} ?`} title={selectedSchedule && `Deletar ${''+selectedSchedule.statusChatEndId === '2' ? 'lembrete' : 'agendamento'} do dia ${selectedSchedule.schedulingDate.split(' ')[0]} ${selectedSchedule.schedulingDate.split(' ')[1]} ?`}
open={confirmModalOpen} open={confirmModalOpen}
onClose={handleCloseConfirmationModal} onClose={handleCloseConfirmationModal}
onConfirm={() => handleDeleteSchedule(selectedSchedule.id)} onConfirm={() => handleDeleteSchedule(selectedSchedule.id)}
@ -540,7 +518,7 @@ const handleModal = (rowData) => {
columns={ columns={
[ [
{ title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => <img src={rowData['ticket.contact.profilePicUrl']} style={{width: 40, borderRadius: '50%'}}/> }, { title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => <img src={rowData['ticket.contact.profilePicUrl']} alt="imagem de perfil do whatsapp" style={{width: 40, borderRadius: '50%'}}/> },
{ title: 'Nome', field: 'ticket.contact.name' }, { title: 'Nome', field: 'ticket.contact.name' },
{ title: 'Contato', field: 'ticket.contact.number' }, { title: 'Contato', field: 'ticket.contact.number' },
{ title: 'Lemb/Agen', field: 'scheduleReminder'}, { title: 'Lemb/Agen', field: 'scheduleReminder'},
@ -558,7 +536,7 @@ const handleModal = (rowData) => {
icon: Edit, icon: Edit,
tooltip: 'Editar', tooltip: 'Editar',
onClick: (event, rowData) => { onClick: (event, rowData) => {
console.log("You want edit data ",rowData)
setSelectedSchedule(rowData); setSelectedSchedule(rowData);
handleModal(rowData) handleModal(rowData)
} }
@ -568,7 +546,7 @@ const handleModal = (rowData) => {
icon: Delete, icon: Delete,
tooltip: 'Deletar', tooltip: 'Deletar',
onClick: (event, rowData) => { onClick: (event, rowData) => {
console.log("You want to delete ",rowData)
setSelectedSchedule(rowData); setSelectedSchedule(rowData);
setConfirmModalOpen(true); setConfirmModalOpen(true);
} }
@ -588,13 +566,6 @@ const handleModal = (rowData) => {
width: 300, width: 300,
}, },
pageSize: 20,
headerStyle: {
position: "sticky",
top: "0"
},
maxBodyHeight: "400px",
rowStyle: { rowStyle: {
fontSize: 12, fontSize: 12,
} }