From 9e8c9be17de347173538cb376b6ec2004253d52b Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 22 Mar 2022 23:59:01 -0300 Subject: [PATCH] =?UTF-8?q?Altera=C3=A7=C3=A3o=20em=20node=20redundante=20?= =?UTF-8?q?do=20banco=20de=20dados=20Schedules=20e=20altera=C3=A7=C3=A3o?= =?UTF-8?q?=20no=20c=C3=B3digo=20com=20refer=C3=AAncia=20a=20esse=20nome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/SchedulingNotifyController.ts | 4 +- backend/src/controllers/TicketController.ts | 19 +- backend/src/database/index.ts | 4 +- .../20220322202120-rename-table-schedules.ts | 11 + ...20220322210021-rename-scheduleId-column.ts | 11 + ...220323010209-rename-table-StatusChatEnd.ts | 11 + .../20220323011547-change-column-referece.ts | 23 + .../20220221193811-create-scheduling-data.ts | 4 +- backend/src/models/SchedulingNotify.ts | 10 +- .../models/{Schedule.ts => StatusChatEnd.ts} | 4 +- .../CreateSchedulingNotifyService.ts | 14 +- .../ListSchedulingNotifyContactService.ts | 2 +- .../ListStatusChatEndService.ts} | 10 +- .../FindOrCreateTicketService.ts | 2 +- .../components/ChatEnd/ModalChatEnd/index.js | 18 +- .../DatePicker2/index.js | 0 .../ModalUpdateScheduleReminder/index.js | 450 ++++++++++++++++++ frontend/src/components/Ticket/index.js | 6 +- .../components/TicketActionButtons/index.js | 4 +- frontend/src/pages/SchedulesReminder/index.js | 53 ++- 20 files changed, 599 insertions(+), 61 deletions(-) create mode 100644 backend/src/database/migrations/20220322202120-rename-table-schedules.ts create mode 100644 backend/src/database/migrations/20220322210021-rename-scheduleId-column.ts create mode 100644 backend/src/database/migrations/20220323010209-rename-table-StatusChatEnd.ts create mode 100644 backend/src/database/migrations/20220323011547-change-column-referece.ts rename backend/src/models/{Schedule.ts => StatusChatEnd.ts} (84%) rename backend/src/services/{ScheduleService/ListScheduleService.ts => StatusChatEndService/ListStatusChatEndService.ts} (75%) rename frontend/src/components/{Report => ModalUpdateScheduleReminder}/DatePicker2/index.js (100%) create mode 100644 frontend/src/components/ModalUpdateScheduleReminder/index.js diff --git a/backend/src/controllers/SchedulingNotifyController.ts b/backend/src/controllers/SchedulingNotifyController.ts index 7765d00..921e663 100644 --- a/backend/src/controllers/SchedulingNotifyController.ts +++ b/backend/src/controllers/SchedulingNotifyController.ts @@ -3,7 +3,7 @@ import AppError from "../errors/AppError"; import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService"; import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService"; - + // const test = await ListSchedulingNotifyContactService('5517988310949','2022-03-18','2022-03-19'); // const test = await ListSchedulingNotifyContactService('','2022-03-18','2022-03-19'); @@ -24,7 +24,7 @@ export const reportScheduleNotifyByDateStartDateEnd = async (req: Request, res: const data_query = await ListSchedulingNotifyContactService(contactNumber, startDate, endDate); - console.group('DATA QUERY SCHEDULE:\n',data_query) + // console.group('DATA QUERY SCHEDULE:\n',data_query) return res.status(200).json(data_query); diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index ff56802..2cebf04 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -33,7 +33,7 @@ interface TicketData { } -import ListScheduleService from "../services/ScheduleService/ListScheduleService"; +import ListStatusChatEndService from "../services/StatusChatEndService/ListStatusChatEndService"; export const index = async (req: Request, res: Response): Promise => { const { @@ -93,19 +93,14 @@ export const show = async (req: Request, res: Response): Promise => { const contact = await ShowTicketService(ticketId); - const { schedules, count, hasMore } = await ListScheduleService({ searchParam: "", pageNumber: "1" }); - - + const { statusChatEnd, count, hasMore } = await ListStatusChatEndService({ searchParam: "", pageNumber: "1" }); + ////////////////// const schedulesContact = await ListSchedulingNotifyContactService(contact.contact.number); ///////////////// + - // console.log('############### schedulesContact: ', schedulesContact) - // console.log('############### contact.contact.number: ',contact.contact.number) - - // return res.status(200).json(contact); - - return res.status(200).json({contact, schedules, schedulesContact}); + return res.status(200).json({contact, statusChatEnd, schedulesContact}); }; @@ -143,11 +138,11 @@ export const update = async ( req: Request, res: Response ): Promise = // lembrete const scheduleData = JSON.parse(schedulingNotifyData) - if( scheduleData.scheduleId === '2'){ + if( scheduleData.statusChatEndId === '2'){ const schedulingNotifyCreate = await CreateSchedulingNotifyService( { ticketId: scheduleData.ticketId, - scheduleId: scheduleData.scheduleId, + statusChatEndId: scheduleData.statusChatEndId, schedulingDate: scheduleData.schedulingDate, schedulingTime: scheduleData.schedulingTime, message: scheduleData.message diff --git a/backend/src/database/index.ts b/backend/src/database/index.ts index 6846c81..b8beda2 100644 --- a/backend/src/database/index.ts +++ b/backend/src/database/index.ts @@ -12,7 +12,7 @@ import UserQueue from "../models/UserQueue"; import QuickAnswer from "../models/QuickAnswer"; import SchedulingNotify from "../models/SchedulingNotify"; -import Schedule from "../models/Schedule"; +import StatusChatEnd from "../models/StatusChatEnd"; // eslint-disable-next-line @@ -35,7 +35,7 @@ const models = [ QuickAnswer, SchedulingNotify, - Schedule, + StatusChatEnd, ]; sequelize.addModels(models); diff --git a/backend/src/database/migrations/20220322202120-rename-table-schedules.ts b/backend/src/database/migrations/20220322202120-rename-table-schedules.ts new file mode 100644 index 0000000..d7bbb08 --- /dev/null +++ b/backend/src/database/migrations/20220322202120-rename-table-schedules.ts @@ -0,0 +1,11 @@ +import { QueryInterface, DataTypes } from "sequelize"; + +module.exports = { + up: (queryInterface: QueryInterface) => { + return queryInterface.renameTable("Schedules", "StatusChatEnd"); + }, + + down: (queryInterface: QueryInterface) => { + return queryInterface.renameTable("StatusChatEnd", "Schedules"); + } +}; diff --git a/backend/src/database/migrations/20220322210021-rename-scheduleId-column.ts b/backend/src/database/migrations/20220322210021-rename-scheduleId-column.ts new file mode 100644 index 0000000..f3e5635 --- /dev/null +++ b/backend/src/database/migrations/20220322210021-rename-scheduleId-column.ts @@ -0,0 +1,11 @@ +import { QueryInterface, DataTypes } from "sequelize"; + +module.exports = { + up: (queryInterface: QueryInterface) => { + return queryInterface.renameColumn("SchedulingNotifies", "scheduleId", "statusChatEndId"); + }, + + down: (queryInterface: QueryInterface) => { + return queryInterface.renameColumn("SchedulingNotifies", "statusChatEndId", "scheduleId"); + } +}; diff --git a/backend/src/database/migrations/20220323010209-rename-table-StatusChatEnd.ts b/backend/src/database/migrations/20220323010209-rename-table-StatusChatEnd.ts new file mode 100644 index 0000000..b41eaf0 --- /dev/null +++ b/backend/src/database/migrations/20220323010209-rename-table-StatusChatEnd.ts @@ -0,0 +1,11 @@ +import { QueryInterface, DataTypes } from "sequelize"; + +module.exports = { + up: (queryInterface: QueryInterface) => { + return queryInterface.renameTable("StatusChatEnd", "StatusChatEnds"); + }, + + down: (queryInterface: QueryInterface) => { + return queryInterface.renameTable("StatusChatEnds", "StatusChatEnd"); + } +}; diff --git a/backend/src/database/migrations/20220323011547-change-column-referece.ts b/backend/src/database/migrations/20220323011547-change-column-referece.ts new file mode 100644 index 0000000..7bdf4dc --- /dev/null +++ b/backend/src/database/migrations/20220323011547-change-column-referece.ts @@ -0,0 +1,23 @@ +import { QueryInterface, DataTypes } from "sequelize"; + +module.exports = { + up: (queryInterface: QueryInterface) => { + return queryInterface.changeColumn("SchedulingNotifies", "statusChatEndId", { + type: DataTypes.INTEGER, + references: { model: "StatusChatEnds", key: "id" }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + allowNull: false + }); + }, + + down: (queryInterface: QueryInterface) => { + return queryInterface.changeColumn("SchedulingNotifies", "statusChatEndId", { + type: DataTypes.INTEGER, + references: { model: "Schedules", key: "id" }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + allowNull: false + }); + } +}; diff --git a/backend/src/database/seeds/20220221193811-create-scheduling-data.ts b/backend/src/database/seeds/20220221193811-create-scheduling-data.ts index de1fc6e..ee34121 100644 --- a/backend/src/database/seeds/20220221193811-create-scheduling-data.ts +++ b/backend/src/database/seeds/20220221193811-create-scheduling-data.ts @@ -3,7 +3,7 @@ import { QueryInterface } from "sequelize"; module.exports = { up: (queryInterface: QueryInterface) => { return queryInterface.bulkInsert( - "Schedules", + "StatusChatEnd", [ { name: "SEM RETORNO DO CLIENTE", @@ -21,6 +21,6 @@ module.exports = { }, down: (queryInterface: QueryInterface) => { - return queryInterface.bulkDelete("Schedules", {}); + return queryInterface.bulkDelete("StatusChatEnd", {}); } }; diff --git a/backend/src/models/SchedulingNotify.ts b/backend/src/models/SchedulingNotify.ts index af94607..1ba2403 100644 --- a/backend/src/models/SchedulingNotify.ts +++ b/backend/src/models/SchedulingNotify.ts @@ -10,7 +10,7 @@ import { BelongsTo } from "sequelize-typescript"; - import Schedule from "./Schedule"; + import StatusChatEnd from "./StatusChatEnd"; import Ticket from "./Ticket"; @Table @@ -20,12 +20,12 @@ import { @Column id: number; - @ForeignKey(() => Schedule) + @ForeignKey(() => StatusChatEnd) @Column - scheduleId: number; + statusChatEndId: number; - @BelongsTo(() => Schedule) - schedule: Schedule; + @BelongsTo(() => StatusChatEnd) + statusChatEnd: StatusChatEnd; @ForeignKey(() => Ticket) diff --git a/backend/src/models/Schedule.ts b/backend/src/models/StatusChatEnd.ts similarity index 84% rename from backend/src/models/Schedule.ts rename to backend/src/models/StatusChatEnd.ts index 01032f2..dde5775 100644 --- a/backend/src/models/Schedule.ts +++ b/backend/src/models/StatusChatEnd.ts @@ -12,7 +12,7 @@ import { import SchedulingNotify from "./SchedulingNotify"; @Table - class Schedule extends Model { + class StatusChatEnd extends Model { @PrimaryKey @AutoIncrement @Column @@ -31,5 +31,5 @@ import { SchedulingNotifies: SchedulingNotify[]; } - export default Schedule; + export default StatusChatEnd; \ No newline at end of file diff --git a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts index 70ec9e1..76518fb 100644 --- a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts +++ b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts @@ -4,27 +4,19 @@ import SchedulingNotify from "../../models/SchedulingNotify"; interface Request { ticketId: string, - scheduleId: string, + statusChatEndId: string, schedulingDate: string, schedulingTime: string, message: string } -const CreateSchedulingNotifyService = async ( - { - ticketId, - scheduleId, - schedulingDate, - schedulingTime, - message - - }: Request): Promise => { +const CreateSchedulingNotifyService = async ({ ticketId, statusChatEndId, schedulingDate, schedulingTime, message }: Request): Promise => { const schedulingNotify = await SchedulingNotify.create( { ticketId, - scheduleId, + statusChatEndId, schedulingDate, schedulingTime, message diff --git a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts index 72ba2fe..4ef8275 100644 --- a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts +++ b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts @@ -112,7 +112,7 @@ const ListSchedulingNotifyContactService = async (contactNumber: string = '', st raw: true, where: where_clause_notify, - attributes:['id', [Sequelize.fn("DATE_FORMAT",Sequelize.col("schedulingDate"),"%d/%m/%Y %H:%i:%s"),"schedulingDate"], + attributes:['id', 'ticketId', [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/ScheduleService/ListScheduleService.ts b/backend/src/services/StatusChatEndService/ListStatusChatEndService.ts similarity index 75% rename from backend/src/services/ScheduleService/ListScheduleService.ts rename to backend/src/services/StatusChatEndService/ListStatusChatEndService.ts index 493921a..a995f82 100644 --- a/backend/src/services/ScheduleService/ListScheduleService.ts +++ b/backend/src/services/StatusChatEndService/ListStatusChatEndService.ts @@ -1,5 +1,5 @@ import { Sequelize } from "sequelize"; -import Schedule from "../../models/Schedule"; +import StatusChatEnd from "../../models/StatusChatEnd"; interface Request { searchParam?: string; @@ -7,7 +7,7 @@ interface Request { } interface Response { - schedules: Schedule[]; + statusChatEnd: StatusChatEnd[]; count: number; hasMore: boolean; } @@ -23,7 +23,7 @@ interface Request { const limit = 20; const offset = limit * (+pageNumber - 1); - const { count, rows: schedules } = await Schedule.findAndCountAll({ + const { count, rows: statusChatEnd } = await StatusChatEnd.findAndCountAll({ where: whereCondition, attributes: ['id', 'name'], limit, @@ -31,10 +31,10 @@ interface Request { order: [["id", "ASC"]] }); - const hasMore = count > offset + schedules.length; + const hasMore = count > offset + statusChatEnd.length; return { - schedules, + statusChatEnd, count, hasMore }; diff --git a/backend/src/services/TicketServices/FindOrCreateTicketService.ts b/backend/src/services/TicketServices/FindOrCreateTicketService.ts index 6f7e84a..bb5ed2c 100644 --- a/backend/src/services/TicketServices/FindOrCreateTicketService.ts +++ b/backend/src/services/TicketServices/FindOrCreateTicketService.ts @@ -1,4 +1,4 @@ -import { subHours, subMinutes } from "date-fns"; +import { subHours, subMinutes, subSeconds } from "date-fns"; import { Op } from "sequelize"; import Contact from "../../models/Contact"; import Ticket from "../../models/Ticket"; diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index 0bb9c34..3851d2f 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -112,14 +112,12 @@ const Modal = (props) => { const [open, setOpen] = useState(true); const [scroll, /*setScroll*/] = useState('body'); - const [scheduleId, setScheduling] = useState(null) + const [statusChatEndId, setStatusChatEnd] = useState(null) const [startDate, setDatePicker] = useState(new Date()) const [timerPicker, setTimerPicker] = useState(new Date()) const [textArea1, setTextArea1] = useState() - - const [data] = useState(props.schedules) - + const [schedulesContact, dispatch] = useReducer(reducer, []); @@ -200,12 +198,12 @@ const timerPickerValue = (data) => { const handleChatEnd = (event, reason) => { - let dataSendServer = {'scheduleId': scheduleId} + let dataSendServer = {'statusChatEndId': statusChatEndId} if (reason && reason === "backdropClick") return; - if (scheduleId === '2'){ + if (statusChatEndId === '2'){ console.log('Entrou! textArea1: ', textArea1) @@ -236,7 +234,7 @@ const timerPickerValue = (data) => { } dataSendServer = { - 'scheduleId': scheduleId, + 'statusChatEndId': statusChatEndId, 'schedulingDate': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), 'schedulingTime': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), 'message': textArea1 @@ -264,7 +262,7 @@ const timerPickerValue = (data) => { // Get from child 1 const textFieldSelect = (data) => { console.log('textFieldSelect: ',data); - setScheduling(data) + setStatusChatEnd(data) } @@ -321,7 +319,7 @@ const handleChange = (event) => { { + currencies={props.statusChatEnd.map((obj)=>{ return {'value': obj.id, 'label': obj.name} })}/> @@ -330,7 +328,7 @@ const handleChange = (event) => { - {scheduleId==='2' && + {statusChatEndId==='2' && diff --git a/frontend/src/components/Report/DatePicker2/index.js b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js similarity index 100% rename from frontend/src/components/Report/DatePicker2/index.js rename to frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js diff --git a/frontend/src/components/ModalUpdateScheduleReminder/index.js b/frontend/src/components/ModalUpdateScheduleReminder/index.js new file mode 100644 index 0000000..4b36f61 --- /dev/null +++ b/frontend/src/components/ModalUpdateScheduleReminder/index.js @@ -0,0 +1,450 @@ + +import React, { useState, useEffect, useRef, useReducer } from 'react'; +import Button from '@mui/material/Button'; +import Dialog from '@mui/material/Dialog'; +import DialogActions from '@mui/material/DialogActions'; +import DialogContent from '@mui/material/DialogContent'; +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 DatePicker from './DatePicker2' +import TimerPickerSelect from '../ChatEnd/TimerPickerSelect' +import TextareaAutosize from '@mui/material/TextareaAutosize'; +// import { subHours } from "date-fns"; + + + +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 toastError from "../../errors/toastError"; +import ConfirmationModal from "../ConfirmationModal"; + + +const reducer = (state, action) => { + + + if (action.type === "LOAD_SCHEDULES") { + const schedulesContact = action.payload; + const newSchedules= []; + + schedulesContact.forEach((schedule) => { + const scheduleIndex = state.findIndex((s) => s.id === schedule.id); + if (scheduleIndex !== -1) { + state[scheduleIndex] = schedule; + } else { + newSchedules.push(schedule); + } + }); + + return [...state, ...newSchedules]; + } + + if (action.type === "DELETE_SCHEDULE") { + const scheduleId = action.payload; + const scheduleIndex = state.findIndex((q) => q.id === scheduleId); + if (scheduleIndex !== -1) { + state.splice(scheduleIndex, 1); + } + return [...state]; + } + + if (action.type === "RESET") { + return []; + } +}; + + + +const Item = (props) => { + + const { sx, ...other } = props; + return ( + (theme.palette.mode === 'dark' ? '#101010' : '#fff'), + color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), + border: '1px solid', + borderColor: (theme) => + theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', + p: 1, + m: 1, + borderRadius: 2, + fontSize: '0.875rem', + fontWeight: '700', + ...sx, + }} + {...other} + /> + ); +} + +Item.propTypes = { + sx: PropTypes.oneOfType([ + PropTypes.arrayOf( + PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), + ), + PropTypes.func, + PropTypes.object, + ]), +}; + + + +const Modal = (props) => { + + const [selectedSchedule, setSelectedSchedule] = useState(null); + const [confirmModalOpen, setConfirmModalOpen] = useState(false); + + const [open, setOpen] = useState(true); + const [scroll, /*setScroll*/] = useState('body'); + const [statusChatEndId, setStatusChatEnd] = useState(null) + const [startDate, setDatePicker] = useState(props.schedulingTime ? new Date(props.schedulingTime) : new Date()) + const [timerPicker, setTimerPicker] = useState(new Date()) + const [textArea1, setTextArea1] = useState() + + + const [schedulesContact, dispatch] = useReducer(reducer, []); + + + const handleCancel = (event, reason) => { + + if (reason && reason === "backdropClick") + return; + + setOpen(false); + }; + + + + useEffect(() => { + + (async () => { + try { + + const { data } = await api.get("/tickets/" + props.ticketId); + + dispatch({ type: "LOAD_SCHEDULES", payload: data.schedulesContact }); + + } catch (err) { + toastError(err); + } + })(); + }, [props]); + + + function formatedTimeHour(timer){ + return `${timer.getHours().toString().padStart(2, '0')}:${timer.getMinutes().toString().padStart(2, '0')}` + } + + function formatedFullCurrentDate(){ + let dateCurrent = new Date() + let day = dateCurrent.getDate().toString().padStart(2, '0'); + let month = (dateCurrent.getMonth()+1).toString().padStart(2, '0'); + let year = dateCurrent.getFullYear(); + return `${year}-${month}-${day}`; + } + + + + const handleCloseConfirmationModal = () => { + setConfirmModalOpen(false); + setSelectedSchedule(null); + }; + + + const handleDeleteSchedule = async (scheduleId) => { + try { + await api.delete(`/schedule/${scheduleId}`); + toast.success(("Lembrete deletado com sucesso!")); + dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); + } catch (err) { + toastError(err); + } + setSelectedSchedule(null); + }; + + // Get from child 2 +const datePickerValue = (data) => { + console.log('datePickerValue: ',(data)); + setDatePicker(data) + + +} + +// Get from child 3 +const timerPickerValue = (data) => { + console.log('timerPickerValue: ',(data)); + setTimerPicker(data) + + +} + + + + const handleChatEnd = (event, reason) => { + + let dataSendServer = {'statusChatEndId': statusChatEndId} + + if (reason && reason === "backdropClick") + return; + + if (statusChatEndId === '2'){ + + console.log('Entrou! textArea1: ', textArea1) + + + 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()) || + (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 + } + + 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`)), + 'message': textArea1 + } + + } + + props.func(dataSendServer) + + setOpen(false); + }; + + + const descriptionElementRef = useRef(null); + useEffect(() => { + if (open) { + const { current: descriptionElement } = descriptionElementRef; + if (descriptionElement !== null) { + descriptionElement.focus(); + } + } + }, [open]); + + + // Get from child 1 +const textFieldSelect = (data) => { + console.log('textFieldSelect: ',data); + setStatusChatEnd(data) +} + + + + +const handleChange = (event) => { + + setTextArea1(event.target.value); + +}; + + + + return ( + + + + {props.modal_header} + + + + + + + + + + + + Selecione uma opção para encerrar o Atendimento + + { + return {'value': obj.id, 'label': obj.name} + })}/> + + + + + + + {statusChatEndId==='2' && + + + + Lembrete + + + + + + + + + + + + + + + + + + + + } + + + + {schedulesContact.length>0 && !props.update && + + + + + + handleDeleteSchedule(selectedSchedule.id)} + > + Deseja realmente deletar esse Lembrete? + + Lembretes + + + + + + + Data + + + Hora + + + Mensagem + + + Deletar + + + + + + <> + {schedulesContact.map((scheduleData, index) => ( + + {scheduleData.schedulingDate.split(' ')[0]} + {scheduleData.schedulingTime.split(' ')[1]} + {scheduleData.message} + + + + { + setSelectedSchedule(scheduleData); + setConfirmModalOpen(true); + + }} + > + + + + + + ))} + + +
+
+
} + + +
+
+ + + +
+ +
+ +
+
+ + ); +} + +export default Modal \ No newline at end of file diff --git a/frontend/src/components/Ticket/index.js b/frontend/src/components/Ticket/index.js index fe0dd8f..6b4a1cb 100644 --- a/frontend/src/components/Ticket/index.js +++ b/frontend/src/components/Ticket/index.js @@ -83,7 +83,7 @@ const Ticket = () => { const [contact, setContact] = useState({}); const [ticket, setTicket] = useState({}); - const [schedule, setSchedule] = useState({}) + const [statusChatEnd, setStatusChatEnd] = useState({}) useEffect(() => { setLoading(true); @@ -101,7 +101,7 @@ const Ticket = () => { setContact(data.contact.contact); setTicket(data.contact); - setSchedule(data.schedules) + setStatusChatEnd(data.statusChatEnd) setLoading(false); } catch (err) { @@ -172,7 +172,7 @@ const Ticket = () => { />
- +
diff --git a/frontend/src/components/TicketActionButtons/index.js b/frontend/src/components/TicketActionButtons/index.js index 5d33693..66c18bd 100644 --- a/frontend/src/components/TicketActionButtons/index.js +++ b/frontend/src/components/TicketActionButtons/index.js @@ -27,7 +27,7 @@ const useStyles = makeStyles(theme => ({ }, })); -const TicketActionButtons = ({ ticket, schedule }) => { +const TicketActionButtons = ({ ticket, statusChatEnd }) => { const classes = useStyles(); const history = useHistory(); const [anchorEl, setAnchorEl] = useState(null); @@ -63,7 +63,7 @@ const TicketActionButtons = ({ ticket, schedule }) => { render() diff --git a/frontend/src/pages/SchedulesReminder/index.js b/frontend/src/pages/SchedulesReminder/index.js index b156842..1f03d1d 100644 --- a/frontend/src/pages/SchedulesReminder/index.js +++ b/frontend/src/pages/SchedulesReminder/index.js @@ -23,6 +23,13 @@ import Delete from '@material-ui/icons/Delete'; 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 Modal from "../../../..ChatEnd/ModalChatEnd"; +import Modal from "../../components/ModalUpdateScheduleReminder"; + + import { IconButton, Paper, @@ -85,7 +92,7 @@ const reducerQ = (state, action) =>{ const reducer = (state, action) => { - if (action.type === "LOAD_USERS") { + if (action.type === "LOAD_SCHEDULES") { const users = action.payload; const newUsers = []; @@ -181,6 +188,8 @@ const SchedulesReminder = () => { const [confirmModalOpen, setConfirmModalOpen] = useState(false); const [dataRows, setData] = useState([]); + const [statusEndChat, setStatusEndChat] = useState(null) + useEffect(() => { dispatch({ type: "RESET" }); @@ -200,7 +209,7 @@ const SchedulesReminder = () => { params: { searchParam, pageNumber }, }); - dispatch({ type: "LOAD_USERS", payload: data.users }); + dispatch({ type: "LOAD_SCHEDULES", payload: data.users }); //setHasMore(data.hasMore); //setLoading(false); } catch (err) { @@ -233,6 +242,8 @@ const SchedulesReminder = () => { dispatchQ({ type: "RESET" }) dispatchQ({ type: "LOAD_QUERY", payload: dataQuery.data }); + // setStatusEndChat(dataQuery.data.statusEndChat) + //setLoading(false); } catch (err) { @@ -307,6 +318,39 @@ const handleDeleteSchedule = async (scheduleId) => { setSelectedSchedule(null); }; + +const chatEndVal = (data) => { + + if(data){ + + console.log('DATA SCHECULE: ', data) + + // data = {...data, 'ticketId': ticket.id} + + // console.log('ChatEnd: ',(data)); + + // handleUpdateTicketStatus(null, "closed", user?.id, data) + + } + +} + + +const handleModal = (rowData) => { + + render() + +}; + return ( @@ -386,7 +430,10 @@ const handleDeleteSchedule = async (scheduleId) => { { icon: Edit, tooltip: 'Editar', - onClick: (event, rowData) => console.log("You saved ",rowData) + onClick: (event, rowData) => { + console.log("You saved ",rowData) + handleModal(rowData) + } }, { icon: Delete,