Latest changes
This commit is contained in:
@@ -59,36 +59,56 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Shared JS for compose (already in dashboard—keep if moved)
|
|
||||||
document.getElementById('composeForm')?.addEventListener('submit', async function(e) {
|
document.getElementById('composeForm')?.addEventListener('submit', async function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const status = document.getElementById('composeStatus');
|
const status = document.getElementById('composeStatus');
|
||||||
status.style.display = 'none';
|
status.style.display = 'none';
|
||||||
|
status.className = 'alert';
|
||||||
|
|
||||||
|
const to_call = document.getElementById('to_call').value.trim();
|
||||||
|
const text = document.getElementById('message_text').value.trim();
|
||||||
|
|
||||||
|
if (!to_call || !text) {
|
||||||
|
status.className = 'alert alert-danger';
|
||||||
|
status.textContent = 'Both To and Message fields are required.';
|
||||||
|
status.style.display = 'block';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const formData = new FormData(this);
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/v1/messages', {
|
const response = await fetch('/api/v1/messages', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
headers: {
|
||||||
credentials: 'include'
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
to_call: to_call,
|
||||||
|
text: text
|
||||||
|
}),
|
||||||
|
credentials: 'include' // sends Basic Auth
|
||||||
});
|
});
|
||||||
const result = await response.json();
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
status.className = 'alert alert-success';
|
status.className = 'alert alert-success';
|
||||||
status.textContent = 'Message sent successfully!';
|
status.textContent = 'Message sent successfully!';
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
this.reset();
|
this.reset();
|
||||||
setTimeout(() => bootstrap.Modal.getInstance(document.getElementById('composeModal')).hide(), 1500);
|
// Auto-close modal and refresh page to show new message
|
||||||
// Optional: refresh page after send
|
setTimeout(() => {
|
||||||
setTimeout(() => location.reload(), 2000);
|
const modal = bootstrap.Modal.getInstance(document.getElementById('composeModal'));
|
||||||
|
if (modal) modal.hide();
|
||||||
|
}, 1000);
|
||||||
|
setTimeout(() => location.reload(), 1500);
|
||||||
} else {
|
} else {
|
||||||
|
const errorData = await response.json();
|
||||||
status.className = 'alert alert-danger';
|
status.className = 'alert alert-danger';
|
||||||
status.textContent = result.detail || 'Failed to send message';
|
status.textContent = errorData.detail || 'Failed to send message';
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
status.className = 'alert alert-danger';
|
status.className = 'alert alert-danger';
|
||||||
status.textContent = 'Network error';
|
status.textContent = 'Network error – check connection';
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user