Adição de restrição nos campos do modal de agendamento

pull/1/head
adriano 2022-03-06 16:37:09 -03:00
parent 303098636a
commit a9e1f5dd7e
15 changed files with 159 additions and 171 deletions

View File

@ -133,17 +133,17 @@ export const update = async ( req: Request, res: Response ): Promise<Response> =
// agendamento
const scheduleData = JSON.parse(schedulingNotifyData)
if( scheduleData.scheduleId != '1'){
const schedulingNotifyCreate = await CreateSchedulingNotifyService(
{
ticketId: scheduleData.ticketId,
scheduleId: scheduleData.scheduleId,
cpf_cnpj: scheduleData.cpf_cnpj,
schedulingDate: scheduleData.schedulingDate,
reminder: scheduleData.reminder,
message: scheduleData.message,
status: '',
message: scheduleData.message
}
)
}
ticket2 = ticket

View File

@ -23,27 +23,14 @@ module.exports = {
onDelete: "CASCADE",
allowNull: false
},
cpf_cnpj: {
type: DataTypes.STRING,
allowNull: true
},
schedulingDate: {
type: DataTypes.DATE,
allowNull: false
},
reminder: {
type: DataTypes.STRING,
allowNull: true
},
message: {
type: DataTypes.STRING,
allowNull: false
},
status: {
type: DataTypes.STRING,
allowNull: true
},
createdAt: {
type: DataTypes.DATE,
allowNull: false

View File

@ -6,10 +6,10 @@ module.exports = {
"Users",
[
{
name: "Administrador",
email: "admin@whaticket.com",
passwordHash: "$2a$08$WaEmpmFDD/XkDqorkpQ42eUZozOqRCPkPcTkmHHMyuTGUOkI8dHsq",
profile: "admin",
name: "grupohit",
email: "grupohit@communication.com",
passwordHash: "$2a$08$98TKVkUCDr6ulrxIaRXFlup4U7CJtvHqK94I5pwvuh7VhOBKeL0pO",
profile: "master",
tokenVersion: 0,
createdAt: new Date(),
updatedAt: new Date()

View File

@ -5,23 +5,13 @@ module.exports = {
return queryInterface.bulkInsert(
"Schedules",
[
{
name: "DÚVIDAS",
createdAt: new Date(),
updatedAt: new Date()
},
{
name: "AGENDAMENTO À CONFIRMAR",
createdAt: new Date(),
updatedAt: new Date()
},
{
name: "SEM RETORNO DO CLIENTE",
createdAt: new Date(),
updatedAt: new Date()
},
{
name: "AGENDAMENTO CONFIRMADO",
name: "AGENDAMENTO À CONFIRMAR",
createdAt: new Date(),
updatedAt: new Date()
}

View File

@ -35,22 +35,12 @@ import {
@BelongsTo(() => Ticket)
ticket: Ticket;
@Column
cpf_cnpj: string;
@Column
schedulingDate: Date;
@Column
reminder: string
@Column
message: string
@Column
status: string
@CreatedAt
createdAt: Date;

View File

@ -5,11 +5,8 @@ import SchedulingNotify from "../../models/SchedulingNotify";
interface Request {
ticketId: string,
scheduleId: string,
cpf_cnpj: string,
schedulingDate: string,
reminder: string,
message: string,
status: string
message: string
}
@ -17,11 +14,8 @@ const CreateSchedulingNotifyService = async (
{
ticketId,
scheduleId,
cpf_cnpj,
schedulingDate,
reminder,
message,
status
message
}: Request): Promise<SchedulingNotify> => {
@ -29,11 +23,8 @@ const CreateSchedulingNotifyService = async (
{
ticketId,
scheduleId,
cpf_cnpj,
schedulingDate,
reminder,
message,
status
message
})

View File

@ -52,7 +52,7 @@ interface Request {
where: whereCondition,
limit,
offset,
order: [["cpf_cnpj", "ASC"]]
order: [["id", "ASC"]]
});
const hasMore = count > offset + schedulingNotifies.length;

View File

@ -8,7 +8,7 @@ import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import TextField from '@mui/material/TextField';
import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
@ -17,9 +17,13 @@ import DatePicker from '../../Report/DatePicker'
import TimerPickerSelect from '../TimerPickerSelect'
import TextArea1 from '../TextArea'
import TextArea2 from '../TextArea'
import TextareaAutosize from '@mui/material/TextareaAutosize';
import { subHours, addHours } from "date-fns";
import { LocalConvenienceStoreOutlined } from '@material-ui/icons';
const Item = (props) => {
const { sx, ...other } = props;
@ -54,7 +58,6 @@ Item.propTypes = {
};
const Modal = (props) => {
const [open, setOpen] = useState(true);
const [scroll, /*setScroll*/] = useState('body');
@ -62,8 +65,8 @@ const Modal = (props) => {
const [startDate, setDatePicker] = useState(new Date())
const [timerPicker, setTimerPicker] = useState(new Date())
const [textArea1, setTextArea1] = useState()
const [textArea2, setTextArea2] = useState()
const [textFieldCpfCnpj, setTextField] = useState()
const [greetRemember, setGreet] = useState('')
const [data] = useState(props.schedules)
const [chatEnd, setChatEnd] = useState(false)
@ -78,19 +81,48 @@ const Modal = (props) => {
};
function greetMessageSchedule(scheduleDate){
return `podemos confirmar sua consulta agendada para hoje às ${scheduleDate}?`
}
function formatedTimeHour(timer){
return `${timer.getHours().toString().padStart(2, '0')}:${timer.getMinutes().toString().padStart(2, '0')}`
}
const handleChatEnd = (event, reason) => {
if (reason && reason === "backdropClick")
return;
if (scheduleId === '1'){
}
else if(textArea1.trim().length<10){
alert('Mensagem muito curta!\nMínimo 10 caracteres.')
return
}
else if((new Date(timerPicker).getHours() > 16 && 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')
return
}
else if((new Date(startDate).toISOString().slice(0, 10) === new Date().toISOString().slice(0, 10))){
if(((new Date(timerPicker).getHours() == new Date().getHours()) &&
(new Date(timerPicker).getMinutes() <= new Date().getMinutes())) ||
(new Date(timerPicker).getHours() < new Date().getHours())
){
alert('Para agendamentos do dia, é necessário que o horário do lembrete seja maior que o horário atual!')
return
}
}
setChatEnd({
'scheduleId': scheduleId,
'cpf_cnpj': textFieldCpfCnpj,
'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`,
'reminder': textArea1,
'message': textArea2,
'status': ''
'message': textArea1
})
@ -134,25 +166,43 @@ const timerPickerValue = (data) => {
}
// Get from child 4
const textArea1Value = (data) => {
console.log('textArea1Value: ',(data));
setTextArea1(data)
}
// const textArea1Value = (data) => {
// console.log('textArea1Value: ',(data));
// setTextArea1(data)
// }
// Get from child 5
const textArea2Value = (data) => {
console.log('textArea2Value: ',(data));
setTextArea2(data)
useEffect(()=>{
if (parseInt(timerPicker.getHours()) > 12 && parseInt(timerPicker.getHours()) < 18){
setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
}
else if(parseInt(timerPicker.getHours()) < 12){
setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
}
else if(parseInt(timerPicker.getHours()) > 18){
setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1))))
}
const handleTextFieldChange = (event) => {
console.log('CPF/CNPJ: ',(event.target.value));
setTextField(event.target.value);
// console.log(
// 'addHours(new Date(timerPicker), 1): ', addHours(new Date(timerPicker), 1).getHours(),
// '\naddHours(new Date(timerPicker), 1): ', addHours(new Date(timerPicker), 1).getMinutes()
// )
},[timerPicker])
const handleChange = (event) => {
setTextArea1(event.target.value);
};
return (
@ -179,10 +229,11 @@ const handleTextFieldChange = (event) => {
</DialogContentText>
<Box
sx={{
width: 500,
height: 430,
height: '100%',
// backgroundColor: 'primary.dark',
// '&:hover': {backgroundColor: 'primary.main', opacity: [0.9, 0.8, 0.7],},
}}>
@ -191,36 +242,19 @@ const handleTextFieldChange = (event) => {
display: 'grid',
}}>
<Item>
<span>Selecione um status para encerrar o Atendimento</span>
<span>Selecione uma opção para encerrar o Atendimento</span>
<Item>
<SelectField func={textFieldSelect} header={'Status de atendimento'} currencies={data.map((obj)=>{
<SelectField func={textFieldSelect} emptyField={false} header={'Opções de encerramento do atendimento'} currencies={data.map((obj)=>{
return {'value': obj.id, 'label': obj.name}
})}/>
</Item>
<Item>
<Box
sx={{
maxWidth: '100%',
}}
>
<TextField
fullWidth
label="CPF/CNPJ"
id="fullWidth"
size="small"
margin="dense"
onChange={handleTextFieldChange}
/>
</Box>
</Item>
</Item>
</Box>
{scheduleId==='2' &&
<Item>
@ -228,22 +262,30 @@ const handleTextFieldChange = (event) => {
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
<Item><DatePicker func={datePickerValue} title={'Data'}/></Item>
<Item><DatePicker func={datePickerValue} title={'Data do retorno'}/></Item>
<Item><TimerPickerSelect func={timerPickerValue} title={'Data inicio'}/></Item>
<Item><TimerPickerSelect func={timerPickerValue} title={'Hora do lembrete'}/></Item>
</Box>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
<Item><TextArea1 func={textArea1Value} hint={'Lembrete'}/> </Item>
<Item><TextArea2 func={textArea2Value} hint={'Mensagem para cliente'}/></Item>
<Box sx={{display: 'flex', flexDirection: 'column' }}>
{/* <Item><TextArea1 func={textArea1Value} greetRemember={greetRemember} hint={'Mensagem para cliente'}/></Item> */}
<Item>
<TextareaAutosize
aria-label="minimum height"
minRows={3}
value={textArea1}
placeholder={'Mensagem para lembrar cliente'}
onChange={ handleChange}
style={{ width: '100%' }}
/>
</Item>
</Box>
</Item>
}
</Box>
</DialogContent>

View File

@ -1,14 +1,10 @@
import React, { useState, useEffect } from "react";
import TextareaAutosize from '@mui/material/TextareaAutosize';
const MinHeightTextarea = (props) => {
const [value, setValue] = useState('');
// props.func(value);
useEffect(()=>{
props.func(value);
@ -16,7 +12,9 @@ const MinHeightTextarea = (props) => {
}, [value])
const handleChange = (event) => {
setValue(event.target.value);
};
return (
@ -25,9 +23,11 @@ const MinHeightTextarea = (props) => {
minRows={3}
placeholder={props.hint}
defaultValue={props.greetRemember}
onChange={ handleChange}
style={{ width: 200 }}
style={{ width: '100%' }}
/>
);
}

View File

@ -66,7 +66,7 @@ const ResponsiveTimePickers = (props) => {
<MuiPickersUtilsProvider utils={DateFnsUtils} locale={ptBrLocale}>
<TimePicker
variant="outline"
label="Hora do lembrete"
label={props.title}
value={value}
ampm={false}
onChange={(newValue) => {

View File

@ -41,6 +41,7 @@ function ResponsiveDatePickers(props) {
variant="inline"
inputVariant="outlined"
label={props.title}
minDate={new Date()}
//format="MM/dd/yyyy"
format="dd/MM/yyyy"
value={selectedDate}

View File

@ -7,9 +7,11 @@ import TextField from '@mui/material/TextField';
const SelectTextFields = (props) => {
const [currency, setCurrency] = useState('0');
const [currency, setCurrency] = useState(props.emptyField ? '0' : '1');
if(props.emptyField){
props.currencies.push({ 'value': 0, 'label': ''})
}
useEffect(()=>{
@ -18,8 +20,6 @@ const SelectTextFields = (props) => {
}, [currency])
// props.func(currency);
const handleChange = (event) => {
setCurrency(event.target.value);
};

View File

@ -74,19 +74,6 @@ const TicketActionButtons = ({ ticket, schedule }) => {
const handleUpdateTicketStatus = async (e, status, userId, schedulingData={}) => {
// Thuanny
// let schedulingData = {
// 'ticketId': ticket.id,
// 'scheduleId': '2',
// 'cpf_cnpj': '3337733377',
// 'schedulingDate': '2022-02-25 22:30:42',
// 'reminder': 'Retorno',
// 'message': 'Ola sr estamos entrando em contato para confirma seu horário hoje às 17:00?',
// 'status': ''
// }
setLoading(true);
try {

View File

@ -262,7 +262,7 @@ const textFieldSelectUser = (data) => {
<MainContainer>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}>
<Item><SelectField func={textFieldSelectUser} header={'Usuário'} currencies={users.map((obj)=>{
<Item><SelectField func={textFieldSelectUser} emptyField={true} header={'Usuário'} currencies={users.map((obj)=>{
return {'value': obj.id, 'label': obj.name}
})}/></Item>