Исправлена форма заказа услуги для показа QR-кода вместо создания заявки напрямую
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -417,21 +417,16 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
// Get CSRF token
|
// Get CSRF token
|
||||||
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||||
|
|
||||||
// Prepare data for submission
|
// Prepare data for QR code generation
|
||||||
const serviceId = document.getElementById('serviceId').value;
|
const serviceId = document.getElementById('serviceId').value;
|
||||||
const clientData = {
|
const clientData = {
|
||||||
service_id: serviceId,
|
client_email: formData.get('email'),
|
||||||
first_name: formData.get('first_name'),
|
client_phone: formData.get('phone'),
|
||||||
last_name: formData.get('last_name'),
|
client_name: formData.get('name')
|
||||||
email: formData.get('email'),
|
|
||||||
phone: formData.get('phone'),
|
|
||||||
description: formData.get('description'),
|
|
||||||
budget: formData.get('budget'),
|
|
||||||
timeline: formData.get('timeline')
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Submit to server
|
// Submit to QR code generation endpoint
|
||||||
fetch(`/service/request/${serviceId}/`, {
|
fetch(`/service/generate_qr_code/${serviceId}/`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -441,24 +436,41 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.registration_link) {
|
||||||
// Show success animation
|
// Hide form and show QR code
|
||||||
document.querySelector('.modal-body form').style.display = 'none';
|
document.querySelector('.modal-body form').style.display = 'none';
|
||||||
document.getElementById('successSection').style.display = 'block';
|
document.getElementById('successSection').style.display = 'none';
|
||||||
|
|
||||||
// Close modal after delay
|
// Create QR code section
|
||||||
setTimeout(() => {
|
const qrSection = document.createElement('div');
|
||||||
const modal = bootstrap.Modal.getInstance(document.getElementById('serviceModal'));
|
qrSection.id = 'qrSection';
|
||||||
if (modal) {
|
qrSection.className = 'text-center py-4';
|
||||||
modal.hide();
|
qrSection.innerHTML = `
|
||||||
}
|
<h4 class="text-primary mb-3">Завершите заявку в Telegram</h4>
|
||||||
// Reset form
|
<p class="text-muted mb-4">Отсканируйте QR-код или перейдите по ссылке для завершения регистрации заявки</p>
|
||||||
form.reset();
|
<div class="qr-code-container mb-4">
|
||||||
document.querySelector('.modal-body form').style.display = 'block';
|
<img src="${data.qr_code_url}" alt="QR Code" class="img-fluid" style="max-width: 250px; border: 2px solid #dee2e6; border-radius: 8px;">
|
||||||
document.getElementById('successSection').style.display = 'none';
|
</div>
|
||||||
}, 3000);
|
<div class="d-grid gap-2">
|
||||||
|
<a href="${data.registration_link}" target="_blank" class="btn btn-primary btn-lg">
|
||||||
|
<i class="fab fa-telegram-plane me-2"></i>
|
||||||
|
Открыть в Telegram
|
||||||
|
</a>
|
||||||
|
<button type="button" class="btn btn-outline-secondary" onclick="resetModal()" data-bs-dismiss="modal">
|
||||||
|
Закрыть
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.modal-body').appendChild(qrSection);
|
||||||
|
|
||||||
|
// Hide footer buttons
|
||||||
|
document.querySelector('.modal-footer').style.display = 'none';
|
||||||
|
|
||||||
|
} else if (data.status === 'existing_request') {
|
||||||
|
alert('У вас уже есть активная заявка на данную услугу. Проверьте ваш Telegram.');
|
||||||
} else {
|
} else {
|
||||||
alert('Ошибка при отправке заявки: ' + (data.message || 'Попробуйте позже'));
|
alert('Ошибка при создании заявки: ' + (data.error || 'Попробуйте позже'));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -473,6 +485,33 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Function to reset modal to initial state
|
||||||
|
function resetModal() {
|
||||||
|
const modal = document.getElementById('serviceModal');
|
||||||
|
const form = document.getElementById('serviceRequestForm');
|
||||||
|
const qrSection = document.getElementById('qrSection');
|
||||||
|
|
||||||
|
// Remove QR section if exists
|
||||||
|
if (qrSection) {
|
||||||
|
qrSection.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show form and hide success section
|
||||||
|
document.querySelector('.modal-body form').style.display = 'block';
|
||||||
|
document.getElementById('successSection').style.display = 'none';
|
||||||
|
|
||||||
|
// Show footer
|
||||||
|
document.querySelector('.modal-footer').style.display = 'flex';
|
||||||
|
|
||||||
|
// Reset form
|
||||||
|
form.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset modal when it's closed
|
||||||
|
document.getElementById('serviceModal').addEventListener('hidden.bs.modal', function () {
|
||||||
|
resetModal();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user