Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions src/components/OrderComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import React, { useState, useMemo, useEffect } from 'react';
import {
Dialog,
Expand Down Expand Up @@ -33,21 +34,21 @@ const statusOptions = [
const getStatusColor = (status) => {
switch (status.toLowerCase()) {
case 'confirmed':
return '#0288d1'; // plava
return '#0288d1';
case 'rejected':
return '#d32f2f'; // crvena
return '#d32f2f';
case 'ready':
return '#388e3c'; // zelena
return '#388e3c';
case 'sent':
return '#fbc02d'; // žuta
return '#fbc02d';
case 'delivered':
return '#1976d2'; // tamno plava
return '#1976d2';
case 'cancelled':
return '#b71c1c'; // tamno crvena
return '#b71c1c';
case 'requested':
return '#757575'; // siva
return '#757575';
default:
return '#9e9e9e'; // fallback siva
return '#9e9e9e';
}
};

Expand All @@ -62,6 +63,8 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {
new Date(narudzba.time).toISOString().slice(0, 16)
);
const [products, setProducts] = useState(narudzba.proizvodi || []);
const [deliveryAddress] = useState(narudzba.deliveryAddress);
const [receivingAddress] = useState(narudzba.receivingAddress);

useEffect(() => {
const fetchMappings = async () => {
Expand All @@ -75,13 +78,8 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {
(u) => u.userName === narudzba.buyerId || u.email === narudzba.buyerId
);

if (storeEntry) {
setStoreId(storeEntry.id);
}

if (userEntry) {
setBuyerId(userEntry.id);
}
if (storeEntry) setStoreId(storeEntry.id);
if (userEntry) setBuyerId(userEntry.id);
};

fetchMappings();
Expand Down Expand Up @@ -110,7 +108,6 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {

if (!storeId) {
alert('Greška: Store ID nije validan.');
console.log(storeId);
return;
}

Expand All @@ -134,6 +131,8 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {
quantity: Number(p.quantity),
};
}),
deliveryAddressId: deliveryAddress?.id,
receivingAddressId: receivingAddress?.id,
};

const res = await apiUpdateOrderAsync(narudzba.id, payload);
Expand Down Expand Up @@ -163,7 +162,6 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {
},
}}
>
{/* Bubble Background */}
<Box
sx={{
position: 'absolute',
Expand Down Expand Up @@ -217,8 +215,6 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {
<DialogContent
sx={{ position: 'relative', zIndex: 1, px: 3, pt: 3, pb: 4 }}
>
{/* Bubble Background */}

<IconButton
onClick={onClose}
sx={{
Expand Down Expand Up @@ -356,6 +352,30 @@ const OrderComponent = ({ open, onClose, narudzba, onOrderUpdated }) => {
</Typography>
)}
</Box>

<Box display='flex' justifyContent='space-between' mb={1}>
<Typography color='text.secondary'>Delivery Address:</Typography>
<Box textAlign='right'>
<Typography fontWeight={600}>
{deliveryAddress?.address}
</Typography>
<Typography variant='caption' color='text.secondary'>
{deliveryAddress?.city}
</Typography>
</Box>
</Box>

<Box display='flex' justifyContent='space-between' mb={1}>
<Typography color='text.secondary'>Receiving Address:</Typography>
<Box textAlign='right'>
<Typography fontWeight={600}>
{receivingAddress?.address}
</Typography>
<Typography variant='caption' color='text.secondary'>
{receivingAddress?.city}
</Typography>
</Box>
</Box>
</Box>

<Divider sx={{ my: 2 }} />
Expand Down
32 changes: 24 additions & 8 deletions src/components/OrdersTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ const OrdersTable = ({
const formatOrderId = (id) => `#${String(id).padStart(5, '0')}`;

const columns = [
{ label: 'Order #', field: 'id' },
{ label: 'Buyer', field: 'buyerName' },
{ label: 'Store', field: 'storeName' },
{ label: 'Status', field: 'status' },
{ label: 'Total', field: 'totalPrice' },
{ label: 'Created', field: 'createdAt' },
{ label: '', field: 'actions' },
];
{ label: 'Order #', field: 'id' },
{ label: 'Buyer', field: 'buyerName' },
{ label: 'Store', field: 'storeName' },
{ label: 'Delivery Address', field: 'deliveryAddress' },
{ label: 'Receiving Address', field: 'receivingAddress' },
{ label: 'Status', field: 'status' },
{ label: 'Total', field: 'totalPrice' },
{ label: 'Created', field: 'createdAt' },
{ label: '', field: 'actions' },
];


return (
<TableContainer component={Paper} sx={{ borderRadius: 2 }}>
Expand Down Expand Up @@ -121,6 +124,14 @@ const OrdersTable = ({
</TableCell>
<TableCell>{order.buyerName}</TableCell>
<TableCell>{order.storeName}</TableCell>

<TableCell>
{order.deliveryAddress?.address ?? 'null'}, {order.deliveryAddress?.city ?? 'null'}
</TableCell>
<TableCell>
{order.receivingAddress?.address ?? 'null'}, {order.receivingAddress?.city ?? 'null'}
</TableCell>

<TableCell>
<Chip
label={order.status}
Expand Down Expand Up @@ -159,9 +170,14 @@ const OrdersTable = ({
</Tooltip>
</TableCell>
</TableRow>


))}
</TableBody>
</Table>



</TableContainer>
);
};
Expand Down