Implementação da remoção do agendamento/lembrete pelo socket
parent
682bfc1116
commit
a36e05992b
|
@ -1,6 +1,6 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import AppError from "../errors/AppError";
|
import AppError from "../errors/AppError";
|
||||||
|
import { getIO } from "../libs/socket";
|
||||||
import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService";
|
import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService";
|
||||||
import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService";
|
import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService";
|
||||||
import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService";
|
import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService";
|
||||||
|
@ -52,7 +52,10 @@ export const createOrUpdateScheduleNotify = async (req: Request, res: Response):
|
||||||
message: scheduleData.message
|
message: scheduleData.message
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
console.group(':::::::::::::::::: DATA schedulingNotifyCreate:\n',schedulingNotifyCreate)
|
|
||||||
|
// console.group(':::::::::::::::::: DATA schedulingNotifyCreate:\n',schedulingNotifyCreate)
|
||||||
|
// const io = getIO();
|
||||||
|
// io.emit("schedulingNotify", {action: "update", schedulingNotifyCreate });
|
||||||
|
|
||||||
return res.status(200).json(schedulingNotifyCreate);
|
return res.status(200).json(schedulingNotifyCreate);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
import SchedulingNotify from "../../models/SchedulingNotify";
|
import SchedulingNotify from "../../models/SchedulingNotify";
|
||||||
|
import { getIO } from "../../libs/socket";
|
||||||
|
|
||||||
|
|
||||||
const DeleteSchedulingNotifyService = async (id: string | number): Promise<void> => {
|
const DeleteSchedulingNotifyService = async (id: string | number): Promise<void> => {
|
||||||
|
@ -9,9 +10,15 @@ const DeleteSchedulingNotifyService = async (id: string | number): Promise<void>
|
||||||
|
|
||||||
if (!schedulingNotify) {
|
if (!schedulingNotify) {
|
||||||
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
|
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await schedulingNotify.destroy();
|
await schedulingNotify.destroy();
|
||||||
|
|
||||||
|
const io = getIO();
|
||||||
|
io.emit("schedulingNotify", {action: "delete", schedulingNotifyId: id});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DeleteSchedulingNotifyService;
|
export default DeleteSchedulingNotifyService;
|
|
@ -131,6 +131,8 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
order: [["id", "DESC"]]
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -497,9 +497,9 @@ const handleChangeHourBefore = (event) => {
|
||||||
|
|
||||||
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
|
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
|
||||||
|
|
||||||
<Item><DatePicker func={datePickerValue} minDate={true} startEmpty={true} title={'Data do lembrete'}/></Item>
|
<Item><DatePicker func={datePickerValue} minDate={true} startEmpty={true} title={'Data'}/></Item>
|
||||||
|
|
||||||
<Item><TimerPickerSelect func={timerPickerValue} title={'Hora do lembrete'}/></Item>
|
<Item><TimerPickerSelect func={timerPickerValue} title={'Hora'}/></Item>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
@ -530,9 +530,9 @@ const handleChangeHourBefore = (event) => {
|
||||||
|
|
||||||
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
|
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
|
||||||
|
|
||||||
<Item><DatePicker func={datePickerValue} minDate={true} startEmpty={true} title={'Data do lembrete'}/></Item>
|
<Item><DatePicker func={datePickerValue} minDate={true} startEmpty={true} title={'Data'}/></Item>
|
||||||
|
|
||||||
<Item><TimerPickerSelect func={timerPickerValue} title={'Hora do lembrete'}/></Item>
|
<Item><TimerPickerSelect func={timerPickerValue} title={'Hora'}/></Item>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
@ -546,7 +546,7 @@ const handleChangeHourBefore = (event) => {
|
||||||
id="outlined-select-currency"
|
id="outlined-select-currency"
|
||||||
disabled={startDate.length>0 ? false : true}
|
disabled={startDate.length>0 ? false : true}
|
||||||
select
|
select
|
||||||
label="Enviar mensagem para cliente"
|
label="Enviar mensagem para o cliente"
|
||||||
value={currencyHourBefore}
|
value={currencyHourBefore}
|
||||||
size="small"
|
size="small"
|
||||||
onChange={handleChangeHourBefore}
|
onChange={handleChangeHourBefore}
|
||||||
|
@ -567,7 +567,7 @@ const handleChangeHourBefore = (event) => {
|
||||||
aria-label="minimum height"
|
aria-label="minimum height"
|
||||||
minRows={3}
|
minRows={3}
|
||||||
value={textArea1}
|
value={textArea1}
|
||||||
placeholder={'Mensagem de envio para cliente'}
|
placeholder={'Mensagem de envio para o cliente'}
|
||||||
onChange={ handleChange}
|
onChange={ handleChange}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -485,12 +485,11 @@ const handleChangeHourBefore = (event) => {
|
||||||
display: 'grid',
|
display: 'grid',
|
||||||
}}>
|
}}>
|
||||||
<Item>
|
<Item>
|
||||||
<span>Selecione uma opção para encerrar o Atendimento</span>
|
|
||||||
|
|
||||||
<SelectField func={textFieldSelect}
|
<SelectField func={textFieldSelect}
|
||||||
emptyField={false}
|
emptyField={false}
|
||||||
textBoxFieldSelected={`${props.rowData.statusChatEndId}`}
|
textBoxFieldSelected={`${props.rowData.statusChatEndId}`}
|
||||||
header={'Opções de encerramento do atendimento'}
|
header={'Opções lembrete/agendamento'}
|
||||||
currencies={props.statusChatEnd.map((obj)=>{
|
currencies={props.statusChatEnd.map((obj)=>{
|
||||||
return {'value': obj.id, 'label': obj.name}
|
return {'value': obj.id, 'label': obj.name}
|
||||||
})}/>
|
})}/>
|
||||||
|
@ -511,16 +510,16 @@ const handleChangeHourBefore = (event) => {
|
||||||
<Item>
|
<Item>
|
||||||
<DatePicker
|
<DatePicker
|
||||||
func={datePickerValue}
|
func={datePickerValue}
|
||||||
minDate={false}
|
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>
|
||||||
|
@ -556,7 +555,7 @@ const handleChangeHourBefore = (event) => {
|
||||||
<Item>
|
<Item>
|
||||||
<DatePicker
|
<DatePicker
|
||||||
func={datePickerValue}
|
func={datePickerValue}
|
||||||
minDate={false}
|
minDate={true}
|
||||||
schedulingDate={props.rowData.schedulingDate}
|
schedulingDate={props.rowData.schedulingDate}
|
||||||
title={'Data do lembrete'}/>
|
title={'Data do lembrete'}/>
|
||||||
</Item>
|
</Item>
|
||||||
|
|
|
@ -67,6 +67,13 @@ const MTable = (props) => {
|
||||||
width: 300,
|
width: 300,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
pageSize: 20,
|
||||||
|
headerStyle: {
|
||||||
|
position: "sticky",
|
||||||
|
top: "0"
|
||||||
|
},
|
||||||
|
maxBodyHeight: "400px",
|
||||||
|
|
||||||
rowStyle: rowData => ({
|
rowStyle: rowData => ({
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF'
|
backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF'
|
||||||
|
|
|
@ -29,6 +29,8 @@ 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 {
|
import {
|
||||||
IconButton,
|
IconButton,
|
||||||
|
@ -71,16 +73,46 @@ const reducerQ = (state, action) =>{
|
||||||
return [...state, ...newQueries]
|
return [...state, ...newQueries]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type === "DELETE_SCHEDULE") {
|
|
||||||
|
|
||||||
|
// if (action.type === "UPDATE_SCHEDULING") {
|
||||||
|
|
||||||
|
// const scheduling = action.payload;
|
||||||
|
// const schedulingIndex = state.findIndex((u) => u.id === +scheduling.id);
|
||||||
|
|
||||||
|
// console.log('**************** UPDATE_SCHEDULING scheduleIndex: ', schedulingIndex)
|
||||||
|
|
||||||
|
// if (schedulingIndex !== -1) {
|
||||||
|
// state[schedulingIndex] = scheduling;
|
||||||
|
// return [...state];
|
||||||
|
// } else {
|
||||||
|
// return [scheduling, ...state];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (action.type === "DELETE_SCHEDULING") {
|
||||||
|
|
||||||
const scheduleId = action.payload;
|
const scheduleId = action.payload;
|
||||||
|
|
||||||
const scheduleIndex = state.findIndex((q) => q.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);
|
||||||
}
|
}
|
||||||
return [...state];
|
return [...state];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (action.type === "DELETE_QUEUE") {
|
||||||
|
// const queueId = action.payload;
|
||||||
|
// const queueIndex = state.findIndex((q) => q.id === queueId);
|
||||||
|
// if (queueIndex !== -1) {
|
||||||
|
// state.splice(queueIndex, 1);
|
||||||
|
// }
|
||||||
|
// return [...state];
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (action.type === "RESET") {
|
if (action.type === "RESET") {
|
||||||
return [];
|
return [];
|
||||||
|
@ -191,6 +223,42 @@ const SchedulesReminder = () => {
|
||||||
const [statusEndChat, setStatusEndChat] = useState(null)
|
const [statusEndChat, setStatusEndChat] = useState(null)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
|
|
||||||
|
socket.on("schedulingNotify", (data) => {
|
||||||
|
|
||||||
|
console.log('SOCKET IO')
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
// if (data.action === "update" || data.action === "create") {
|
||||||
|
|
||||||
|
// console.log('UPDATE_SCHEDULING: ', data.schedulingNotifyCreate)
|
||||||
|
|
||||||
|
// // dispatchQ({ type: "UPDATE_SCHEDULING", payload: data.schedulingNotifyCreate });
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (data.action === "delete") {
|
||||||
|
console.log('DELETE_SCHEDULING id: ', data.schedulingNotifyId)
|
||||||
|
dispatchQ({ type: "DELETE_SCHEDULING", payload: +data.schedulingNotifyId });
|
||||||
|
//handleDeleteRows(data.schedulingNotifyId)
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
socket.disconnect();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// dispatch({ type: "RESET" });
|
// dispatch({ type: "RESET" });
|
||||||
dispatchQ({ type: "RESET" })
|
dispatchQ({ type: "RESET" })
|
||||||
|
@ -215,7 +283,8 @@ const SchedulesReminder = () => {
|
||||||
|
|
||||||
console.log(':::::::::::::: statusChatEndLoad: ', statusChatEndLoad.data)
|
console.log(':::::::::::::: statusChatEndLoad: ', statusChatEndLoad.data)
|
||||||
|
|
||||||
setStatusEndChat(statusChatEndLoad.data)
|
|
||||||
|
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) {
|
||||||
|
@ -264,13 +333,13 @@ const SchedulesReminder = () => {
|
||||||
if(!loading){
|
if(!loading){
|
||||||
console.log('carregando table...')
|
console.log('carregando table...')
|
||||||
|
|
||||||
const dataLoad = query.map(({ scheduleReminder, ...others }) => (
|
// const dataLoad = query.map(({ scheduleReminder, ...others }) => (
|
||||||
|
|
||||||
{ ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' }
|
// { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' }
|
||||||
|
|
||||||
));
|
// ));
|
||||||
|
|
||||||
console.log('NEW DATA: ', dataLoad)
|
// 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' }
|
||||||
|
@ -333,7 +402,7 @@ 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!"));
|
||||||
handleDeleteRows(scheduleId)
|
//handleDeleteRows(scheduleId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
|
@ -519,6 +588,13 @@ const handleModal = (rowData) => {
|
||||||
width: 300,
|
width: 300,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
pageSize: 20,
|
||||||
|
headerStyle: {
|
||||||
|
position: "sticky",
|
||||||
|
top: "0"
|
||||||
|
},
|
||||||
|
maxBodyHeight: "400px",
|
||||||
|
|
||||||
rowStyle: {
|
rowStyle: {
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue