diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index 2cebf04..4b7d4b5 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -11,7 +11,8 @@ import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService"; import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService"; - + +import {isScheduling} from "../helpers/CheckSchedulingReminderNotify" @@ -135,10 +136,23 @@ export const update = async ( req: Request, res: Response ): Promise = } /////////////////////////////// + + // lembrete const scheduleData = JSON.parse(schedulingNotifyData) + // lembrete // agendamento + if( scheduleData.statusChatEndId === '2' || scheduleData.statusChatEndId === '3'){ + + console.log('*** schedulingDate: ', scheduleData.schedulingDate) + console.log('*** schedulingTime: ', scheduleData.schedulingTime) + + if(isScheduling(scheduleData.schedulingDate, scheduleData.schedulingTime)){ + console.log('*** É AGENDAMENTO!') + } + else{ + console.log('*** É LEMBRETE!') + } - if( scheduleData.statusChatEndId === '2'){ const schedulingNotifyCreate = await CreateSchedulingNotifyService( { ticketId: scheduleData.ticketId, diff --git a/backend/src/helpers/CheckSchedulingReminderNotify.ts b/backend/src/helpers/CheckSchedulingReminderNotify.ts new file mode 100644 index 0000000..4cd08a0 --- /dev/null +++ b/backend/src/helpers/CheckSchedulingReminderNotify.ts @@ -0,0 +1,11 @@ + + +export const isScheduling = (schedulingDate:string, schedulingTime:string) => { + + if (schedulingDate === schedulingTime){ + return false + } + + return true + +} \ No newline at end of file diff --git a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts index a06365e..8f6e4cc 100644 --- a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts +++ b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts @@ -3,7 +3,7 @@ import SchedulingNotify from "../../models/SchedulingNotify"; interface Request { - schedulingNotifyId?: string, + schedulingNotifyId?: string, ticketId: string, statusChatEndId: string, schedulingDate: string, diff --git a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts index 4ef8275..ba862ea 100644 --- a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts +++ b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts @@ -45,7 +45,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st where_clause = {} where_clause_notify = { - schedulingTime: { + schedulingDate: { [Op.gte]: startDate+' 00:00:00.000000', [Op.lte]: endDate +' 23:59:59.999999' }, @@ -57,7 +57,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st where_clause = {} where_clause_notify = { - schedulingTime: { + schedulingDate: { [Op.gte]: startDate+' 00:00:00.000000', [Op.lte]: startDate +' 23:59:59.999999' }, @@ -69,7 +69,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st where_clause = {} where_clause_notify = { - schedulingTime: { + schedulingDate: { [Op.gte]: endDate+' 00:00:00.000000', [Op.lte]: endDate +' 23:59:59.999999' }, @@ -81,7 +81,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st where_clause = nameNumber where_clause_notify = { - schedulingTime: { + schedulingDate: { [Op.gte]: startDate+' 00:00:00.000000', [Op.lte]: startDate +' 23:59:59.999999' }, @@ -93,7 +93,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st where_clause = nameNumber where_clause_notify = { - schedulingTime: { + schedulingDate: { [Op.gte]: endDate+' 00:00:00.000000', [Op.lte]: endDate +' 23:59:59.999999' }, @@ -112,7 +112,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st raw: true, where: where_clause_notify, - attributes:['id', 'ticketId', [Sequelize.fn("DATE_FORMAT",Sequelize.col("schedulingDate"),"%d/%m/%Y %H:%i:%s"),"schedulingDate"], + attributes:['id', 'ticketId','statusChatEndId', [Sequelize.fn("DATE_FORMAT",Sequelize.col("schedulingDate"),"%d/%m/%Y %H:%i:%s"),"schedulingDate"], [Sequelize.fn("DATE_FORMAT",Sequelize.col("schedulingTime"),"%d/%m/%Y %H:%i:%s"),"schedulingTime"], 'message'], include: [ diff --git a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyService.ts b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyService.ts index e1867e3..1c42641 100644 --- a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyService.ts +++ b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyService.ts @@ -32,13 +32,13 @@ interface Request { const whereCondition = { [Op.and]: [ { - "$schedulingDate$": Sequelize.where(Sequelize.fn("date", Sequelize.col("schedulingDate")), `${date.trim()}`) + "$schedulingTime$": Sequelize.where(Sequelize.fn("date", Sequelize.col("schedulingTime")), `${date.trim()}`) }, { - "$schedulingDate$": Sequelize.where(Sequelize.fn("hour", Sequelize.col("schedulingDate")), `${hour.trim()}`) + "$schedulingTime$": Sequelize.where(Sequelize.fn("hour", Sequelize.col("schedulingTime")), `${hour.trim()}`) }, { - "$schedulingDate$": Sequelize.where(Sequelize.fn("minute", Sequelize.col("schedulingDate")), `${minute.trim()}`) + "$schedulingTime$": Sequelize.where(Sequelize.fn("minute", Sequelize.col("schedulingTime")), `${minute.trim()}`) } ] }; diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index 1f76e06..e28ca51 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -8,12 +8,14 @@ import DialogContentText from '@mui/material/DialogContentText'; import DialogTitle from '@mui/material/DialogTitle'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; -import SelectField from "../../Report/SelectField"; - +import SelectField from "../../Report/SelectField"; import DatePicker from '../../Report/DatePicker' import TimerPickerSelect from '../TimerPickerSelect' import TextareaAutosize from '@mui/material/TextareaAutosize'; -// import { subHours } from "date-fns"; + +import { subHours, addDays, isEqual, subDays} from "date-fns"; +import TextFieldSelectHourBefore from '@mui/material/TextField'; +import MenuItem from '@mui/material/MenuItem'; @@ -108,17 +110,17 @@ const Modal = (props) => { // const [clientSchedules, dispatch] = useReducer(reducer, []); const [selectedSchedule, setSelectedSchedule] = useState(null); - const [confirmModalOpen, setConfirmModalOpen] = useState(false); - + const [confirmModalOpen, setConfirmModalOpen] = useState(false); const [open, setOpen] = useState(true); const [scroll, /*setScroll*/] = useState('body'); const [statusChatEndId, setStatusChatEnd] = useState(null) const [startDate, setDatePicker] = useState(new Date()) const [timerPicker, setTimerPicker] = useState(new Date()) - const [textArea1, setTextArea1] = useState() - - + const [textArea1, setTextArea1] = useState() const [schedulesContact, dispatch] = useReducer(reducer, []); + + const [currencyHourBefore, setCurrency] = useState(null); + const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null); const handleCancel = (event, reason) => { @@ -128,7 +130,6 @@ const Modal = (props) => { setOpen(false); }; - useEffect(() => { @@ -170,7 +171,7 @@ const Modal = (props) => { const handleDeleteSchedule = async (scheduleId) => { try { await api.delete(`/schedule/${scheduleId}`); - toast.success(("Lembrete deletado com sucesso!")); + toast.success(("Lembrete/Agendamento deletado com sucesso!")); dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); } catch (err) { toastError(err); @@ -194,7 +195,24 @@ const timerPickerValue = (data) => { } - + const dateCurrentFormated = (dateF=null) => { + + let date =null + + if(dateF){ + date = new Date(dateF) + } + else{ + date = new Date(); + } + + let day = date.getDate().toString().padStart(2, '0'); + let month = (date.getMonth()+1).toString().padStart(2, '0'); + let year = date.getFullYear(); + + return `${year}-${month}-${day}` + +} const handleChatEnd = (event, reason) => { @@ -203,44 +221,82 @@ const timerPickerValue = (data) => { if (reason && reason === "backdropClick") return; - if (statusChatEndId === '2'){ + if (statusChatEndId === '2' || statusChatEndId === '3'){ console.log('Entrou! textArea1: ', textArea1) + if( startDate.trim().length==0){ - if(textArea1 && textArea1.trim().length<5){ - alert('Mensagem muito curta!') + alert('Selecione uma data atual ou futura!') + + return + } + + else if(textArea1 && textArea1.trim().length<5){ + alert('Mensagem muito curta!') return } else if(!textArea1){ alert('Defina uma mensagem para enviar para o cliente!') return } - else if(formatedFullCurrentDate()===startDate){ - - if((new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || + else if(formatedFullCurrentDate()===startDate && + ((new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || (new Date(timerPicker).getHours() === new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || (new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() >= new Date().getMinutes()) || - (new Date(timerPicker).getHours() < new Date().getHours)){ + (new Date(timerPicker).getHours() < new Date().getHours))){ alert('Horário menor ou igual horário atual!') - return - } - + return } else if((new Date(timerPicker).getHours() > 20 && new Date(timerPicker).getMinutes() > 0) || (new Date(timerPicker).getHours() < 6)){ alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 06:00 e 20:00') return } + + + + let dateSendMessage = startDate + let timeBefore = formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)) + + if(statusChatEndId === '3'){ + + if(!currencyHourBefore){ + alert('Para agendamentos do dia corrente, essa funcionalidade atende a agendeamentos com no mínimo 2 horas adiantado a partir da hora atual!') + return + } + + timeBefore = currencyHourBefore + + let sendMessageDayBefore = currenciesTimeBefore.filter(i => i.label.indexOf('24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO') >= 0); + + 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))) + } + + + console.log('AGENDAMENTO ENVIO MENSAGEM1: ', `${dateSendMessage} ${timeBefore}:00` ) + + } else if (statusChatEndId === '2'){ + + console.log('AGENDAMENTO ENVIO MENSAGEM2: ', startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)) ) + + } dataSendServer = { 'statusChatEndId': statusChatEndId, - 'schedulingDate': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), - 'schedulingTime': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), + 'schedulingDate': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}`))+':00', + 'schedulingTime': `${dateSendMessage} ${timeBefore}:00`, 'message': textArea1 } + - } + } + props.func(dataSendServer) @@ -248,6 +304,98 @@ const timerPickerValue = (data) => { }; + + + + useEffect(()=>{ + + const hoursBeforeAvalible = (timer) =>{ + + let hours = [] + let hour = 1 + + console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>> startDate: ', startDate ) + console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>> dateCurrentFormated: ', dateCurrentFormated() ) + console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>> startDate: ',typeof(startDate) ) + console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>> startDate: ',(startDate) ) + + if(typeof(startDate)==='string' && startDate.trim().length>0 && startDate === dateCurrentFormated()){ + + console.log('HOJE++++') + + while(subHours(timer, hour).getHours()>=6 && + + subHours(timer, hour).getHours()>=new Date().getHours() && + 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`}) + + hour++; + } + + if(hours.length>1){ + console.log('entrou----------------------: ', hours.length) + hours.pop() + setCurrency(hours[0].value) + } + else{ + setCurrency(null) + } + + } + else{ + + while(subHours(timer, hour).getHours()>=6 && subHours(timer, hour).getHours()<=20){ + + console.log('******** another day TIMER: ', formatedTimeHour(subHours(timer,hour))) + + hours.push( + {value: formatedTimeHour(subHours(timer,hour)), + label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`}) + + hour++; + } + + if(hours.length>0){ + console.log('entrou----------------------: ', hours.length) + setCurrency(hours[0].value) + } + else{ + setCurrency(null) + } + + } + + + if(new Date(startDate) > addDays(new Date(), 1) ){ + + 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)))) + + } + + console.log('hourshourshourshourshourshourshourshourshourshourshourshours ', hours) + + + return {time: hours, hour:hour} + + } + + console.log('===================================== addDays: ', addDays(new Date(), 1)) + + + + setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker).time) + + },[timerPicker, startDate]) + + + + + const descriptionElementRef = useRef(null); useEffect(() => { if (open) { @@ -263,16 +411,28 @@ const timerPickerValue = (data) => { const textFieldSelect = (data) => { console.log('textFieldSelect: ',data); setStatusChatEnd(data) + } - - const handleChange = (event) => { setTextArea1(event.target.value); }; + + +const handleChangeHourBefore = (event) => { + + console.log('textFihandleChangeHourBefore: ',event.target.value); + + // var matchedTime = currenciesTimeBefore.filter(i => i.label.indexOf('24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO') >= 0); + + // console.log('textFihandleChangeHourBefore matchedTime: ',matchedTime); + + setCurrency(event.target.value); + +}; @@ -359,7 +519,65 @@ const handleChange = (event) => { - } + } + + {statusChatEndId==='3' && + + + + + Agendamento + + + + + + + + + + + + + + + {currencyHourBefore && startDate && typeof(startDate)==='string' && startDate.trim().length > 0 && currenciesTimeBefore.length > 0 && + 0 ? false : true} + select + label="Enviar mensagem para cliente" + value={currencyHourBefore} + size="small" + onChange={handleChangeHourBefore} + > + {currenciesTimeBefore.map((option) => ( + + {option.label} + + ))} + + } + + + + + + + + + + + + + } {/* {schedulesContact.length>0 && diff --git a/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js index 9de3619..54f3538 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js @@ -31,6 +31,7 @@ function formatDate(strDate){ 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))); diff --git a/frontend/src/components/ModalUpdateScheduleReminder/index.js b/frontend/src/components/ModalUpdateScheduleReminder/index.js index 865689e..b1b8142 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/index.js @@ -13,7 +13,12 @@ import SelectField from "../Report/SelectField"; import DatePicker from './DatePicker2' import TimerPickerSelect from './TimerPickerSelect2' import TextareaAutosize from '@mui/material/TextareaAutosize'; -// import { subHours } from "date-fns"; + +import { subHours, addDays, isEqual, subDays} from "date-fns"; +import TextFieldSelectHourBefore from '@mui/material/TextField'; +import MenuItem from '@mui/material/MenuItem'; + + @@ -111,14 +116,19 @@ const Modal = (props) => { const [open, setOpen] = useState(true); const [scroll, /*setScroll*/] = useState('body'); - const [statusChatEndId, setStatusChatEnd] = useState(null) + const [statusChatEndId, setStatusChatEnd] = useState(props.rowData.statusChatEndId) const [startDate, setDatePicker] = useState(props.rowData.schedulingTime ? new Date(props.rowData.schedulingTime) : new Date()) const [timerPicker, setTimerPicker] = useState(new Date()) const [textArea1, setTextArea1] = useState(props.rowData.message) - - const [schedulesContact, dispatch] = useReducer(reducer, []); + const [currencyHourBefore, setCurrency] = useState(props.rowData.schedulingTime.split(' ')[1].slice(0,5)); + const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null); + const [contador, setCount] = useState(0) + + + + const handleCancel = (event, reason) => { @@ -169,7 +179,7 @@ const Modal = (props) => { const handleDeleteSchedule = async (scheduleId) => { try { await api.delete(`/schedule/${scheduleId}`); - toast.success(("Lembrete deletado com sucesso!")); + toast.success(("Lembrete/Agendamento deletado com sucesso!")); dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); } catch (err) { toastError(err); @@ -193,6 +203,27 @@ const timerPickerValue = (data) => { } + + +const dateCurrentFormated = (dateF=null) => { + + let date =null + + if(dateF){ + date = new Date(dateF) + } + else{ + date = new Date(); + } + + let day = date.getDate().toString().padStart(2, '0'); + let month = (date.getMonth()+1).toString().padStart(2, '0'); + let year = date.getFullYear(); + + return `${year}-${month}-${day}` + +} + const handleChatEnd = (event, reason) => { @@ -202,7 +233,7 @@ const timerPickerValue = (data) => { if (reason && reason === "backdropClick") return; - if (statusChatEndId === '2'){ + if (statusChatEndId === '2'|| statusChatEndId === '3'){ console.log('Entrou! textArea1: ', textArea1) @@ -215,30 +246,61 @@ const timerPickerValue = (data) => { alert('Defina uma mensagem para enviar para o cliente!') return } - else if(formatedFullCurrentDate()===startDate){ - - if((new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || - (new Date(timerPicker).getHours() === new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || - (new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() >= new Date().getMinutes()) || - (new Date(timerPicker).getHours() < new Date().getHours)){ - alert('Horário menor ou igual horário atual!') - return - } + else if(formatedFullCurrentDate()===startDate && + ((new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || + (new Date(timerPicker).getHours() === new Date().getHours() && new Date(timerPicker).getMinutes() <= new Date().getMinutes()) || + (new Date(timerPicker).getHours() < new Date().getHours() && new Date(timerPicker).getMinutes() >= new Date().getMinutes()) || + (new Date(timerPicker).getHours() < new Date().getHours))){ + alert('Horário menor ou igual horário atual!') + return + } + else if((new Date(timerPicker).getHours() > 20 && new Date(timerPicker).getMinutes() > 0) || + (new Date(timerPicker).getHours() < 6)){ + alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 06:00 e 20:00') + return + } + + + let dateSendMessage = startDate + let timeBefore = formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)) + + if(statusChatEndId === '3'){ + + if(!currencyHourBefore){ + alert('Para agendamentos do dia corrente, essa funcionalidade atende a agendeamentos com no mínimo 2 horas adiantado a partir da hora atual!') + return + } + + timeBefore = currencyHourBefore + + let sendMessageDayBefore = currenciesTimeBefore.filter(i => i.label.indexOf('24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO') >= 0); + + 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))) + } + + + console.log('AGENDAMENTO ENVIO MENSAGEM1: ', `${dateSendMessage} ${timeBefore}:00` ) + + } else if (statusChatEndId === '2'){ + + console.log('AGENDAMENTO ENVIO MENSAGEM2: ', startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}`)) ) + } - else if((new Date(timerPicker).getHours() > 20 && new Date(timerPicker).getMinutes() > 0) || - (new Date(timerPicker).getHours() < 6)){ - alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 06:00 e 20:00') - return - } dataSendServer = { - 'schedulingNotifyId': props.rowData.id, - 'statusChatEndId': statusChatEndId, - 'schedulingDate': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), - 'schedulingTime': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), + 'schedulingNotifyId': props.rowData.id, + 'statusChatEndId': statusChatEndId, + 'schedulingDate': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}`))+':00', + 'schedulingTime': `${dateSendMessage} ${timeBefore}:00`, 'message': textArea1 } + const formatDateTimeBrazil = (dateTime) => { @@ -248,11 +310,11 @@ const timerPickerValue = (data) => { return `${date[2]}/${date[1]}/${date[0]} ${time}` } - - props.rowData['schedulingDate'] = formatDateTimeBrazil(`${dataSendServer['schedulingDate']}:00`) - props.rowData['schedulingTime'] = formatDateTimeBrazil(`${dataSendServer['schedulingTime']}:00`) - props.rowData['message'] = textArea1 + props.rowData['statusChatEndId'] = statusChatEndId + props.rowData['schedulingDate'] = formatDateTimeBrazil(`${dataSendServer['schedulingDate']}`) + props.rowData['schedulingTime'] = formatDateTimeBrazil(`${dataSendServer['schedulingTime']}`) + props.rowData['message'] = textArea1 } @@ -260,7 +322,93 @@ const timerPickerValue = (data) => { setOpen(false); }; + + + + + useEffect(()=>{ + + setCount(contador+1) + + const hoursBeforeAvalible = (timer) =>{ + + let hours = [] + let hour = 1 + + + if(typeof(startDate)==='string' && startDate.trim().length>0 && startDate === dateCurrentFormated()){ + + console.log('HOJE++++') + + while(subHours(timer, hour).getHours()>=6 && + + subHours(timer, hour).getHours()>=new Date().getHours() && + 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`}) + + hour++; + } + + if(hours.length>1){ + hours.pop() + + if(contador>1) + setCurrency( hours[0].value) + } + else{ + setCurrency(null) + } + + } + else{ + + while(subHours(timer, hour).getHours()>=6 && subHours(timer, hour).getHours()<=20){ + + console.log('******** another day TIMER: ', formatedTimeHour(subHours(timer,hour))) + + hours.push( + {value: formatedTimeHour(subHours(timer,hour)), + label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`}) + + hour++; + } + + if(hours.length>0){ + + if(contador>1) + setCurrency( hours[0].value) + } + else{ + setCurrency(null) + } + + } + + + if(new Date(startDate) > addDays(new Date(), 1) ){ + + 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)))) + + } + + return {time: hours, hour:hour} + + } + + console.log('CONTADOR 1: ', contador) + + setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker).time) + + },[timerPicker, startDate]) + + + + const descriptionElementRef = useRef(null); useEffect(() => { @@ -287,6 +435,15 @@ const handleChange = (event) => { setTextArea1(event.target.value); }; + + +const handleChangeHourBefore = (event) => { + + setCurrency(event.target.value); + + console.log('CONTADOR 2: ', contador) + +}; @@ -332,7 +489,7 @@ const handleChange = (event) => { { return {'value': obj.id, 'label': obj.name} @@ -351,7 +508,8 @@ const handleChange = (event) => { - + { } + + {statusChatEndId==='3' && + + + + + Agendamento + + + + + + + + + + + + + + + + + + + {currencyHourBefore && startDate && typeof(startDate)==='string' && startDate.trim().length > 0 && currenciesTimeBefore.length > 0 && + 0 ? false : true} + select + label="Enviar mensagem para cliente" + value={currencyHourBefore} + size="small" + onChange={handleChangeHourBefore} + > + {currenciesTimeBefore.map((option) => ( + + {option.label} + + ))} + + } + + + + + + + + + + + + + } + diff --git a/frontend/src/pages/SchedulesReminder/index.js b/frontend/src/pages/SchedulesReminder/index.js index 547193b..b64218d 100644 --- a/frontend/src/pages/SchedulesReminder/index.js +++ b/frontend/src/pages/SchedulesReminder/index.js @@ -263,7 +263,18 @@ const SchedulesReminder = () => { if(!loading){ console.log('carregando table...') - setData(query) + + const dataLoad = query.map(({ scheduleReminder, ...others }) => ( + + { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } + + )); + + console.log('NEW DATA: ', dataLoad) + + setData(query.map(({ scheduleReminder, ...others }) => ( + { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } + ))) } }, [loading]) @@ -321,7 +332,7 @@ const handleDeleteRows = (id) => { const handleDeleteSchedule = async (scheduleId) => { try { await api.delete(`/schedule/${scheduleId}`); - toast.success(("Lembrete deletado com sucesso!")); + toast.success(("Lembrete/Agendamento deletado com sucesso!")); handleDeleteRows(scheduleId) } catch (err) { toastError(err); @@ -333,15 +344,22 @@ const handleDeleteSchedule = async (scheduleId) => { const handleUpdateSchedule = async (scheduleData, rowsDataNew) => { - try { + try { + await api.post("/schedule", scheduleData); - toast.success(("Lembrete atualizado com sucesso!")); + toast.success(("Lembrete/Agendamento atualizado com sucesso!")); ////////////////// const dataUpdate = [...dataRows]; const index = rowsDataNew.tableData['id']; dataUpdate[index] = rowsDataNew; - setData([...dataUpdate]); + + setData([...dataUpdate].map(({ scheduleReminder, ...others }) => ( + { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } + ))); + + + ///////////////// @@ -372,11 +390,13 @@ const chatEndVal = (data, rowsDataNew) => { const handleModal = (rowData) => { + // NATY + render() @@ -438,12 +458,12 @@ const handleModal = (rowData) => { handleDeleteSchedule(selectedSchedule.id)} > - Deseja realmente deletar esse Lembrete? + Deseja realmente deletar esse lembrete/agendamento ? { [ { title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => }, - { title: 'Nome', field: 'ticket.contact.name' }, - { title: 'Contato', field: 'ticket.contact.number' }, - { title: 'schedulingTime', field: 'schedulingTime' }, - { title: 'schedulingDate', field: 'schedulingDate' }, - { title: 'message', field: 'message' }, + { title: 'Contato', field: 'ticket.contact.number' }, + { title: 'Lemb/Agen', field: 'scheduleReminder'}, + { title: 'Envio', field: 'schedulingTime' }, + { title: 'Data', field: 'schedulingDate' }, + { title: 'Mensagem', field: 'message', width: "80%" }, ] } @@ -487,7 +507,8 @@ const handleModal = (rowData) => { } ]} - options={{ + options={ + { search: true, selection: false, paging: false, @@ -497,6 +518,10 @@ const handleModal = (rowData) => { searchFieldStyle: { width: 300, }, + + rowStyle: { + fontSize: 12, + } }} />