diff --git a/backend/src/controllers/SchedulingNotifyController.ts b/backend/src/controllers/SchedulingNotifyController.ts index 6c490ff..f38ce90 100644 --- a/backend/src/controllers/SchedulingNotifyController.ts +++ b/backend/src/controllers/SchedulingNotifyController.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import AppError from "../errors/AppError"; - +import { getIO } from "../libs/socket"; import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService"; import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService"; import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService"; @@ -52,7 +52,10 @@ export const createOrUpdateScheduleNotify = async (req: Request, res: Response): 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); diff --git a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts index 8f6e4cc..13931bb 100644 --- a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts +++ b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts @@ -62,7 +62,7 @@ const CreateSchedulingNotifyService = async ({ }) } - + return schedulingNotify } diff --git a/backend/src/services/SchedulingNotifyServices/DeleteSchedulingNotifyService.ts b/backend/src/services/SchedulingNotifyServices/DeleteSchedulingNotifyService.ts index 38f1176..ba3acae 100644 --- a/backend/src/services/SchedulingNotifyServices/DeleteSchedulingNotifyService.ts +++ b/backend/src/services/SchedulingNotifyServices/DeleteSchedulingNotifyService.ts @@ -1,5 +1,6 @@ import AppError from "../../errors/AppError"; import SchedulingNotify from "../../models/SchedulingNotify"; +import { getIO } from "../../libs/socket"; const DeleteSchedulingNotifyService = async (id: string | number): Promise => { @@ -9,9 +10,15 @@ const DeleteSchedulingNotifyService = async (id: string | number): Promise if (!schedulingNotify) { throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404); + return } await schedulingNotify.destroy(); + + const io = getIO(); + io.emit("schedulingNotify", {action: "delete", schedulingNotifyId: id}); + + }; export default DeleteSchedulingNotifyService; \ No newline at end of file diff --git a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts index ba862ea..046cba1 100644 --- a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts +++ b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts @@ -130,6 +130,8 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st }, ], + + order: [["id", "DESC"]] }); diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index e28ca51..4fe240a 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -497,9 +497,9 @@ const handleChangeHourBefore = (event) => { - + - + @@ -530,9 +530,9 @@ const handleChangeHourBefore = (event) => { - + - + @@ -546,7 +546,7 @@ const handleChangeHourBefore = (event) => { id="outlined-select-currency" disabled={startDate.length>0 ? false : true} select - label="Enviar mensagem para cliente" + label="Enviar mensagem para o cliente" value={currencyHourBefore} size="small" onChange={handleChangeHourBefore} @@ -567,7 +567,7 @@ const handleChangeHourBefore = (event) => { aria-label="minimum height" minRows={3} value={textArea1} - placeholder={'Mensagem de envio para cliente'} + placeholder={'Mensagem de envio para o cliente'} onChange={ handleChange} style={{ width: '100%' }} /> diff --git a/frontend/src/components/ModalUpdateScheduleReminder/index.js b/frontend/src/components/ModalUpdateScheduleReminder/index.js index b1b8142..bf02e94 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/index.js @@ -485,12 +485,11 @@ const handleChangeHourBefore = (event) => { display: 'grid', }}> - Selecione uma opção para encerrar o Atendimento { return {'value': obj.id, 'label': obj.name} })}/> @@ -511,16 +510,16 @@ const handleChangeHourBefore = (event) => { + title={'Data'}/> + title={'Hora'}/> @@ -556,7 +555,7 @@ const handleChangeHourBefore = (event) => { diff --git a/frontend/src/components/Report/MTable/index.js b/frontend/src/components/Report/MTable/index.js index fabc0a0..a2ca6b5 100644 --- a/frontend/src/components/Report/MTable/index.js +++ b/frontend/src/components/Report/MTable/index.js @@ -67,6 +67,13 @@ const MTable = (props) => { width: 300, }, + pageSize: 20, + headerStyle: { + position: "sticky", + top: "0" + }, + maxBodyHeight: "400px", + rowStyle: rowData => ({ fontSize: 12, backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF' diff --git a/frontend/src/pages/SchedulesReminder/index.js b/frontend/src/pages/SchedulesReminder/index.js index b64218d..5dfb69d 100644 --- a/frontend/src/pages/SchedulesReminder/index.js +++ b/frontend/src/pages/SchedulesReminder/index.js @@ -29,6 +29,8 @@ import { render } from '@testing-library/react'; // import Modal from "../../../..ChatEnd/ModalChatEnd"; import Modal from "../../components/ModalUpdateScheduleReminder"; +import openSocket from "socket.io-client"; + import { IconButton, @@ -71,15 +73,45 @@ const reducerQ = (state, action) =>{ 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 scheduleIndex = state.findIndex((q) => q.id === scheduleId); + + const scheduleIndex = state.findIndex((u) => u.id === scheduleId); + console.log('**************** scheduleIndex: ', scheduleIndex) if (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") { @@ -190,6 +222,42 @@ const SchedulesReminder = () => { 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(() => { // dispatch({ type: "RESET" }); @@ -214,8 +282,9 @@ const SchedulesReminder = () => { // dispatch({ type: "LOAD_STATUS_CHAT_END", payload: statusChatEndLoad.data }); console.log(':::::::::::::: statusChatEndLoad: ', statusChatEndLoad.data) + - setStatusEndChat(statusChatEndLoad.data) + setStatusEndChat(statusChatEndLoad.data.filter(status => (status.id == '2' || status.id == '3'))) //setHasMore(data.hasMore); // setLoading(false); } catch (err) { @@ -264,13 +333,13 @@ const SchedulesReminder = () => { if(!loading){ 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 }) => ( { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } @@ -333,7 +402,7 @@ const handleDeleteSchedule = async (scheduleId) => { try { await api.delete(`/schedule/${scheduleId}`); toast.success(("Lembrete/Agendamento deletado com sucesso!")); - handleDeleteRows(scheduleId) + //handleDeleteRows(scheduleId) } catch (err) { toastError(err); } @@ -519,6 +588,13 @@ const handleModal = (rowData) => { width: 300, }, + pageSize: 20, + headerStyle: { + position: "sticky", + top: "0" + }, + maxBodyHeight: "400px", + rowStyle: { fontSize: 12, }