diff --git a/backend/package.json b/backend/package.json index 61d065e..6098b4e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -37,7 +37,7 @@ "sequelize-cli": "^5.5.1", "sequelize-typescript": "^1.1.0", "socket.io": "^3.0.5", - "whatsapp-web.js": "^1.15.5", + "whatsapp-web.js": "^1.15.6", "yup": "^0.32.8" }, "devDependencies": { diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index 643141b..104972f 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -10,6 +10,7 @@ import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage"; import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService"; import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService"; +import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService"; @@ -94,9 +95,16 @@ export const show = async (req: Request, res: Response): Promise => { const { schedules, count, hasMore } = await ListScheduleService({ 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}); + return res.status(200).json({contact, schedules, schedulesContact}); }; diff --git a/backend/src/models/Ticket.ts b/backend/src/models/Ticket.ts index 41ae739..72370e5 100644 --- a/backend/src/models/Ticket.ts +++ b/backend/src/models/Ticket.ts @@ -78,8 +78,8 @@ class Ticket extends Model { @HasMany(() => Message) messages: Message[]; - @HasOne(() => SchedulingNotify) - schedulingNotify: SchedulingNotify + @HasMany(() => SchedulingNotify) + schedulingNotify: SchedulingNotify[]; } export default Ticket; diff --git a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts new file mode 100644 index 0000000..5313116 --- /dev/null +++ b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts @@ -0,0 +1,43 @@ +import Ticket from "../../models/Ticket"; +import Contact from "../../models/Contact"; +import SchedulingNotify from "../../models/SchedulingNotify"; +import { Op, where, Sequelize } from "sequelize"; +import AppError from "../../errors/AppError"; + +const ListSchedulingNotifyContactService = async (contactNumber: string): Promise => { + + + const ticket = await SchedulingNotify.findAll({ + + attributes:['id', [Sequelize.fn("DATE_FORMAT",Sequelize.col("schedulingDate"),"%d/%m/%Y %H:%i:%s"),"schedulingDate"], 'message'], + + include: [ + { + model: Ticket, + required:true, + attributes: [], + include: [ + { + model: Contact, + where:{ + number: contactNumber, + }, + attributes: ['name', 'number'] + }, + ] + }, + + ], + + }); + + + if (!ticket) { + throw new AppError("ERR_NO_TICKET_FOUND", 404); + } + + return ticket; + }; + + export default ListSchedulingNotifyContactService; + \ No newline at end of file diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index db9d91b..f098441 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -6,22 +6,50 @@ 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 DialogTitle from '@mui/material/DialogTitle'; import PropTypes from 'prop-types'; -import Box from '@mui/material/Box'; - +import Box from '@mui/material/Box'; import SelectField from "../../Report/SelectField"; -import DatePicker from '../../Report/DatePicker' - +import DatePicker from '../../Report/DatePicker' import TimerPickerSelect from '../TimerPickerSelect' - + +// import MainHeader from "../../components/MainHeader"; +// import MainHeaderButtonsWrapper from "../../components/MainHeaderButtonsWrapper"; +// import TableRowSkeleton from "../../components/TableRowSkeleton"; +// import Title from "../../components/Title"; import TextareaAutosize from '@mui/material/TextareaAutosize'; -import { addHours } from "date-fns"; +import { addHours, subHours } from "date-fns"; + + + +import { + IconButton, + makeStyles, + Paper, + Table, + TableBody, + TableCell, + TableHead, + TableRow, + Typography, +} from "@material-ui/core"; + +const useStyles = makeStyles((theme) => ({ + mainPaper: { + flex: 1, + padding: theme.spacing(1), + overflowY: "scroll", + ...theme.scrollbarStyles, + }, + customTableCell: { + display: "flex", + alignItems: "center", + justifyContent: "center", + }, +})); const Item = (props) => { @@ -59,6 +87,7 @@ Item.propTypes = { const Modal = (props) => { + const classes = useStyles(); const [open, setOpen] = useState(true); const [scroll, /*setScroll*/] = useState('body'); @@ -69,6 +98,7 @@ const Modal = (props) => { const [data] = useState(props.schedules) + const [schedulesContact] = useState(props.schedulesContact) const handleCancel = (event, reason) => { @@ -123,9 +153,9 @@ const dateCurrentFormated = () => { alert('Mensagem muito curta!\nMínimo 10 caracteres.') return } - else if((new Date(timerPicker).getHours() > 16 && new Date(timerPicker).getMinutes() > 0) || + else if((new Date(timerPicker).getHours() > 20 && new Date(timerPicker).getMinutes() > 0) || (new Date(timerPicker).getHours() < 7)){ - alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 07:00 e 17:00') + alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 07:00 e 20:00') return } else if(startDate === dateCurrentFormated()){ @@ -138,14 +168,19 @@ const dateCurrentFormated = () => { return } } + + // console.log('NEW DATE: ', formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00') props.func({ 'scheduleId': scheduleId, - 'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`, + // 'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`, + 'schedulingDate': startDate+' '+formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00', 'message': textArea1 }); + + setOpen(false); }; @@ -177,15 +212,18 @@ const textFieldSelect = (data) => { useEffect(()=>{ - if (parseInt(timerPicker.getHours()) > 12 && parseInt(timerPicker.getHours()) < 18){ - setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) + if (parseInt(timerPicker.getHours()) > 11 && parseInt(timerPicker.getHours()) < 18){ + // setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) + setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1))) } else if(parseInt(timerPicker.getHours()) < 12){ - setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) + // setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) + setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1))) } - else if(parseInt(timerPicker.getHours()) > 18){ + else if(parseInt(timerPicker.getHours()) > 17){ - setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) + // setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) + setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1))) } @@ -281,6 +319,93 @@ const handleChange = (event) => { } + + {/* + + Titulo 1 + + + + + + + + + + table name + + + table color + + + table greeting + + + table actions + + + + + <> + {schedulesContact.map((queue) => ( + + {queue.name} + +
+ +
+
+ +
+ + {queue.greetingMessage} + +
+
+ + handleEditQueue(queue)} + > + + + + { + setSelectedQueue(queue); + setConfirmModalOpen(true); + }} + > + + + +
+ ))} + {loading && } + +
+
+
+ +
*/} diff --git a/frontend/src/components/Report/DatePicker/index.js b/frontend/src/components/Report/DatePicker/index.js index ee7e2ee..7f0597c 100644 --- a/frontend/src/components/Report/DatePicker/index.js +++ b/frontend/src/components/Report/DatePicker/index.js @@ -8,6 +8,9 @@ import { KeyboardDatePicker, MuiPickersUtilsProvider, } from '@material-ui/pickers'; + + + import ptBrLocale from "date-fns/locale/pt-BR"; diff --git a/frontend/src/components/Ticket/index.js b/frontend/src/components/Ticket/index.js index 8f74035..da72e66 100644 --- a/frontend/src/components/Ticket/index.js +++ b/frontend/src/components/Ticket/index.js @@ -84,6 +84,7 @@ const Ticket = () => { const [ticket, setTicket] = useState({}); const [schedule, setSchedule] = useState({}) + const [schedulesContact, setSchedulesContact] = useState({}) useEffect(() => { setLoading(true); @@ -98,10 +99,13 @@ const Ticket = () => { // setContact(data.contact); // setTicket(data); + console.log('SCHEDULE CONTACT: ',data.schedulesContact) + setContact(data.contact.contact); setTicket(data.contact); setSchedule(data.schedules) + setSchedulesContact(data.schedulesContact) setLoading(false); } catch (err) { @@ -172,7 +176,7 @@ const Ticket = () => { />
- +
diff --git a/frontend/src/components/TicketActionButtons/index.js b/frontend/src/components/TicketActionButtons/index.js index 9827fab..d2a1ad0 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, schedule, schedulesContact }) => { const classes = useStyles(); const history = useHistory(); const [anchorEl, setAnchorEl] = useState(null); @@ -65,6 +65,7 @@ const TicketActionButtons = ({ ticket, schedule }) => { modal_header={'Finalização de Atendimento'} func={chatEndVal} schedules={schedule} + schedulesContact={schedulesContact} />) };