From 68a421c567370be923d92d265008dbded88d23d6 Mon Sep 17 00:00:00 2001 From: adriano Date: Fri, 11 Mar 2022 00:01:58 -0300 Subject: [PATCH] =?UTF-8?q?Codigifica=C3=A7=C3=A3o=20para=20atendente=20po?= =?UTF-8?q?der=20escolher=20hora=20de=20envio=20de=20mensagem=20como=20lem?= =?UTF-8?q?brete=20para=20retorno=20de=20agendamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ChatEnd/ModalChatEnd/index.js | 156 +++++++++++++----- .../components/Report/SelectField/index.js | 2 +- 2 files changed, 120 insertions(+), 38 deletions(-) diff --git a/frontend/src/components/ChatEnd/ModalChatEnd/index.js b/frontend/src/components/ChatEnd/ModalChatEnd/index.js index f098441..d220238 100644 --- a/frontend/src/components/ChatEnd/ModalChatEnd/index.js +++ b/frontend/src/components/ChatEnd/ModalChatEnd/index.js @@ -10,6 +10,10 @@ import DialogTitle from '@mui/material/DialogTitle'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; import SelectField from "../../Report/SelectField"; + +import TextFieldSelectHourBefore from '@mui/material/TextField'; +import MenuItem from '@mui/material/MenuItem'; + import DatePicker from '../../Report/DatePicker' import TimerPickerSelect from '../TimerPickerSelect' @@ -21,7 +25,7 @@ import TimerPickerSelect from '../TimerPickerSelect' import TextareaAutosize from '@mui/material/TextareaAutosize'; -import { addHours, subHours } from "date-fns"; +import { addHours, subHours, subMinutes } from "date-fns"; @@ -84,6 +88,7 @@ Item.propTypes = { ]), }; + const Modal = (props) => { @@ -98,7 +103,12 @@ const Modal = (props) => { const [data] = useState(props.schedules) + const [schedulesContact] = useState(props.schedulesContact) + + const [currencyHourBefore, setCurrency] = useState(formatedTimeHour(subHours(timerPicker,1))); + const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState( ); + const [test, setTest] = useState(null); const handleCancel = (event, reason) => { @@ -109,6 +119,7 @@ const Modal = (props) => { }; + function greetMessageSchedule(scheduleDate){ return `podemos confirmar sua consulta agendada para hoje às ${scheduleDate}?` @@ -118,6 +129,35 @@ const Modal = (props) => { return `${timer.getHours().toString().padStart(2, '0')}:${timer.getMinutes().toString().padStart(2, '0')}` } + function hoursBeforeAvalible(timer){ + + + let hours = [] + let hour = 1 + + while(subHours(timer, hour).getHours()>=6 /*&& subHours(timer, hour).getHours()>=new Date().getHours()*/){ + + 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){ + setCurrency(hours[0].value) + } + + + return hours + + console.log('HOURS: ',hours) + + } + + // Get from child 2 const datePickerValue = (data) => { @@ -143,6 +183,7 @@ const dateCurrentFormated = () => { } const handleChatEnd = (event, reason) => { + if (reason && reason === "backdropClick") return; @@ -158,28 +199,35 @@ const dateCurrentFormated = () => { 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()){ + // else if(startDate === dateCurrentFormated()){ + // if( + // (new Date(subHours(timerPicker, 1)).getHours() <= new Date().getHours() && + // new Date(subHours(timerPicker, 1)).getMinutes() <= new Date().getMinutes()) || - 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 - } - } + // (new Date(subHours(timerPicker, 1)).getHours() == new Date().getHours() && + // new Date(subHours(timerPicker, 1)).getMinutes() <= new Date().getMinutes()) + + // ) + // { - // console.log('NEW DATE: ', formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00') - + // alert('Para agendamentos do dia, é necessário que o horário do lembrete seja no mínimo uma hora adiantado!') + + // return + // } + // } + + + + props.func({ - 'scheduleId': scheduleId, + 'scheduleId': scheduleId, + // 'schedulingDate': startDate+' '+formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00', // 'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`, - 'schedulingDate': startDate+' '+formatedTimeHour(subHours(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`), 1))+':00', + 'schedulingDate': `${startDate} ${currencyHourBefore}:00`, 'message': textArea1 - }); - - + }); + setOpen(false); }; @@ -203,6 +251,17 @@ const textFieldSelect = (data) => { } +const handleChangeHourBefore = (event) => { + + console.log('textFihandleChangeHourBefore: ',event.target.value); + + setCurrency(event.target.value); +}; + + + + + // Get from child 4 // const textArea1Value = (data) => { @@ -225,7 +284,9 @@ useEffect(()=>{ // setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(addHours(new Date(timerPicker), 1)))) setTextArea1('Boa noite, '+greetMessageSchedule( formatedTimeHour(new Date(timerPicker), 1))) } - + + setCurrenciesTimeBefore(hoursBeforeAvalible(timerPicker)) + },[timerPicker]) @@ -235,6 +296,8 @@ const handleChange = (event) => { setTextArea1(event.target.value); }; + + return ( @@ -275,13 +338,15 @@ const handleChange = (event) => { display: 'grid', }}> - Selecione uma opção para encerrar o Atendimento - - - { + Selecione uma opção para encerrar o Atendimento + + { return {'value': obj.id, 'label': obj.name} })}/> - + @@ -295,26 +360,43 @@ const handleChange = (event) => { - + - + - + + + + + {currenciesTimeBefore.map((option) => ( + + {option.label} + + ))} + + + - {/* */} - - - + + + diff --git a/frontend/src/components/Report/SelectField/index.js b/frontend/src/components/Report/SelectField/index.js index 0993b4d..5dd4cdc 100644 --- a/frontend/src/components/Report/SelectField/index.js +++ b/frontend/src/components/Report/SelectField/index.js @@ -15,7 +15,7 @@ const SelectTextFields = (props) => { useEffect(()=>{ - + props.func(currency); },[currency, props])