From 7020d15c70632608a84a6d109976d0010c2fca4f Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 21 Mar 2022 02:06:56 -0300 Subject: [PATCH 1/6] =?UTF-8?q?Adi=C3=A7=C3=A3o=20da=20fun=C3=A7=C3=A3o=20?= =?UTF-8?q?deletar=20para=20os=20lembretes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/SchedulingNotifyController.ts | 28 ++ backend/src/controllers/TicketController.ts | 1 + backend/src/routes/SchedulingNotifyRoutes.ts | 2 + .../ListSchedulingNotifyContactService.ts | 117 ++++- .../components/ChatEnd/ModalChatEnd/index.js | 9 +- .../src/components/Report/DatePicker/index.js | 29 +- .../components/Report/DatePicker2/index.js | 97 ++++ .../src/components/Report/MTable/index.js | 126 +++--- frontend/src/layout/MainListItems.js | 9 +- frontend/src/pages/Report/index.js | 7 +- frontend/src/pages/SchedulesReminder/index.js | 427 ++++++++++++++++++ frontend/src/routes/index.js | 10 +- 12 files changed, 776 insertions(+), 86 deletions(-) create mode 100644 frontend/src/components/Report/DatePicker2/index.js create mode 100644 frontend/src/pages/SchedulesReminder/index.js diff --git a/backend/src/controllers/SchedulingNotifyController.ts b/backend/src/controllers/SchedulingNotifyController.ts index 4185686..7765d00 100644 --- a/backend/src/controllers/SchedulingNotifyController.ts +++ b/backend/src/controllers/SchedulingNotifyController.ts @@ -1,8 +1,35 @@ import { Request, Response } from "express"; +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'); +// const test = await ListSchedulingNotifyContactService('5517988310949'); +// console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$ test:\n', test) + + +type IndexQuery = { + contactNumber: string; + startDate: string; + endDate: string; +}; + + +export const reportScheduleNotifyByDateStartDateEnd = async (req: Request, res: Response): Promise => { + + const { contactNumber, startDate, endDate } = req.query as IndexQuery + + const data_query = await ListSchedulingNotifyContactService(contactNumber, startDate, endDate); + + console.group('DATA QUERY SCHEDULE:\n',data_query) + + return res.status(200).json(data_query); + +}; + export const remove = async ( req: Request, res: Response ): Promise => { console.log('EEEEEEEEEEEEEEEEEEEEEEEEEEE') @@ -13,3 +40,4 @@ export const remove = async ( req: Request, res: Response ): Promise = return res.status(200).send(); }; + diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index d4274d1..ff56802 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -94,6 +94,7 @@ export const show = async (req: Request, res: Response): Promise => { const contact = await ShowTicketService(ticketId); const { schedules, count, hasMore } = await ListScheduleService({ searchParam: "", pageNumber: "1" }); + ////////////////// const schedulesContact = await ListSchedulingNotifyContactService(contact.contact.number); diff --git a/backend/src/routes/SchedulingNotifyRoutes.ts b/backend/src/routes/SchedulingNotifyRoutes.ts index 975b5a1..affa282 100644 --- a/backend/src/routes/SchedulingNotifyRoutes.ts +++ b/backend/src/routes/SchedulingNotifyRoutes.ts @@ -7,4 +7,6 @@ const schedulingNotifiyRoutes = Router(); schedulingNotifiyRoutes.delete("/schedule/:scheduleId", isAuth, SchedulingNotifyController.remove); +schedulingNotifiyRoutes.get("/schedules", isAuth, SchedulingNotifyController.reportScheduleNotifyByDateStartDateEnd); + export default schedulingNotifiyRoutes; diff --git a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts index 2a20ee0..72ba2fe 100644 --- a/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts +++ b/backend/src/services/SchedulingNotifyServices/ListSchedulingNotifyContactService.ts @@ -4,26 +4,127 @@ import SchedulingNotify from "../../models/SchedulingNotify"; import { Op, where, Sequelize } from "sequelize"; import AppError from "../../errors/AppError"; -const ListSchedulingNotifyContactService = async (contactNumber: string): Promise => { +const ListSchedulingNotifyContactService = async (contactNumber: string = '', startDate: string='', endDate: string=''): Promise => { + + let where_clause = {} + let where_clause_notify = {} + + let nameNumber = { + + [Op.or]: [ + { + name: Sequelize.where( + Sequelize.fn("LOWER", Sequelize.col("name")), + "LIKE", + `%${contactNumber.toLowerCase().trim()}%` + ) + }, + { number: { [Op.like]: `%${contactNumber.toLowerCase().trim()}%` } } + ] + + } + + + + + if (contactNumber.trim().length>0 && startDate.trim().length>0 && endDate.trim().length>0){ + + where_clause = nameNumber + + where_clause_notify = { + schedulingTime: { + [Op.gte]: startDate+' 00:00:00.000000', + [Op.lte]: endDate +' 23:59:59.999999' + }, + } + + } + else if (contactNumber.trim().length==0 && startDate.trim().length>0 && endDate.trim().length>0){ + + where_clause = {} + + where_clause_notify = { + schedulingTime: { + [Op.gte]: startDate+' 00:00:00.000000', + [Op.lte]: endDate +' 23:59:59.999999' + }, + } + + } + else if (contactNumber.trim().length==0 && startDate.trim().length>0 && endDate.trim().length==0){ + + where_clause = {} + + where_clause_notify = { + schedulingTime: { + [Op.gte]: startDate+' 00:00:00.000000', + [Op.lte]: startDate +' 23:59:59.999999' + }, + } + + } + else if (contactNumber.trim().length==0 && startDate.trim().length==0 && endDate.trim().length>0){ + + where_clause = {} + + where_clause_notify = { + schedulingTime: { + [Op.gte]: endDate+' 00:00:00.000000', + [Op.lte]: endDate +' 23:59:59.999999' + }, + } + + } + else if (contactNumber.trim().length>0 && startDate.trim().length>0 && endDate.trim().length==0){ + + where_clause = nameNumber + + where_clause_notify = { + schedulingTime: { + [Op.gte]: startDate+' 00:00:00.000000', + [Op.lte]: startDate +' 23:59:59.999999' + }, + } + + } + else if (contactNumber.trim().length>0 && startDate.trim().length==0 && endDate.trim().length>0){ + + where_clause = nameNumber + + where_clause_notify = { + schedulingTime: { + [Op.gte]: endDate+' 00:00:00.000000', + [Op.lte]: endDate +' 23:59:59.999999' + }, + } + + } + else if(contactNumber.trim().length>0){ + + where_clause = nameNumber + + } + const ticket = await SchedulingNotify.findAll({ + + raw: true, + where: where_clause_notify, attributes:['id', [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: [ - { - model: Ticket, + { + model: Ticket, required:true, attributes: [], include: [ { - model: Contact, - where:{ - number: contactNumber, - }, - attributes: ['name', 'number'] + model: Contact, + where: where_clause, + attributes: ['name', 'number', 'profilePicUrl'] }, ] }, diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index 36e71f6..0bb9c34 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -28,7 +28,8 @@ import { } from "@material-ui/core"; import { DeleteOutline } from "@material-ui/icons"; -import { toast } from "react-toastify"; import api from "../../../services/api"; +import { toast } from "react-toastify"; + import api from "../../../services/api"; import toastError from "../../../errors/toastError"; import ConfirmationModal from "../../ConfirmationModal"; @@ -337,7 +338,7 @@ const handleChange = (event) => { - + @@ -351,7 +352,7 @@ const handleChange = (event) => { aria-label="minimum height" minRows={3} value={textArea1} - placeholder={'Mensagem para lembrar cliente'} + placeholder={'Mensagem de envio para cliente'} onChange={ handleChange} style={{ width: '100%' }} /> @@ -375,7 +376,7 @@ const handleChange = (event) => { > Deseja realmente deletar esse Lembrete? - Lembrete + Lembretes diff --git a/frontend/src/components/Report/DatePicker/index.js b/frontend/src/components/Report/DatePicker/index.js index 7f0597c..db4ae5c 100644 --- a/frontend/src/components/Report/DatePicker/index.js +++ b/frontend/src/components/Report/DatePicker/index.js @@ -22,13 +22,28 @@ function formatDateDatePicker(data){ } function ResponsiveDatePickers(props) { - const [selectedDate, handleDateChange] = useState(new Date()); + const [selectedDate, handleDateChange] = useState(props.startEmpty? null : new Date()); + - // props.func(formatDateDatePicker(selectedDate)); + ////////////////////////// + useEffect(() => { + if (props.reset) { + handleDateChange(null) + props.setReset(false) + } + }, [props.reset, props.setReset, props]) + ///////////////////////// useEffect(()=>{ - - props.func(formatDateDatePicker(selectedDate)); + + + if( !selectedDate ){ + props.func(''); + } + else{ + props.func(formatDateDatePicker(selectedDate)); + } + }, [selectedDate, props]) @@ -37,15 +52,17 @@ function ResponsiveDatePickers(props) { handleDateChange(date)} + /> diff --git a/frontend/src/components/Report/DatePicker2/index.js b/frontend/src/components/Report/DatePicker2/index.js new file mode 100644 index 0000000..9002b42 --- /dev/null +++ b/frontend/src/components/Report/DatePicker2/index.js @@ -0,0 +1,97 @@ + + +import React, { Fragment, useState, useEffect } from "react"; + + +import DateFnsUtils from '@date-io/date-fns'; // choose your lib +import { + KeyboardDatePicker, + MuiPickersUtilsProvider, +} from '@material-ui/pickers'; + + + + +import ptBrLocale from "date-fns/locale/pt-BR"; + + +function formatDateDatePicker(data){ + return String(new Date(data).getFullYear())+'-'+ + String(new Date(data).getMonth() + 1).padStart(2,'0')+'-'+ + String(new Date(data).getDate()).padStart(2,'0') +} + +function ResponsiveDatePickers(props) { + const [selectedDate, handleDateChange] = useState(null); + + // props.func(formatDateDatePicker(selectedDate)); + + useEffect(()=>{ + + if( !selectedDate ){ + props.func(''); + } + else{ + props.func(formatDateDatePicker(selectedDate)); + } + + + + }, [selectedDate, props]) + + return ( + + + + handleDateChange(date)} + /> + + + ); +} + +export default ResponsiveDatePickers; + + + + +/*import * as React from 'react'; +import TextField from '@mui/material/TextField'; +import AdapterDateFns from '@mui/lab/AdapterDateFns'; +import LocalizationProvider from '@mui/lab/LocalizationProvider'; +import DesktopDatePicker from '@mui/lab/DesktopDatePicker'; +import Stack from '@mui/material/Stack'; + +const ResponsiveDatePickers = (props) => { + + const [value, setValue] = React.useState(new Date()); + + props.func(value); + + return ( + + + {setValue(newValue)}} + renderInput={(params) => } + /> + + + ); +} + +export default ResponsiveDatePickers*/ \ No newline at end of file diff --git a/frontend/src/components/Report/MTable/index.js b/frontend/src/components/Report/MTable/index.js index a066ab4..fabc0a0 100644 --- a/frontend/src/components/Report/MTable/index.js +++ b/frontend/src/components/Report/MTable/index.js @@ -1,77 +1,81 @@ - -import { useState, useEffect} from 'react'; -import MaterialTable from 'material-table'; -import Modal from '../Modal' + +import { useState, useEffect } from 'react'; +import MaterialTable from 'material-table'; +import Modal from '../Modal' import { render } from '@testing-library/react'; -import React from 'react'; +import React from 'react'; -const MTable = (props) => { - - const [selectedRow, setSelectedRow] = useState(null); +const MTable = (props) => { + + const [selectedRow, setSelectedRow] = useState(null); //const dataLoad = props.data.map((dt) => { return { ...dt }}); - const dataLoad = props.data.map(({user, ...others})=>({...others, 'user': user ? user : {name: 'Aguardando atendente', email:''}})); + const dataLoad = props.data.map(({ user, ...others }) => ({ ...others, 'user': user ? user : { name: 'Aguardando atendente', email: '' } })); + + const columnsLoad = props.columns.map((column) => { return { ...column } }); - const columnsLoad = props.columns.map((column) => { return { ...column }}); - useEffect(() => { - - console.log(`You have clicked the button ${selectedRow} times`) - - },[selectedRow]); - return ( - - { + }, [selectedRow]); - console.log(selectedRow.tableData.id); - console.log(selectedRow); - console.log(selectedRow.messages); - setSelectedRow(selectedRow.tableData.id) + return ( - if(props.hasChild) { - render() - } - - console.log('props.hasChild: ', props.hasChild) + ({ - fontSize: 12, - backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF' - }) - }} - /> - ); + maxWidth={true} + + onRowClick={(evt, selectedRow) => { - }; + if(props.removeClickRow){ + return + } + console.log(selectedRow.tableData.id); + console.log(selectedRow); + console.log(selectedRow.messages); + setSelectedRow(selectedRow.tableData.id) - export default React.memo(MTable) \ No newline at end of file + if (props.hasChild) { + render() + } + + console.log('props.hasChild: ', props.hasChild) + + //evt.stopPropagation() + } + } + + options={{ + search: true, + selection: false, + paging: false, + padding: 'dense', + sorting: true ? props.hasChild : false, + //loadingType: 'linear', + searchFieldStyle: { + width: 300, + }, + + rowStyle: rowData => ({ + fontSize: 12, + backgroundColor: selectedRow === rowData.tableData.id ? '#ec5114' : '#FFF' + }) + }} + /> + ); + +}; + + +export default React.memo(MTable) \ No newline at end of file diff --git a/frontend/src/layout/MainListItems.js b/frontend/src/layout/MainListItems.js index 93613fb..c524b76 100644 --- a/frontend/src/layout/MainListItems.js +++ b/frontend/src/layout/MainListItems.js @@ -9,7 +9,9 @@ import Divider from "@material-ui/core/Divider"; import { Badge } from "@material-ui/core"; import DashboardOutlinedIcon from "@material-ui/icons/DashboardOutlined"; -import ReportOutlinedIcon from "@material-ui/icons/ReportOutlined"; +import ReportOutlinedIcon from "@material-ui/icons/ReportOutlined"; +import SendOutlined from '@material-ui/icons/SendOutlined'; + //import ReportOutlined from "@bit/mui-org.material-ui-icons.report-outlined"; @@ -89,6 +91,11 @@ const MainListItems = (props) => { to="/contacts" primary={i18n.t("mainDrawer.listItems.contacts")} icon={} + /> + } /> { return {'value': obj.id, 'label': obj.name} })}/> - - + + {/* */} @@ -282,7 +282,8 @@ const textFieldSelectUser = (data) => { diff --git a/frontend/src/pages/SchedulesReminder/index.js b/frontend/src/pages/SchedulesReminder/index.js new file mode 100644 index 0000000..b156842 --- /dev/null +++ b/frontend/src/pages/SchedulesReminder/index.js @@ -0,0 +1,427 @@ +import React, { useState, useEffect, useReducer, useContext} from "react"; +import MainContainer from "../../components/MainContainer"; +import api from "../../services/api"; +import SelectField from "../../components/Report/SelectField"; +//import { data } from '../../components/Report/MTable/data'; +import DatePicker1 from '../../components/Report/DatePicker' +import DatePicker2 from '../../components/Report/DatePicker' +//import { Button } from "@material-ui/core"; +import MTable from "../../components/Report/MTable"; +import PropTypes from 'prop-types'; +import Box from '@mui/material/Box'; +import { AuthContext } from "../../context/Auth/AuthContext"; +import { Can } from "../../components/Can"; + +import SearchIcon from "@material-ui/icons/Search"; +import TextField from "@material-ui/core/TextField"; +import InputAdornment from "@material-ui/core/InputAdornment"; +import Button from "@material-ui/core/Button"; + +import MaterialTable from 'material-table'; + +import Delete from '@material-ui/icons/Delete'; +import Edit from '@material-ui/icons/Edit'; +import Save from '@material-ui/icons/Save'; + +import { + IconButton, + Paper, + Table, + TableBody, + TableCell, + TableHead, + TableRow, +} from "@material-ui/core"; + +import { DeleteOutline } from "@material-ui/icons"; +import { toast } from "react-toastify"; +import toastError from "../../errors/toastError"; +import ConfirmationModal from "../../components/ConfirmationModal"; + + + +const reducerQ = (state, action) =>{ + + if(action.type === 'LOAD_QUERY'){ + + console.log('----------------action.payload: ', action.payload) + const queries = action.payload + const newQueries = [] + + queries.forEach((query) => { + + const queryIndex = state.findIndex((q) => q.id === query.id) + + if(queryIndex !== -1){ + state[queryIndex] = query + } + else{ + newQueries.push(query) + } + + }) + + return [...state, ...newQueries] + } + + 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 reducer = (state, action) => { + + if (action.type === "LOAD_USERS") { + const users = action.payload; + const newUsers = []; + + users.forEach((user) => { + const userIndex = state.findIndex((u) => u.id === user.id); + if (userIndex !== -1) { + state[userIndex] = user; + } else { + newUsers.push(user); + } + }); + + return [...state, ...newUsers]; + } + + if (action.type === "RESET") { + return []; + } +}; + + + + +function 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, + ]), +}; + + + +let columnsData = [ + + { 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' }, + + ]; + + + + +const SchedulesReminder = () => { + + const { user: userA } = useContext(AuthContext); + + //-------- + const [searchParam] = useState(""); + //const [loading, setLoading] = useState(false); + //const [hasMore, setHasMore] = useState(false); + const [pageNumber, setPageNumber] = useState(1); + const [users, dispatch] = useReducer(reducer, []); + //const [columns, setColums] = useState([]) + const [startDate, setDatePicker1] = useState(new Date()) + const [endDate, setDatePicker2] = useState(new Date()) + const [userId, setUser] = useState(null) + const [query, dispatchQ] = useReducer(reducerQ, []) + const [contactNumber, setContactNumber] = useState(""); + + const [resetChild, setReset] = useState(false) + + const [selectedSchedule, setSelectedSchedule] = useState(null); + const [confirmModalOpen, setConfirmModalOpen] = useState(false); + const [dataRows, setData] = useState([]); + + + useEffect(() => { + dispatch({ type: "RESET" }); + dispatchQ({ type: "RESET" }) + + setPageNumber(1); + }, [searchParam]); + + useEffect(() => { + //setLoading(true); + + const delayDebounceFn = setTimeout(() => { + + const fetchUsers = async () => { + try { + const { data } = await api.get("/users/", { + params: { searchParam, pageNumber }, + }); + + dispatch({ type: "LOAD_USERS", payload: data.users }); + //setHasMore(data.hasMore); + //setLoading(false); + } catch (err) { + console.log(err); + } + }; + + fetchUsers(); + + }, 500); + return () => clearTimeout(delayDebounceFn); + }, [searchParam, pageNumber]); + + useEffect(() => { + + setData(query) + + }, [query]) + + useEffect(() => { + //setLoading(true); + + const delayDebounceFn = setTimeout(() => { + + const fetchQueries = async () => { + try { + + const dataQuery = await api.get("/schedules/", {params: {contactNumber, startDate, endDate },}); + + dispatchQ({ type: "RESET" }) + dispatchQ({ type: "LOAD_QUERY", payload: dataQuery.data }); + + //setLoading(false); + + } catch (err) { + console.log(err); + } + }; + + fetchQueries(); + + }, 500); + return () => clearTimeout(delayDebounceFn); + + }, [contactNumber, startDate, endDate]); + + +// Get from child 1 +const datePicker1Value = (data) => { + console.log('DATE1: ',(data)); + setDatePicker1(data) +} + +// Get from child 2 +const datePicker2Value = (data) => { + console.log('DATE2: ',(data)); + setDatePicker2(data) +} + +// Get from child 3 +const textFieldSelectUser = (data) => { + console.log('textField: ',data); + setUser(data) +} + +const handleSearch = (event) => { + setContactNumber(event.target.value.toLowerCase()); +}; + +const handleClear = () => { + + setContactNumber('') + + setReset(true) + +} + +const handleCloseConfirmationModal = () => { + setConfirmModalOpen(false); + setSelectedSchedule(null); +}; + + +const handleDeleteRows = (id) => { + + let _data = [...dataRows]; + + _data.forEach(rd => { + _data = _data.filter(t => t.id !== id); + }); + setData(_data); + +}; + + +const handleDeleteSchedule = async (scheduleId) => { + try { + await api.delete(`/schedule/${scheduleId}`); + toast.success(("Lembrete deletado com sucesso!")); + handleDeleteRows(scheduleId) + } catch (err) { + toastError(err); + } + setSelectedSchedule(null); +}; + + return ( + + + + + + + + + + ), + }} + /> + + + {/* + { + return {'value': obj.id, 'label': obj.name} + })}/> + + */} + + + + + + {/* */} + + + + + + + + + + + + + {/* */} + + handleDeleteSchedule(selectedSchedule.id)} + > + Deseja realmente deletar esse Lembrete? + + + console.log("You saved ",rowData) + }, + { + icon: Delete, + tooltip: 'Deletar', + onClick: (event, rowData) => { + console.log("You want to delete ",rowData) + setSelectedSchedule(rowData); + setConfirmModalOpen(true); + } + // onClick: handleDeleteRows + } + ]} + + options={{ + search: true, + selection: false, + paging: false, + padding: 'dense', + sorting: true, + //loadingType: 'linear', + searchFieldStyle: { + width: 300, + }, + + }} + /> + + + + + + + ) + + +}; + +export default SchedulesReminder; diff --git a/frontend/src/routes/index.js b/frontend/src/routes/index.js index f05b0b6..ad0b229 100644 --- a/frontend/src/routes/index.js +++ b/frontend/src/routes/index.js @@ -6,6 +6,7 @@ import LoggedInLayout from "../layout"; import Dashboard from "../pages/Dashboard/"; import Report from "../pages/Report/"; +import SchedulesReminder from "../pages/SchedulesReminder/"; import Tickets from "../pages/Tickets/"; import Signup from "../pages/Signup/"; @@ -19,8 +20,7 @@ import Queues from "../pages/Queues/"; import { AuthProvider } from "../context/Auth/AuthContext"; import { WhatsAppsProvider } from "../context/WhatsApp/WhatsAppsContext"; import Route from "./Route"; - -//import { Report } from "@material-ui/icons"; + //console.log('---AuthProvider: ',AuthProvider) @@ -58,9 +58,13 @@ const Routes = () => { component={Report} isPrivate /> - + + + + + Date: Tue, 22 Mar 2022 23:59:01 -0300 Subject: [PATCH 2/6] =?UTF-8?q?Altera=C3=A7=C3=A3o=20em=20node=20redundant?= =?UTF-8?q?e=20do=20banco=20de=20dados=20Schedules=20e=20altera=C3=A7?= =?UTF-8?q?=C3=A3o=20no=20c=C3=B3digo=20com=20refer=C3=AAncia=20a=20esse?= =?UTF-8?q?=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, From 74c3be6690c0a5a37a364f3665b4e1aeef98c9a7 Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 24 Mar 2022 19:16:31 -0300 Subject: [PATCH 3/6] =?UTF-8?q?Cria=C3=A7=C3=A3o=20do=20Delete=20e=20Updat?= =?UTF-8?q?e=20completo=20do=20recurso=20Lembrete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/SchedulingNotifyController.ts | 30 ++- .../controllers/StatusChatEndController.ts | 12 ++ backend/src/routes/SchedulingNotifyRoutes.ts | 2 + backend/src/routes/index.ts | 5 +- backend/src/routes/statusChatEndRoutes.ts | 10 + .../CreateSchedulingNotifyService.ts | 85 +++++++-- .../components/ChatEnd/ModalChatEnd/index.js | 5 +- .../DatePicker2/index.js | 15 +- .../TimerPickerSelect2/index.js | 93 ++++++++++ .../ModalUpdateScheduleReminder/index.js | 104 +++-------- .../components/Report/SelectField/index.js | 10 +- frontend/src/pages/SchedulesReminder/index.js | 172 +++++++++++------- 12 files changed, 381 insertions(+), 162 deletions(-) create mode 100644 backend/src/controllers/StatusChatEndController.ts create mode 100644 backend/src/routes/statusChatEndRoutes.ts create mode 100644 frontend/src/components/ModalUpdateScheduleReminder/TimerPickerSelect2/index.js diff --git a/backend/src/controllers/SchedulingNotifyController.ts b/backend/src/controllers/SchedulingNotifyController.ts index 921e663..6c490ff 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"; - +import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService"; // const test = await ListSchedulingNotifyContactService('5517988310949','2022-03-18','2022-03-19'); // const test = await ListSchedulingNotifyContactService('','2022-03-18','2022-03-19'); @@ -11,12 +11,17 @@ import ListSchedulingNotifyContactService from "../services/SchedulingNotifySer // console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$ test:\n', test) + + + + type IndexQuery = { contactNumber: string; startDate: string; endDate: string; }; + export const reportScheduleNotifyByDateStartDateEnd = async (req: Request, res: Response): Promise => { @@ -30,6 +35,29 @@ export const reportScheduleNotifyByDateStartDateEnd = async (req: Request, res: }; + +export const createOrUpdateScheduleNotify = async (req: Request, res: Response): Promise => { + + const scheduleData = req.body; + + console.log(' +++++++++++ scheduleData: ', scheduleData) + + const schedulingNotifyCreate = await CreateSchedulingNotifyService( + { + schedulingNotifyId: scheduleData.schedulingNotifyId, + ticketId: scheduleData.ticketId, + statusChatEndId: scheduleData.statusChatEndId, + schedulingDate: scheduleData.schedulingDate, + schedulingTime: scheduleData.schedulingTime, + message: scheduleData.message + } + ) + console.group(':::::::::::::::::: DATA schedulingNotifyCreate:\n',schedulingNotifyCreate) + + return res.status(200).json(schedulingNotifyCreate); + +}; + export const remove = async ( req: Request, res: Response ): Promise => { console.log('EEEEEEEEEEEEEEEEEEEEEEEEEEE') diff --git a/backend/src/controllers/StatusChatEndController.ts b/backend/src/controllers/StatusChatEndController.ts new file mode 100644 index 0000000..a7ee259 --- /dev/null +++ b/backend/src/controllers/StatusChatEndController.ts @@ -0,0 +1,12 @@ +import { Request, Response } from "express"; +import AppError from "../errors/AppError"; + +import ListStatusChatEndService from "../services/StatusChatEndService/ListStatusChatEndService"; + +export const show = async (req: Request, res: Response): Promise => { + + const { statusChatEnd, count, hasMore } = await ListStatusChatEndService({ searchParam: "", pageNumber: "1" }); + + return res.status(200).json(statusChatEnd); +}; + \ No newline at end of file diff --git a/backend/src/routes/SchedulingNotifyRoutes.ts b/backend/src/routes/SchedulingNotifyRoutes.ts index affa282..ab0a203 100644 --- a/backend/src/routes/SchedulingNotifyRoutes.ts +++ b/backend/src/routes/SchedulingNotifyRoutes.ts @@ -7,6 +7,8 @@ const schedulingNotifiyRoutes = Router(); schedulingNotifiyRoutes.delete("/schedule/:scheduleId", isAuth, SchedulingNotifyController.remove); +schedulingNotifiyRoutes.post("/schedule", isAuth, SchedulingNotifyController.createOrUpdateScheduleNotify); + schedulingNotifiyRoutes.get("/schedules", isAuth, SchedulingNotifyController.reportScheduleNotifyByDateStartDateEnd); export default schedulingNotifiyRoutes; diff --git a/backend/src/routes/index.ts b/backend/src/routes/index.ts index 98bcf6b..e52ded1 100644 --- a/backend/src/routes/index.ts +++ b/backend/src/routes/index.ts @@ -12,6 +12,7 @@ import queueRoutes from "./queueRoutes"; import quickAnswerRoutes from "./quickAnswerRoutes"; import reportRoutes from "./reportRoutes"; import schedulingNotifiyRoutes from "./SchedulingNotifyRoutes"; +import statusChatEndRoutes from "./statusChatEndRoutes"; const routes = Router(); @@ -27,8 +28,8 @@ routes.use(whatsappSessionRoutes); routes.use(queueRoutes); routes.use(quickAnswerRoutes); -routes.use(schedulingNotifiyRoutes) +routes.use(schedulingNotifiyRoutes); routes.use(reportRoutes); - +routes.use(statusChatEndRoutes); export default routes; diff --git a/backend/src/routes/statusChatEndRoutes.ts b/backend/src/routes/statusChatEndRoutes.ts new file mode 100644 index 0000000..9eff396 --- /dev/null +++ b/backend/src/routes/statusChatEndRoutes.ts @@ -0,0 +1,10 @@ +import { Router } from "express"; +import isAuth from "../middleware/isAuth"; + +import * as StatusChatEnd from "../controllers/StatusChatEndController"; + +const statusChatEndRoutes = Router(); + +statusChatEndRoutes.get("/statusChatEnd", isAuth, StatusChatEnd.show); + +export default statusChatEndRoutes; \ No newline at end of file diff --git a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts index 76518fb..a06365e 100644 --- a/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts +++ b/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyService.ts @@ -3,27 +3,88 @@ import SchedulingNotify from "../../models/SchedulingNotify"; interface Request { + schedulingNotifyId?: string, ticketId: string, statusChatEndId: string, schedulingDate: string, schedulingTime: string, message: string -} - - -const CreateSchedulingNotifyService = async ({ ticketId, statusChatEndId, schedulingDate, schedulingTime, message }: Request): Promise => { +} - const schedulingNotify = await SchedulingNotify.create( - { - ticketId, - statusChatEndId, - schedulingDate, - schedulingTime, - message + +const CreateSchedulingNotifyService = async ({ + schedulingNotifyId = '', + ticketId, + statusChatEndId, + schedulingDate, + schedulingTime, + message +}: Request): Promise => { + + let schedulingNotify = null; + + if(schedulingNotifyId){ + + console.log('000000000000000000000000000 ATUALIZOU!') - }) + schedulingNotify = await SchedulingNotify.findOne({ where: { id: schedulingNotifyId } }); + + if(schedulingNotify){ + + try{ + + await schedulingNotify.update({ statusChatEndId, schedulingDate, schedulingTime, message}); + + }catch(err){ + + throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404); + + } + + + //await scheduleNotify.reload({attributes: ["id", "name"]}); + } + + } + + if(!schedulingNotify){ + + console.log('111111111111111111111111111 criou!') + + schedulingNotify = await SchedulingNotify.create( + { + ticketId, + statusChatEndId, + schedulingDate, + schedulingTime, + message + + }) + + } + return schedulingNotify } + + + + + +// const CreateSchedulingNotifyService = async ({ ticketId, statusChatEndId, schedulingDate, schedulingTime, message }: Request): Promise => { + +// const schedulingNotify = await SchedulingNotify.create( +// { +// ticketId, +// statusChatEndId, +// schedulingDate, +// schedulingTime, +// message + +// }) + +// return schedulingNotify +// } + export default CreateSchedulingNotifyService \ 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 3851d2f..1f76e06 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -318,6 +318,7 @@ const handleChange = (event) => { { return {'value': obj.id, 'label': obj.name} @@ -360,7 +361,7 @@ const handleChange = (event) => { } - {schedulesContact.length>0 && + {/* {schedulesContact.length>0 && @@ -423,7 +424,7 @@ const handleChange = (event) => { - } + } */} diff --git a/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js index 9002b42..9de3619 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js @@ -21,12 +21,21 @@ function formatDateDatePicker(data){ String(new Date(data).getDate()).padStart(2,'0') } + +function formatDate(strDate){ + const date = strDate.split(' ')[0].split('/') + const time = strDate.split(' ')[1] + return `${date[2]}-${date[1]}-${date[0]} ${time}` +} + + function ResponsiveDatePickers(props) { - const [selectedDate, handleDateChange] = useState(null); - // props.func(formatDateDatePicker(selectedDate)); + console.log('schedulingDate schedulingDate schedulingDate: ', formatDate(props.schedulingDate)) - useEffect(()=>{ + const [selectedDate, handleDateChange] = useState(new Date(formatDate(props.schedulingDate))); + + useEffect(()=>{ if( !selectedDate ){ props.func(''); diff --git a/frontend/src/components/ModalUpdateScheduleReminder/TimerPickerSelect2/index.js b/frontend/src/components/ModalUpdateScheduleReminder/TimerPickerSelect2/index.js new file mode 100644 index 0000000..f02731d --- /dev/null +++ b/frontend/src/components/ModalUpdateScheduleReminder/TimerPickerSelect2/index.js @@ -0,0 +1,93 @@ + + + +// import React, { useState } from "react"; +// import { DateTimePicker, KeyboardDateTimePicker } from "@material-ui/pickers"; + +// function InlineDateTimePickerDemo(props) { +// const [selectedDate, handleDateChange] = useState(new Date("2018-01-01T00:00:00.000Z")); + +// return ( +// <> +// + +// +// +// ); +// } + +// export default InlineDateTimePickerDemo; + + + +import React, { Fragment, useState, useEffect } from "react"; +// import TextField from '@mui/material/TextField'; +import DateFnsUtils from '@date-io/date-fns'; + +import { + TimePicker, + MuiPickersUtilsProvider, +} from '@material-ui/pickers'; + + +import ptBrLocale from "date-fns/locale/pt-BR"; + + +function formatDate(strDate){ + const date = strDate.split(' ')[0].split('/') + const time = strDate.split(' ')[1] + return `${date[2]}-${date[1]}-${date[0]} ${time}` +} + + +const ResponsiveTimePickers = (props) => { + + const [value, setValue] = useState(new Date(new Date(formatDate(props.schedulingDate)))); + + // props.func(value); + + useEffect(()=>{ + + props.func(value); + + }, [value, props]) + + return ( + + + + + { + setValue(newValue); + }} + // Ativar se necessario + // renderInput={(params) => } + + /> + + + + + ); +} + +export default ResponsiveTimePickers diff --git a/frontend/src/components/ModalUpdateScheduleReminder/index.js b/frontend/src/components/ModalUpdateScheduleReminder/index.js index 4b36f61..865689e 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/index.js @@ -11,7 +11,7 @@ import Box from '@mui/material/Box'; import SelectField from "../Report/SelectField"; import DatePicker from './DatePicker2' -import TimerPickerSelect from '../ChatEnd/TimerPickerSelect' +import TimerPickerSelect from './TimerPickerSelect2' import TextareaAutosize from '@mui/material/TextareaAutosize'; // import { subHours } from "date-fns"; @@ -112,9 +112,9 @@ const Modal = (props) => { 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 [startDate, setDatePicker] = useState(props.rowData.schedulingTime ? new Date(props.rowData.schedulingTime) : new Date()) const [timerPicker, setTimerPicker] = useState(new Date()) - const [textArea1, setTextArea1] = useState() + const [textArea1, setTextArea1] = useState(props.rowData.message) const [schedulesContact, dispatch] = useReducer(reducer, []); @@ -135,7 +135,7 @@ const Modal = (props) => { (async () => { try { - const { data } = await api.get("/tickets/" + props.ticketId); + const { data } = await api.get("/tickets/" + props.rowData.ticketId); dispatch({ type: "LOAD_SCHEDULES", payload: data.schedulesContact }); @@ -233,15 +233,30 @@ const timerPickerValue = (data) => { } 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`)), 'message': textArea1 } + + const formatDateTimeBrazil = (dateTime) => { + let date = dateTime.split(' ')[0] + let time = dateTime.split(' ')[1] + date = date.split('-') + 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.func(dataSendServer) + props.func(dataSendServer, props.rowData) setOpen(false); }; @@ -317,6 +332,7 @@ const handleChange = (event) => { { return {'value': obj.id, 'label': obj.name} @@ -337,12 +353,17 @@ const handleChange = (event) => { - + + + @@ -365,72 +386,7 @@ const handleChange = (event) => { } - - {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); - - }} - > - - - - - - ))} - - -
-
-
} - + diff --git a/frontend/src/components/Report/SelectField/index.js b/frontend/src/components/Report/SelectField/index.js index 5dd4cdc..df5dec5 100644 --- a/frontend/src/components/Report/SelectField/index.js +++ b/frontend/src/components/Report/SelectField/index.js @@ -7,9 +7,15 @@ import TextField from '@mui/material/TextField'; const SelectTextFields = (props) => { - const [currency, setCurrency] = useState(props.emptyField ? '0' : '1'); + // const [currency, setCurrency] = useState(props.emptyField ? '0' : '1'); - if(props.emptyField){ + console.log(':::::::::::::::::::::: props.textBoxFieldSelected: ', props.textBoxFieldSelected) + + const [currency, setCurrency] = useState(props.textBoxFieldSelected ? props.textBoxFieldSelected: '0'); + + // const [currency, setCurrency] = useState(props.textBoxFieldSelected); + + if(!props.textBoxFieldSelected){ props.currencies.push({ 'value': 0, 'label': ''}) } diff --git a/frontend/src/pages/SchedulesReminder/index.js b/frontend/src/pages/SchedulesReminder/index.js index 1f03d1d..547193b 100644 --- a/frontend/src/pages/SchedulesReminder/index.js +++ b/frontend/src/pages/SchedulesReminder/index.js @@ -90,28 +90,28 @@ const reducerQ = (state, action) =>{ -const reducer = (state, action) => { +// const reducer = (state, action) => { - if (action.type === "LOAD_SCHEDULES") { - const users = action.payload; - const newUsers = []; +// if (action.type === "LOAD_STATUS_CHAT_END") { +// const users = action.payload; +// const newUsers = []; - users.forEach((user) => { - const userIndex = state.findIndex((u) => u.id === user.id); - if (userIndex !== -1) { - state[userIndex] = user; - } else { - newUsers.push(user); - } - }); +// users.forEach((user) => { +// const userIndex = state.findIndex((u) => u.id === user.id); +// if (userIndex !== -1) { +// state[userIndex] = user; +// } else { +// newUsers.push(user); +// } +// }); - return [...state, ...newUsers]; - } +// return [...state, ...newUsers]; +// } - if (action.type === "RESET") { - return []; - } -}; +// if (action.type === "RESET") { +// return []; +// } +// }; @@ -150,17 +150,17 @@ Item.propTypes = { -let columnsData = [ +// let columnsData = [ - { title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => }, +// { 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: 'Nome', field: 'ticket.contact.name' }, +// { title: 'Contato', field: 'ticket.contact.number' }, +// { title: 'schedulingTime', field: 'schedulingTime' }, +// { title: 'schedulingDate', field: 'schedulingDate' }, +// { title: 'message', field: 'message' }, - ]; +// ]; @@ -171,10 +171,10 @@ const SchedulesReminder = () => { //-------- const [searchParam] = useState(""); - //const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(null); //const [hasMore, setHasMore] = useState(false); const [pageNumber, setPageNumber] = useState(1); - const [users, dispatch] = useReducer(reducer, []); + // const [users, dispatch] = useReducer(reducer, []); //const [columns, setColums] = useState([]) const [startDate, setDatePicker1] = useState(new Date()) const [endDate, setDatePicker2] = useState(new Date()) @@ -192,45 +192,47 @@ const SchedulesReminder = () => { useEffect(() => { - dispatch({ type: "RESET" }); + // dispatch({ type: "RESET" }); dispatchQ({ type: "RESET" }) setPageNumber(1); }, [searchParam]); + + //natalia useEffect(() => { - //setLoading(true); + // setLoading(true); const delayDebounceFn = setTimeout(() => { - const fetchUsers = async () => { + const fetchStatusChatEnd = async () => { try { - const { data } = await api.get("/users/", { + const statusChatEndLoad = await api.get("/statusChatEnd", { params: { searchParam, pageNumber }, }); - dispatch({ type: "LOAD_SCHEDULES", payload: data.users }); + // dispatch({ type: "LOAD_STATUS_CHAT_END", payload: statusChatEndLoad.data }); + + console.log(':::::::::::::: statusChatEndLoad: ', statusChatEndLoad.data) + + setStatusEndChat(statusChatEndLoad.data) //setHasMore(data.hasMore); - //setLoading(false); + // setLoading(false); } catch (err) { console.log(err); } }; - fetchUsers(); + fetchStatusChatEnd(); }, 500); return () => clearTimeout(delayDebounceFn); }, [searchParam, pageNumber]); - useEffect(() => { - setData(query) - - }, [query]) useEffect(() => { - //setLoading(true); + setLoading(true); const delayDebounceFn = setTimeout(() => { @@ -241,10 +243,7 @@ const SchedulesReminder = () => { dispatchQ({ type: "RESET" }) dispatchQ({ type: "LOAD_QUERY", payload: dataQuery.data }); - - // setStatusEndChat(dataQuery.data.statusEndChat) - - //setLoading(false); + setLoading(false); } catch (err) { console.log(err); @@ -257,6 +256,17 @@ const SchedulesReminder = () => { return () => clearTimeout(delayDebounceFn); }, [contactNumber, startDate, endDate]); + + + + useEffect(() => { + + if(!loading){ + console.log('carregando table...') + setData(query) + } + + }, [loading]) // Get from child 1 @@ -291,6 +301,7 @@ const handleClear = () => { const handleCloseConfirmationModal = () => { setConfirmModalOpen(false); + console.log('cancelou NULL 1') setSelectedSchedule(null); }; @@ -315,22 +326,45 @@ const handleDeleteSchedule = async (scheduleId) => { } catch (err) { toastError(err); } + console.log('cancelou NULL 2') + setSelectedSchedule(null); +}; + + + +const handleUpdateSchedule = async (scheduleData, rowsDataNew) => { + try { + await api.post("/schedule", scheduleData); + toast.success(("Lembrete atualizado com sucesso!")); + ////////////////// + + const dataUpdate = [...dataRows]; + const index = rowsDataNew.tableData['id']; + dataUpdate[index] = rowsDataNew; + setData([...dataUpdate]); + + ///////////////// + + + } catch (err) { + toastError(err); + } + //console.log('cancelou NULL 3') setSelectedSchedule(null); }; -const chatEndVal = (data) => { +const chatEndVal = (data, rowsDataNew) => { if(data){ console.log('DATA SCHECULE: ', data) + + console.log(':::::::::::::::::::: ChatEnd2: ',(data)); + console.log(':::::::::::::::::::: Rows data fro child: ',(rowsDataNew)); - // data = {...data, 'ticketId': ticket.id} + handleUpdateSchedule(data, rowsDataNew) - // console.log('ChatEnd: ',(data)); - - // handleUpdateTicketStatus(null, "closed", user?.id, data) - } } @@ -341,12 +375,9 @@ const handleModal = (rowData) => { render() }; @@ -403,13 +434,8 @@ const handleModal = (rowData) => { display: 'grid', }}> - - - {/* */} + + { }, + + { title: 'Nome', field: 'ticket.contact.name' }, + { title: 'Contato', field: 'ticket.contact.number' }, + { title: 'schedulingTime', field: 'schedulingTime' }, + { title: 'schedulingDate', field: 'schedulingDate' }, + { title: 'message', field: 'message' }, + + ] + } data={dataRows} // icons={tableIcons} @@ -431,9 +469,11 @@ const handleModal = (rowData) => { icon: Edit, tooltip: 'Editar', onClick: (event, rowData) => { - console.log("You saved ",rowData) - handleModal(rowData) + console.log("You want edit data ",rowData) + setSelectedSchedule(rowData); + handleModal(rowData) } + }, { icon: Delete, From 682bfc11168e995d09cf4553c66368b36cf69876 Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 28 Mar 2022 16:28:35 -0300 Subject: [PATCH 4/6] =?UTF-8?q?Cria=C3=A7=C3=A3o=20do=20lembrete=20e=20age?= =?UTF-8?q?ndamento=20completo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/controllers/TicketController.ts | 18 +- .../helpers/CheckSchedulingReminderNotify.ts | 11 + .../CreateSchedulingNotifyService.ts | 2 +- .../ListSchedulingNotifyContactService.ts | 12 +- .../ListSchedulingNotifyService.ts | 6 +- .../components/ChatEnd/ModalChatEnd/index.js | 272 +++++++++++++++-- .../DatePicker2/index.js | 1 + .../ModalUpdateScheduleReminder/index.js | 288 ++++++++++++++++-- frontend/src/pages/SchedulesReminder/index.js | 53 +++- 9 files changed, 580 insertions(+), 83 deletions(-) create mode 100644 backend/src/helpers/CheckSchedulingReminderNotify.ts 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, + } }} /> From a36e05992b4974ebfa305bbde8ac27039e9b89d7 Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 29 Mar 2022 18:32:48 -0300 Subject: [PATCH 5/6] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20da=20remo=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20agendamento/lembrete=20pelo=20socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/SchedulingNotifyController.ts | 7 +- .../CreateSchedulingNotifyService.ts | 2 +- .../DeleteSchedulingNotifyService.ts | 7 ++ .../ListSchedulingNotifyContactService.ts | 2 + .../components/ChatEnd/ModalChatEnd/index.js | 12 +-- .../ModalUpdateScheduleReminder/index.js | 11 +-- .../src/components/Report/MTable/index.js | 7 ++ frontend/src/pages/SchedulesReminder/index.js | 96 +++++++++++++++++-- 8 files changed, 119 insertions(+), 25 deletions(-) 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, } From 56fccf84146902e4cf44c27f4f093bb002a75d3f Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 30 Mar 2022 11:09:20 -0300 Subject: [PATCH 6/6] =?UTF-8?q?Finaliza=C3=A7=C3=A3o=20da=20funcionalidade?= =?UTF-8?q?=20de=20lembrete/agendameto=20com=20remo=C3=A7=C3=A3o=20das=20v?= =?UTF-8?q?ari=C3=A1veis=20n=C3=A3o=20usadas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ChatEnd/ModalChatEnd/index.js | 116 +++----------- .../DatePicker2/index.js | 4 +- .../ModalUpdateScheduleReminder/index.js | 145 +++++++++--------- .../components/Report/SelectField/index.js | 2 +- frontend/src/pages/Report/index.js | 8 +- frontend/src/pages/SchedulesReminder/index.js | 127 ++++++--------- 6 files changed, 144 insertions(+), 258 deletions(-) diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index 4fe240a..b6edf6d 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -13,27 +13,14 @@ import DatePicker from '../../Report/DatePicker' import TimerPickerSelect from '../TimerPickerSelect' import TextareaAutosize from '@mui/material/TextareaAutosize'; -import { subHours, addDays, isEqual, subDays} from "date-fns"; +import { subHours, addDays, subDays} from "date-fns"; import TextFieldSelectHourBefore from '@mui/material/TextField'; import MenuItem from '@mui/material/MenuItem'; - -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"; +import toastError from "../../../errors/toastError"; const reducer = (state, action) => { @@ -109,8 +96,7 @@ Item.propTypes = { const Modal = (props) => { // const [clientSchedules, dispatch] = useReducer(reducer, []); - const [selectedSchedule, setSelectedSchedule] = useState(null); - const [confirmModalOpen, setConfirmModalOpen] = useState(false); + // const [selectedSchedule, setSelectedSchedule] = useState(null); const [open, setOpen] = useState(true); const [scroll, /*setScroll*/] = useState('body'); const [statusChatEndId, setStatusChatEnd] = useState(null) @@ -161,23 +147,18 @@ const Modal = (props) => { } + - const handleCloseConfirmationModal = () => { - setConfirmModalOpen(false); - setSelectedSchedule(null); - }; - - - const handleDeleteSchedule = async (scheduleId) => { - try { - await api.delete(`/schedule/${scheduleId}`); - toast.success(("Lembrete/Agendamento deletado com sucesso!")); - dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); - } catch (err) { - toastError(err); - } - setSelectedSchedule(null); - }; + // const handleDeleteSchedule = async (scheduleId) => { + // try { + // await api.delete(`/schedule/${scheduleId}`); + // toast.success(("Lembrete/Agendamento deletado com sucesso!")); + // dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); + // } catch (err) { + // toastError(err); + // } + // setSelectedSchedule(null); + // }; // Get from child 2 const datePickerValue = (data) => { @@ -225,7 +206,7 @@ const timerPickerValue = (data) => { console.log('Entrou! textArea1: ', textArea1) - if( startDate.trim().length==0){ + if( startDate.trim().length === 0){ alert('Selecione uma data atual ou futura!') @@ -579,70 +560,9 @@ const handleChangeHourBefore = (event) => { } - {/* {schedulesContact.length>0 && - - - - - - 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); - - }} - > - - - - - - ))} - - -
-
-
} */} + {schedulesContact.length>0 && +
+ } diff --git a/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js index 54f3538..a4e953e 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/DatePicker2/index.js @@ -30,9 +30,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 bf02e94..cdca7f2 100644 --- a/frontend/src/components/ModalUpdateScheduleReminder/index.js +++ b/frontend/src/components/ModalUpdateScheduleReminder/index.js @@ -14,30 +14,17 @@ import DatePicker from './DatePicker2' import TimerPickerSelect from './TimerPickerSelect2' import TextareaAutosize from '@mui/material/TextareaAutosize'; -import { subHours, addDays, isEqual, subDays} from "date-fns"; +import { subHours, addDays, subDays} from "date-fns"; import TextFieldSelectHourBefore from '@mui/material/TextField'; import MenuItem from '@mui/material/MenuItem'; - - -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"; +import toastError from "../../errors/toastError"; + const reducer = (state, action) => { @@ -111,8 +98,8 @@ Item.propTypes = { const Modal = (props) => { - const [selectedSchedule, setSelectedSchedule] = useState(null); - const [confirmModalOpen, setConfirmModalOpen] = useState(false); + // const [selectedSchedule, setSelectedSchedule] = useState(null); + // const [confirmModalOpen, setConfirmModalOpen] = useState(false); const [open, setOpen] = useState(true); const [scroll, /*setScroll*/] = useState('body'); @@ -124,11 +111,11 @@ const Modal = (props) => { const [currencyHourBefore, setCurrency] = useState(props.rowData.schedulingTime.split(' ')[1].slice(0,5)); const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null); - const [contador, setCount] = useState(0) - - - + const [currencyHourBeforeAux, ] = useState(props.rowData.schedulingTime.split(' ')[1].slice(0,5)); + + if(schedulesContact){} + const handleCancel = (event, reason) => { @@ -170,26 +157,26 @@ const Modal = (props) => { - const handleCloseConfirmationModal = () => { - setConfirmModalOpen(false); - setSelectedSchedule(null); - }; + // const handleCloseConfirmationModal = () => { + // setConfirmModalOpen(false); + // setSelectedSchedule(null); + // }; - const handleDeleteSchedule = async (scheduleId) => { - try { - await api.delete(`/schedule/${scheduleId}`); - toast.success(("Lembrete/Agendamento deletado com sucesso!")); - dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); - } catch (err) { - toastError(err); - } - setSelectedSchedule(null); - }; + // const handleDeleteSchedule = async (scheduleId) => { + // try { + // await api.delete(`/schedule/${scheduleId}`); + // toast.success(("Lembrete/Agendamento 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) @@ -197,7 +184,7 @@ const datePickerValue = (data) => { // Get from child 3 const timerPickerValue = (data) => { - console.log('timerPickerValue: ',(data)); + setTimerPicker(data) @@ -235,7 +222,7 @@ const dateCurrentFormated = (dateF=null) => { if (statusChatEndId === '2'|| statusChatEndId === '3'){ - console.log('Entrou! textArea1: ', textArea1) + if(textArea1 && textArea1.trim().length<5){ @@ -278,18 +265,17 @@ const dateCurrentFormated = (dateF=null) => { 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 (statusChatEndId === '2'){ + } @@ -327,8 +313,19 @@ const dateCurrentFormated = (dateF=null) => { useEffect(()=>{ + + const selectedTimeOld = (_hours) => { - setCount(contador+1) + let selectedOld = _hours.filter((h)=>(h.value===currencyHourBeforeAux))[0] + + if(selectedOld){ + + return selectedOld + } + + return null + + } const hoursBeforeAvalible = (timer) =>{ @@ -338,25 +335,24 @@ const dateCurrentFormated = (dateF=null) => { 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))) - + subHours(timer, hour).getHours()<=20){ + hours.push({value: formatedTimeHour(subHours(timer,hour)), label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`}) hour++; } if(hours.length>1){ - hours.pop() + hours.pop() - if(contador>1) - setCurrency( hours[0].value) + let selectedOld = selectedTimeOld(hours) + setCurrency(selectedOld ? selectedOld.value : hours[0].value) + } else{ setCurrency(null) @@ -365,9 +361,7 @@ const dateCurrentFormated = (dateF=null) => { } else{ - while(subHours(timer, hour).getHours()>=6 && subHours(timer, hour).getHours()<=20){ - - console.log('******** another day TIMER: ', formatedTimeHour(subHours(timer,hour))) + while(subHours(timer, hour).getHours()>=6 && subHours(timer, hour).getHours()<=20){ hours.push( {value: formatedTimeHour(subHours(timer,hour)), @@ -377,9 +371,13 @@ const dateCurrentFormated = (dateF=null) => { } if(hours.length>0){ + - if(contador>1) - setCurrency( hours[0].value) + let selectedOld = selectedTimeOld(hours) + setCurrency(selectedOld ? selectedOld.value : hours[0].value) + + //if(contador>1) + // setCurrency( hours[0].value) } else{ setCurrency(null) @@ -390,21 +388,21 @@ const dateCurrentFormated = (dateF=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)))) - + hours.push({value: formatedTimeHour(timerPicker) , label: `24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO`}) + + let selectedOld = selectedTimeOld(hours) + + if(selectedOld) + setCurrency(selectedOld.value) } return {time: hours, hour:hour} - } - - console.log('CONTADOR 1: ', contador) - + } + setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker).time) - },[timerPicker, startDate]) + },[timerPicker, startDate, currencyHourBeforeAux]) @@ -423,7 +421,7 @@ const dateCurrentFormated = (dateF=null) => { // Get from child 1 const textFieldSelect = (data) => { - console.log('textFieldSelect: ',data); + setStatusChatEnd(data) } @@ -440,8 +438,7 @@ const handleChange = (event) => { const handleChangeHourBefore = (event) => { setCurrency(event.target.value); - - console.log('CONTADOR 2: ', contador) + }; @@ -557,14 +554,14 @@ const handleChangeHourBefore = (event) => { func={datePickerValue} minDate={true} schedulingDate={props.rowData.schedulingDate} - title={'Data do lembrete'}/> + title={'Data'}/>
+ title={'Hora'}/> diff --git a/frontend/src/components/Report/SelectField/index.js b/frontend/src/components/Report/SelectField/index.js index df5dec5..a234526 100644 --- a/frontend/src/components/Report/SelectField/index.js +++ b/frontend/src/components/Report/SelectField/index.js @@ -9,7 +9,7 @@ const SelectTextFields = (props) => { // const [currency, setCurrency] = useState(props.emptyField ? '0' : '1'); - console.log(':::::::::::::::::::::: props.textBoxFieldSelected: ', props.textBoxFieldSelected) + const [currency, setCurrency] = useState(props.textBoxFieldSelected ? props.textBoxFieldSelected: '0'); diff --git a/frontend/src/pages/Report/index.js b/frontend/src/pages/Report/index.js index a8de521..1af6439 100644 --- a/frontend/src/pages/Report/index.js +++ b/frontend/src/pages/Report/index.js @@ -17,7 +17,7 @@ const reducerQ = (state, action) =>{ if(action.type === 'LOAD_QUERY'){ - console.log('----------------action.payload: ', action.payload) + const queries = action.payload const newQueries = [] @@ -234,19 +234,19 @@ const Report = () => { // Get from child 1 const datePicker1Value = (data) => { - console.log('DATE1: ',(data)); + setDatePicker1(data) } // Get from child 2 const datePicker2Value = (data) => { - console.log('DATE2: ',(data)); + setDatePicker2(data) } // Get from child 3 const textFieldSelectUser = (data) => { - console.log('textField: ',data); + setUser(data) } diff --git a/frontend/src/pages/SchedulesReminder/index.js b/frontend/src/pages/SchedulesReminder/index.js index 5dfb69d..90e7af9 100644 --- a/frontend/src/pages/SchedulesReminder/index.js +++ b/frontend/src/pages/SchedulesReminder/index.js @@ -1,16 +1,16 @@ -import React, { useState, useEffect, useReducer, useContext} from "react"; +import React, { useState, useEffect, useReducer} from "react"; import MainContainer from "../../components/MainContainer"; import api from "../../services/api"; -import SelectField from "../../components/Report/SelectField"; + //import { data } from '../../components/Report/MTable/data'; import DatePicker1 from '../../components/Report/DatePicker' import DatePicker2 from '../../components/Report/DatePicker' //import { Button } from "@material-ui/core"; -import MTable from "../../components/Report/MTable"; + import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; -import { AuthContext } from "../../context/Auth/AuthContext"; -import { Can } from "../../components/Can"; + + import SearchIcon from "@material-ui/icons/Search"; import TextField from "@material-ui/core/TextField"; @@ -20,29 +20,19 @@ import Button from "@material-ui/core/Button"; import MaterialTable from 'material-table'; import Delete from '@material-ui/icons/Delete'; -import Edit from '@material-ui/icons/Edit'; -import Save from '@material-ui/icons/Save'; +import Edit from '@material-ui/icons/Edit'; -import Dialog from '@mui/material/Dialog'; + import { render } from '@testing-library/react'; // import Modal from "../../../..ChatEnd/ModalChatEnd"; import Modal from "../../components/ModalUpdateScheduleReminder"; import openSocket from "socket.io-client"; - - -import { - IconButton, - Paper, - Table, - TableBody, - TableCell, - TableHead, - TableRow, -} from "@material-ui/core"; -import { DeleteOutline } from "@material-ui/icons"; + + + import { toast } from "react-toastify"; import toastError from "../../errors/toastError"; import ConfirmationModal from "../../components/ConfirmationModal"; @@ -53,7 +43,7 @@ const reducerQ = (state, action) =>{ if(action.type === 'LOAD_QUERY'){ - console.log('----------------action.payload: ', action.payload) + const queries = action.payload const newQueries = [] @@ -80,7 +70,7 @@ const reducerQ = (state, action) =>{ // 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; @@ -95,7 +85,7 @@ const reducerQ = (state, action) =>{ const scheduleId = action.payload; const scheduleIndex = state.findIndex((u) => u.id === scheduleId); - console.log('**************** scheduleIndex: ', scheduleIndex) + if (scheduleIndex !== -1) { state.splice(scheduleIndex, 1); } @@ -199,7 +189,7 @@ Item.propTypes = { const SchedulesReminder = () => { - const { user: userA } = useContext(AuthContext); + //-------- const [searchParam] = useState(""); @@ -210,7 +200,7 @@ const SchedulesReminder = () => { //const [columns, setColums] = useState([]) const [startDate, setDatePicker1] = useState(new Date()) const [endDate, setDatePicker2] = useState(new Date()) - const [userId, setUser] = useState(null) + const [query, dispatchQ] = useReducer(reducerQ, []) const [contactNumber, setContactNumber] = useState(""); @@ -231,19 +221,19 @@ const SchedulesReminder = () => { 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) } @@ -281,10 +271,14 @@ const SchedulesReminder = () => { // dispatch({ type: "LOAD_STATUS_CHAT_END", payload: statusChatEndLoad.data }); - console.log(':::::::::::::: statusChatEndLoad: ', statusChatEndLoad.data) + - setStatusEndChat(statusChatEndLoad.data.filter(status => (status.id == '2' || status.id == '3'))) + // setStatusEndChat(statusChatEndLoad.data.filter(status => (status.id == '2' || status.id == '3'))) + + setStatusEndChat(statusChatEndLoad.data.filter(status => (`${status.id}` === '2' || `${status.id}` === '3'))) + + //setHasMore(data.hasMore); // setLoading(false); } catch (err) { @@ -331,41 +325,30 @@ const SchedulesReminder = () => { useEffect(() => { if(!loading){ - console.log('carregando table...') - // 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' } + { ...others, 'scheduleReminder': `${others.statusChatEndId}` === '3' ? 'Agendamento' : 'Lembrete' } ))) } - }, [loading]) + }, [loading, query]) // Get from child 1 const datePicker1Value = (data) => { - console.log('DATE1: ',(data)); + setDatePicker1(data) } // Get from child 2 const datePicker2Value = (data) => { - console.log('DATE2: ',(data)); + setDatePicker2(data) } -// Get from child 3 -const textFieldSelectUser = (data) => { - console.log('textField: ',data); - setUser(data) -} + const handleSearch = (event) => { setContactNumber(event.target.value.toLowerCase()); @@ -381,21 +364,21 @@ const handleClear = () => { const handleCloseConfirmationModal = () => { setConfirmModalOpen(false); - console.log('cancelou NULL 1') + setSelectedSchedule(null); }; -const handleDeleteRows = (id) => { +// const handleDeleteRows = (id) => { - let _data = [...dataRows]; +// let _data = [...dataRows]; - _data.forEach(rd => { - _data = _data.filter(t => t.id !== id); - }); - setData(_data); +// _data.forEach(rd => { +// _data = _data.filter(t => t.id !== id); +// }); +// setData(_data); -}; +// }; const handleDeleteSchedule = async (scheduleId) => { @@ -406,7 +389,7 @@ const handleDeleteSchedule = async (scheduleId) => { } catch (err) { toastError(err); } - console.log('cancelou NULL 2') + setSelectedSchedule(null); }; @@ -424,7 +407,7 @@ const handleUpdateSchedule = async (scheduleData, rowsDataNew) => { dataUpdate[index] = rowsDataNew; setData([...dataUpdate].map(({ scheduleReminder, ...others }) => ( - { ...others, 'scheduleReminder': others.statusChatEndId == '3' ? 'Agendamento' : 'Lembrete' } + { ...others, 'scheduleReminder': `${others.statusChatEndId}` === '3' ? 'Agendamento' : 'Lembrete' } ))); @@ -436,7 +419,7 @@ const handleUpdateSchedule = async (scheduleData, rowsDataNew) => { } catch (err) { toastError(err); } - //console.log('cancelou NULL 3') + // setSelectedSchedule(null); }; @@ -445,10 +428,10 @@ const chatEndVal = (data, rowsDataNew) => { if(data){ - console.log('DATA SCHECULE: ', data) + - console.log(':::::::::::::::::::: ChatEnd2: ',(data)); - console.log(':::::::::::::::::::: Rows data fro child: ',(rowsDataNew)); + + handleUpdateSchedule(data, rowsDataNew) @@ -493,12 +476,7 @@ const handleModal = (rowData) => { /> - {/* - { - return {'value': obj.id, 'label': obj.name} - })}/> - - */} + @@ -527,7 +505,7 @@ const handleModal = (rowData) => { handleDeleteSchedule(selectedSchedule.id)} @@ -540,7 +518,7 @@ const handleModal = (rowData) => { columns={ [ - { title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => }, + { title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => imagem de perfil do whatsapp }, { title: 'Nome', field: 'ticket.contact.name' }, { title: 'Contato', field: 'ticket.contact.number' }, { title: 'Lemb/Agen', field: 'scheduleReminder'}, @@ -558,7 +536,7 @@ const handleModal = (rowData) => { icon: Edit, tooltip: 'Editar', onClick: (event, rowData) => { - console.log("You want edit data ",rowData) + setSelectedSchedule(rowData); handleModal(rowData) } @@ -568,7 +546,7 @@ const handleModal = (rowData) => { icon: Delete, tooltip: 'Deletar', onClick: (event, rowData) => { - console.log("You want to delete ",rowData) + setSelectedSchedule(rowData); setConfirmModalOpen(true); } @@ -588,13 +566,6 @@ const handleModal = (rowData) => { width: 300, }, - pageSize: 20, - headerStyle: { - position: "sticky", - top: "0" - }, - maxBodyHeight: "400px", - rowStyle: { fontSize: 12, }