fix: prevenir multiplos agendamentos travando botao durante a submissao
Build and Deploy (Gitea Actions) / build-and-deploy (push) Has been cancelled
Details
Build and Deploy (Gitea Actions) / build-and-deploy (push) Has been cancelled
Details
This commit is contained in:
parent
dfcfdae1f8
commit
094640bffb
|
|
@ -62,6 +62,7 @@ export default function Agenda() {
|
||||||
const [newDate, setNewDate] = useState(today.toISOString().split('T')[0]);
|
const [newDate, setNewDate] = useState(today.toISOString().split('T')[0]);
|
||||||
const [newTime, setNewTime] = useState('10:00');
|
const [newTime, setNewTime] = useState('10:00');
|
||||||
const [newNotes, setNewNotes] = useState('');
|
const [newNotes, setNewNotes] = useState('');
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (professionals.length > 0 && !newProf) {
|
if (professionals.length > 0 && !newProf) {
|
||||||
|
|
@ -247,8 +248,8 @@ export default function Agenda() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-footer">
|
<div className="modal-footer">
|
||||||
<button className="btn btn-secondary" onClick={() => setShowModal(false)}>Cancelar</button>
|
<button className="btn btn-secondary" disabled={submitting} onClick={() => setShowModal(false)}>Cancelar</button>
|
||||||
<button className="btn btn-primary" onClick={async () => {
|
<button className="btn btn-primary" disabled={submitting} onClick={async () => {
|
||||||
const [h, m] = newTime.split(':').map(Number);
|
const [h, m] = newTime.split(':').map(Number);
|
||||||
const selectedSvc = services.find(s => s.id === newService);
|
const selectedSvc = services.find(s => s.id === newService);
|
||||||
|
|
||||||
|
|
@ -258,6 +259,7 @@ export default function Agenda() {
|
||||||
|
|
||||||
const slug = localStorage.getItem('agendapro_tenant_slug') || 'barbearia-premium';
|
const slug = localStorage.getItem('agendapro_tenant_slug') || 'barbearia-premium';
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/tenant/agenda', {
|
const res = await fetch('/api/tenant/agenda', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
@ -288,8 +290,10 @@ export default function Agenda() {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
}}>Agendar</button>
|
}}>{submitting ? 'Agendando...' : 'Agendar'}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue