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 // agendamento
const scheduleData = JSON.parse(schedulingNotifyData) const scheduleData = JSON.parse(schedulingNotifyData)
if( scheduleData.scheduleId != '1'){
const schedulingNotifyCreate = await CreateSchedulingNotifyService( const schedulingNotifyCreate = await CreateSchedulingNotifyService(
{ {
ticketId: scheduleData.ticketId, ticketId: scheduleData.ticketId,
scheduleId: scheduleData.scheduleId, scheduleId: scheduleData.scheduleId,
cpf_cnpj: scheduleData.cpf_cnpj,
schedulingDate: scheduleData.schedulingDate, schedulingDate: scheduleData.schedulingDate,
reminder: scheduleData.reminder, message: scheduleData.message
message: scheduleData.message,
status: '',
} }
) )
}
ticket2 = ticket ticket2 = ticket

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,7 +52,7 @@ interface Request {
where: whereCondition, where: whereCondition,
limit, limit,
offset, offset,
order: [["cpf_cnpj", "ASC"]] order: [["id", "ASC"]]
}); });
const hasMore = count > offset + schedulingNotifies.length; 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 DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle'; import DialogTitle from '@mui/material/DialogTitle';
import TextField from '@mui/material/TextField';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
@ -17,9 +17,13 @@ import DatePicker from '../../Report/DatePicker'
import TimerPickerSelect from '../TimerPickerSelect' import TimerPickerSelect from '../TimerPickerSelect'
import TextArea1 from '../TextArea' 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 Item = (props) => {
const { sx, ...other } = props; const { sx, ...other } = props;
@ -54,7 +58,6 @@ Item.propTypes = {
}; };
const Modal = (props) => { const Modal = (props) => {
const [open, setOpen] = useState(true); const [open, setOpen] = useState(true);
const [scroll, /*setScroll*/] = useState('body'); const [scroll, /*setScroll*/] = useState('body');
@ -62,8 +65,8 @@ const Modal = (props) => {
const [startDate, setDatePicker] = useState(new Date()) const [startDate, setDatePicker] = useState(new Date())
const [timerPicker, setTimerPicker] = useState(new Date()) const [timerPicker, setTimerPicker] = useState(new Date())
const [textArea1, setTextArea1] = useState() const [textArea1, setTextArea1] = useState()
const [textArea2, setTextArea2] = useState() const [greetRemember, setGreet] = useState('')
const [textFieldCpfCnpj, setTextField] = useState()
const [data] = useState(props.schedules) const [data] = useState(props.schedules)
const [chatEnd, setChatEnd] = useState(false) 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) => { const handleChatEnd = (event, reason) => {
if (reason && reason === "backdropClick") if (reason && reason === "backdropClick")
return; 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({ setChatEnd({
'scheduleId': scheduleId, 'scheduleId': scheduleId,
'cpf_cnpj': textFieldCpfCnpj,
'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`, 'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`,
'reminder': textArea1, 'message': textArea1
'message': textArea2,
'status': ''
}) })
@ -134,25 +166,43 @@ const timerPickerValue = (data) => {
} }
// Get from child 4 // Get from child 4
const textArea1Value = (data) => { // const textArea1Value = (data) => {
console.log('textArea1Value: ',(data)); // console.log('textArea1Value: ',(data));
setTextArea1(data) // setTextArea1(data)
} // }
// Get from child 5 useEffect(()=>{
const textArea2Value = (data) => {
console.log('textArea2Value: ',(data)); if (parseInt(timerPicker.getHours()) > 12 && parseInt(timerPicker.getHours()) < 18){
setTextArea2(data) 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)); // console.log(
setTextField(event.target.value); // '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 ( return (
@ -179,10 +229,11 @@ const handleTextFieldChange = (event) => {
</DialogContentText> </DialogContentText>
<Box <Box
sx={{ sx={{
width: 500, width: 500,
height: 430, height: '100%',
// backgroundColor: 'primary.dark', // backgroundColor: 'primary.dark',
// '&:hover': {backgroundColor: 'primary.main', opacity: [0.9, 0.8, 0.7],}, // '&:hover': {backgroundColor: 'primary.main', opacity: [0.9, 0.8, 0.7],},
}}> }}>
@ -191,36 +242,19 @@ const handleTextFieldChange = (event) => {
display: 'grid', display: 'grid',
}}> }}>
<Item> <Item>
<span>Selecione um status para encerrar o Atendimento</span> <span>Selecione uma opção para encerrar o Atendimento</span>
<Item> <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} return {'value': obj.id, 'label': obj.name}
})}/> })}/>
</Item> </Item>
<Item>
<Box
sx={{
maxWidth: '100%',
}}
>
<TextField
fullWidth
label="CPF/CNPJ"
id="fullWidth"
size="small"
margin="dense"
onChange={handleTextFieldChange}
/>
</Box>
</Item>
</Item> </Item>
</Box> </Box>
{scheduleId==='2' &&
<Item> <Item>
@ -228,22 +262,30 @@ const handleTextFieldChange = (event) => {
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}> <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>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}> <Box sx={{display: 'flex', flexDirection: 'column' }}>
<Item><TextArea1 func={textArea1Value} hint={'Lembrete'}/> </Item>
<Item><TextArea2 func={textArea2Value} hint={'Mensagem para cliente'}/></Item>
{/* <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> </Box>
</Item> </Item>
}
</Box> </Box>
</DialogContent> </DialogContent>

View File

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

View File

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

View File

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

View File

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

View File

@ -74,19 +74,6 @@ const TicketActionButtons = ({ ticket, schedule }) => {
const handleUpdateTicketStatus = async (e, status, userId, schedulingData={}) => { 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); setLoading(true);
try { try {

View File

@ -262,7 +262,7 @@ const textFieldSelectUser = (data) => {
<MainContainer> <MainContainer>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}> <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} return {'value': obj.id, 'label': obj.name}
})}/></Item> })}/></Item>