2025-05-25 16:54:16 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
2025-05-25 16:25:22 +02:00
|
|
|
try {
|
2025-05-25 16:54:16 +02:00
|
|
|
const token = localStorage.getItem('token');
|
|
|
|
if (!token) {
|
2025-05-25 16:25:22 +02:00
|
|
|
window.location.href = '/login.html';
|
|
|
|
return;
|
|
|
|
}
|
2025-05-25 16:54:16 +02:00
|
|
|
|
|
|
|
const response = await fetch('/api/order-history', {
|
|
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
|
|
});
|
2025-05-25 16:25:22 +02:00
|
|
|
|
2025-05-25 16:54:16 +02:00
|
|
|
if (!response.ok) throw new Error('Błąd ładowania historii');
|
2025-05-25 16:25:22 +02:00
|
|
|
|
2025-05-25 16:54:16 +02:00
|
|
|
const orders = await response.json();
|
2025-05-25 16:25:22 +02:00
|
|
|
const container = document.getElementById('order-history');
|
2025-05-25 16:54:16 +02:00
|
|
|
container.innerHTML = '';
|
|
|
|
|
|
|
|
orders.forEach(order => {
|
|
|
|
const orderDate = new Date(order.data_zamowienia).toLocaleDateString();
|
|
|
|
const orderHTML = `
|
|
|
|
<div class="card dark-card mb-3">
|
|
|
|
<div class="card-body">
|
|
|
|
<h5 class="card-title">Zamówienie #${order.id}</h5>
|
|
|
|
<p class="card-text">Data: ${orderDate}</p>
|
|
|
|
<p class="card-text">Suma: ${order.suma_totalna} PLN</p>
|
|
|
|
<p class="card-text">Status: ${order.status || 'Przyjęto do realizacji'}</p>
|
|
|
|
</div>
|
2025-05-25 16:25:22 +02:00
|
|
|
</div>
|
2025-05-25 16:54:16 +02:00
|
|
|
`;
|
|
|
|
container.insertAdjacentHTML('beforeend', orderHTML);
|
|
|
|
});
|
|
|
|
|
2025-05-25 16:25:22 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Error:', error);
|
2025-05-25 16:54:16 +02:00
|
|
|
alert('Nie udało się załadować historii zamówień');
|
2025-05-25 16:25:22 +02:00
|
|
|
}
|
2025-05-25 16:54:16 +02:00
|
|
|
});
|