Remoção do agendamento e refatoração do código para o lembrete

pull/1/head
adriano 2022-03-17 08:58:22 -03:00
parent 9f3183f8ce
commit 43b3d31724
4 changed files with 68 additions and 174 deletions

View File

@ -139,7 +139,7 @@ export const update = async ( req: Request, res: Response ): Promise<Response> =
} }
/////////////////////////////// ///////////////////////////////
// agendamento // lembrete
const scheduleData = JSON.parse(schedulingNotifyData) const scheduleData = JSON.parse(schedulingNotifyData)
if( scheduleData.scheduleId === '2'){ if( scheduleData.scheduleId === '2'){

View File

@ -11,7 +11,7 @@ module.exports = {
updatedAt: new Date() updatedAt: new Date()
}, },
{ {
name: "AGENDAMENTO À CONFIRMAR", name: "LEMBRETE",
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date() updatedAt: new Date()
} }

View File

@ -9,12 +9,11 @@ import DialogTitle from '@mui/material/DialogTitle';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import SelectField from "../../Report/SelectField"; import SelectField from "../../Report/SelectField";
import TextFieldSelectHourBefore from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import DatePicker from '../../Report/DatePicker' import DatePicker from '../../Report/DatePicker'
import TimerPickerSelect from '../TimerPickerSelect' import TimerPickerSelect from '../TimerPickerSelect'
import TextareaAutosize from '@mui/material/TextareaAutosize'; import TextareaAutosize from '@mui/material/TextareaAutosize';
import { subHours } from "date-fns"; // import { subHours } from "date-fns";
@ -122,8 +121,6 @@ const Modal = (props) => {
const [schedulesContact, dispatch] = useReducer(reducer, []); const [schedulesContact, dispatch] = useReducer(reducer, []);
const [currencyHourBefore, setCurrency] = useState(null);
const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null);
const handleCancel = (event, reason) => { const handleCancel = (event, reason) => {
@ -151,15 +148,18 @@ const Modal = (props) => {
}, [props]); }, [props]);
function greetMessageSchedule(scheduleDate){
return `podemos confirmar sua consulta agendada para hoje às ${scheduleDate}?`
}
function formatedTimeHour(timer){ function formatedTimeHour(timer){
return `${timer.getHours().toString().padStart(2, '0')}:${timer.getMinutes().toString().padStart(2, '0')}` 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 = () => { const handleCloseConfirmationModal = () => {
@ -171,7 +171,7 @@ const Modal = (props) => {
const handleDeleteSchedule = async (scheduleId) => { const handleDeleteSchedule = async (scheduleId) => {
try { try {
await api.delete(`/schedule/${scheduleId}`); await api.delete(`/schedule/${scheduleId}`);
toast.success(("Agendamento deletado com sucesso!")); toast.success(("Lembrete deletado com sucesso!"));
dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId }); dispatch({ type: "DELETE_SCHEDULE", payload: scheduleId });
} catch (err) { } catch (err) {
toastError(err); toastError(err);
@ -195,50 +195,55 @@ const timerPickerValue = (data) => {
} }
const dateCurrentFormated = () => {
let 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) => { const handleChatEnd = (event, reason) => {
let dataSendServer = {'scheduleId': scheduleId}
if (reason && reason === "backdropClick") if (reason && reason === "backdropClick")
return; return;
if (scheduleId === '1'){ if (scheduleId === '2'){
}
else if(textArea1 && textArea1.trim().length<10){ console.log('Entrou! textArea1: ', textArea1)
alert('Mensagem muito curta!\nMínimo 10 caracteres.')
if(textArea1 && textArea1.trim().length<5){
alert('Mensagem muito curta!')
return 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) || else if((new Date(timerPicker).getHours() > 20 && new Date(timerPicker).getMinutes() > 0) ||
(new Date(timerPicker).getHours() < 7)){ (new Date(timerPicker).getHours() < 6)){
alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 07:00 e 20:00') alert('Horário comercial inválido!\n Selecione um horário de lembrete válido entre às 06:00 e 20:00')
return return
} }
else 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!') dataSendServer = {
return
}
props.func({
'scheduleId': scheduleId, 'scheduleId': scheduleId,
'schedulingDate': `${startDate} ${currencyHourBefore}:00`, 'schedulingDate': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)),
'schedulingTime': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)), 'schedulingTime': startDate+' '+formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`)),
'message': textArea1 'message': textArea1
}); }
}
props.func(dataSendServer)
setOpen(false); setOpen(false);
}; };
@ -262,101 +267,6 @@ const textFieldSelect = (data) => {
} }
const handleChangeHourBefore = (event) => {
console.log('textFihandleChangeHourBefore: ',event.target.value);
setCurrency(event.target.value);
};
useEffect(()=>{
const hoursBeforeAvalible = (timer) =>{
let hours = []
let hour = 1
if(startDate === dateCurrentFormated()){
console.log('HOJE++++')
while(subHours(timer, hour).getHours()>=6 &&
subHours(timer, hour).getHours()>=new Date().getHours() &&
subHours(timer, hour).getHours()<=19){
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()<=19){
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)
}
}
return {time: hours, hour:hour}
}
setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker).time)
},[timerPicker, startDate])
useEffect(()=>{
console.log('CURRENCY HOUR BEFORE: ', `${startDate} ${currencyHourBefore}:00`)
let auxDate = new Date(`${startDate} ${currencyHourBefore}:00`)
if (parseInt(auxDate.getHours()) > 11 && parseInt(auxDate.getHours()) < 18){
setTextArea1('Boa tarde, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1)))
}
else if(parseInt(auxDate.getHours()) < 12){
setTextArea1('Bom dia, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1)))
}
else if(parseInt(auxDate.getHours()) > 17){
setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1)))
}
},[currencyHourBefore, startDate, timerPicker])
const handleChange = (event) => { const handleChange = (event) => {
@ -423,39 +333,19 @@ const handleChange = (event) => {
<Item> <Item>
<span>Lembrete de retorno</span> <span>Lembrete</span>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}> <Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)' }}>
<Item><DatePicker func={datePickerValue} minDate = {true} title={'Data do agendamento'}/></Item> <Item><DatePicker func={datePickerValue} minDate = {true} title={'Data do lembrete'}/></Item>
<Item><TimerPickerSelect func={timerPickerValue} title={'Hora do agendamento'}/></Item> <Item><TimerPickerSelect func={timerPickerValue} title={'Hora do lembrete'}/></Item>
</Box> </Box>
<Box sx={{display: 'flex', flexDirection: 'column' }}> <Box sx={{display: 'flex', flexDirection: 'column' }}>
{currencyHourBefore &&
<Item>
<TextFieldSelectHourBefore
id="outlined-select-currency"
select
label="Enviar mensagem para cliente"
value={currencyHourBefore}
size="small"
onChange={handleChangeHourBefore}
>
{currenciesTimeBefore.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</TextFieldSelectHourBefore>
</Item>
}
<Item> <Item>
<TextareaAutosize <TextareaAutosize
aria-label="minimum height" aria-label="minimum height"
@ -483,9 +373,9 @@ const handleChange = (event) => {
onClose={handleCloseConfirmationModal} onClose={handleCloseConfirmationModal}
onConfirm={() => handleDeleteSchedule(selectedSchedule.id)} onConfirm={() => handleDeleteSchedule(selectedSchedule.id)}
> >
<span>Deseja realmente deletar esse Agendamento? </span> <span>Deseja realmente deletar esse Lembrete? </span>
</ConfirmationModal> </ConfirmationModal>
<span>Agendamentos</span> <span>Lembrete</span>
<Paper variant="outlined"> <Paper variant="outlined">
<Table size="small"> <Table size="small">
@ -497,6 +387,9 @@ const handleChange = (event) => {
<TableCell align="center"> <TableCell align="center">
Hora Hora
</TableCell> </TableCell>
<TableCell align="center">
Mensagem
</TableCell>
<TableCell align="center"> <TableCell align="center">
Deletar Deletar
</TableCell> </TableCell>
@ -509,6 +402,8 @@ const handleChange = (event) => {
<TableRow key={scheduleData.id}> <TableRow key={scheduleData.id}>
<TableCell align="center">{scheduleData.schedulingDate.split(' ')[0]}</TableCell> <TableCell align="center">{scheduleData.schedulingDate.split(' ')[0]}</TableCell>
<TableCell align="center">{scheduleData.schedulingTime.split(' ')[1]}</TableCell> <TableCell align="center">{scheduleData.schedulingTime.split(' ')[1]}</TableCell>
<TableCell align="center">{scheduleData.message}</TableCell>
<TableCell align="center"> <TableCell align="center">
<IconButton <IconButton

View File

@ -55,7 +55,6 @@ const TicketActionButtons = ({ ticket, schedule }) => {
} }
} }