Alteração do horário comercial para té às 20

pull/1/head
adriano 2022-03-10 08:24:10 -03:00
parent bc79a29f21
commit d0be6729fe
8 changed files with 207 additions and 23 deletions

View File

@ -37,7 +37,7 @@
"sequelize-cli": "^5.5.1",
"sequelize-typescript": "^1.1.0",
"socket.io": "^3.0.5",
"whatsapp-web.js": "^1.15.5",
"whatsapp-web.js": "^1.15.6",
"yup": "^0.32.8"
},
"devDependencies": {

View File

@ -10,6 +10,7 @@ import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService";
import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService";
@ -94,9 +95,16 @@ export const show = async (req: Request, res: Response): Promise<Response> => {
const { schedules, count, hasMore } = await ListScheduleService({ searchParam: "", pageNumber: "1" });
//////////////////
const schedulesContact = await ListSchedulingNotifyContactService(contact.contact.number);
/////////////////
// console.log('############### schedulesContact: ', schedulesContact)
// console.log('############### contact.contact.number: ',contact.contact.number)
// return res.status(200).json(contact);
return res.status(200).json({contact, schedules});
return res.status(200).json({contact, schedules, schedulesContact});
};

View File

@ -78,8 +78,8 @@ class Ticket extends Model<Ticket> {
@HasMany(() => Message)
messages: Message[];
@HasOne(() => SchedulingNotify)
schedulingNotify: SchedulingNotify
@HasMany(() => SchedulingNotify)
schedulingNotify: SchedulingNotify[];
}
export default Ticket;

View File

@ -0,0 +1,43 @@
import Ticket from "../../models/Ticket";
import Contact from "../../models/Contact";
import SchedulingNotify from "../../models/SchedulingNotify";
import { Op, where, Sequelize } from "sequelize";
import AppError from "../../errors/AppError";
const ListSchedulingNotifyContactService = async (contactNumber: string): Promise<SchedulingNotify[]> => {
const ticket = await SchedulingNotify.findAll({
attributes:['id', [Sequelize.fn("DATE_FORMAT",Sequelize.col("schedulingDate"),"%d/%m/%Y %H:%i:%s"),"schedulingDate"], 'message'],
include: [
{
model: Ticket,
required:true,
attributes: [],
include: [
{
model: Contact,
where:{
number: contactNumber,
},
attributes: ['name', 'number']
},
]
},
],
});
if (!ticket) {
throw new AppError("ERR_NO_TICKET_FOUND", 404);
}
return ticket;
};
export default ListSchedulingNotifyContactService;

View File

@ -7,21 +7,49 @@ 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 '../../Report/DatePicker'
import TimerPickerSelect from '../TimerPickerSelect'
// import MainHeader from "../../components/MainHeader";
// import MainHeaderButtonsWrapper from "../../components/MainHeaderButtonsWrapper";
// import TableRowSkeleton from "../../components/TableRowSkeleton";
// import Title from "../../components/Title";
import TextareaAutosize from '@mui/material/TextareaAutosize';
import { addHours } from "date-fns";
import { addHours, subHours } from "date-fns";
import {
IconButton,
makeStyles,
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
Typography,
} from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
mainPaper: {
flex: 1,
padding: theme.spacing(1),
overflowY: "scroll",
...theme.scrollbarStyles,
},
customTableCell: {
display: "flex",
alignItems: "center",
justifyContent: "center",
},
}));
const Item = (props) => {
@ -59,6 +87,7 @@ Item.propTypes = {
const Modal = (props) => {
const classes = useStyles();
const [open, setOpen] = useState(true);
const [scroll, /*setScroll*/] = useState('body');
@ -69,6 +98,7 @@ const Modal = (props) => {
const [data] = useState(props.schedules)
const [schedulesContact] = useState(props.schedulesContact)
const handleCancel = (event, reason) => {
@ -123,9 +153,9 @@ const dateCurrentFormated = () => {
alert('Mensagem muito curta!\nMínimo 10 caracteres.')
return
}
else if((new Date(timerPicker).getHours() > 16 && new Date(timerPicker).getMinutes() > 0) ||
else if((new Date(timerPicker).getHours() > 20 && new Date(timerPicker).getMinutes() > 0) ||
(new Date(timerPicker).getHours() < 7)){
alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 07:00 e 17:00')
alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 07:00 e 20:00')
return
}
else if(startDate === dateCurrentFormated()){
@ -139,13 +169,18 @@ const dateCurrentFormated = () => {
}
}
// console.log('NEW DATE: ', formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00')
props.func({
'scheduleId': scheduleId,
'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`,
// 'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`,
'schedulingDate': startDate+' '+formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00',
'message': textArea1
});
setOpen(false);
};
@ -177,15 +212,18 @@ const textFieldSelect = (data) => {
useEffect(()=>{
if (parseInt(timerPicker.getHours()) > 12 && parseInt(timerPicker.getHours()) < 18){
setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
if (parseInt(timerPicker.getHours()) > 11 && parseInt(timerPicker.getHours()) < 18){
// setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1)))
}
else if(parseInt(timerPicker.getHours()) < 12){
setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
// setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1)))
}
else if(parseInt(timerPicker.getHours()) > 18){
else if(parseInt(timerPicker.getHours()) > 17){
setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
// setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1)))
}
@ -282,6 +320,93 @@ const handleChange = (event) => {
</Item>
}
{/* <Item>
<MainHeader>
<Title>Titulo 1</Title>
<MainHeaderButtonsWrapper>
<Button
variant="contained"
color="primary"
// onClick={handleOpenQueueModal}
>
buttons add
</Button>
</MainHeaderButtonsWrapper>
</MainHeader>
<Paper variant="outlined">
<Table size="small">
<TableHead>
<TableRow>
<TableCell align="center">
table name
</TableCell>
<TableCell align="center">
table color
</TableCell>
<TableCell align="center">
table greeting
</TableCell>
<TableCell align="center">
table actions
</TableCell>
</TableRow>
</TableHead>
<TableBody>
<>
{schedulesContact.map((queue) => (
<TableRow key={queue.id}>
<TableCell align="center">{queue.name}</TableCell>
<TableCell align="center">
<div className={classes.customTableCell}>
<span
style={{
backgroundColor: queue.color,
width: 60,
height: 20,
alignSelf: "center",
}}
/>
</div>
</TableCell>
<TableCell align="center">
<div className={classes.customTableCell}>
<Typography
style={{ width: 300, align: "center" }}
noWrap
variant="body2"
>
{queue.greetingMessage}
</Typography>
</div>
</TableCell>
<TableCell align="center">
<IconButton
size="small"
// onClick={() => handleEditQueue(queue)}
>
<Edit />
</IconButton>
<IconButton
size="small"
onClick={() => {
setSelectedQueue(queue);
setConfirmModalOpen(true);
}}
>
<DeleteOutline />
</IconButton>
</TableCell>
</TableRow>
))}
{loading && <TableRowSkeleton columns={4} />}
</>
</TableBody>
</Table>
</Paper>
</Item> */}
</Box>
</DialogContent>

View File

@ -9,6 +9,9 @@ import {
MuiPickersUtilsProvider,
} from '@material-ui/pickers';
import ptBrLocale from "date-fns/locale/pt-BR";

View File

@ -84,6 +84,7 @@ const Ticket = () => {
const [ticket, setTicket] = useState({});
const [schedule, setSchedule] = useState({})
const [schedulesContact, setSchedulesContact] = useState({})
useEffect(() => {
setLoading(true);
@ -98,10 +99,13 @@ const Ticket = () => {
// setContact(data.contact);
// setTicket(data);
console.log('SCHEDULE CONTACT: ',data.schedulesContact)
setContact(data.contact.contact);
setTicket(data.contact);
setSchedule(data.schedules)
setSchedulesContact(data.schedulesContact)
setLoading(false);
} catch (err) {
@ -172,7 +176,7 @@ const Ticket = () => {
/>
</div>
<div className={classes.ticketActionButtons}>
<TicketActionButtons ticket={ticket} schedule={schedule}/>
<TicketActionButtons ticket={ticket} schedule={schedule} schedulesContact={schedulesContact}/>
</div>
</TicketHeader>
<ReplyMessageProvider>

View File

@ -27,7 +27,7 @@ const useStyles = makeStyles(theme => ({
},
}));
const TicketActionButtons = ({ ticket, schedule }) => {
const TicketActionButtons = ({ ticket, schedule, schedulesContact }) => {
const classes = useStyles();
const history = useHistory();
const [anchorEl, setAnchorEl] = useState(null);
@ -65,6 +65,7 @@ const TicketActionButtons = ({ ticket, schedule }) => {
modal_header={'Finalização de Atendimento'}
func={chatEndVal}
schedules={schedule}
schedulesContact={schedulesContact}
/>)
};