Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order mocking #45

Merged
merged 5 commits into from
Jul 29, 2024
Merged
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
133 changes: 132 additions & 1 deletion src/Pages/OrderStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,134 @@
import { useState } from 'react';
import { Typography, List, ListItem, ListItemText, Box, Paper, Container, TextField } from '@mui/material';

export const OrderStatus = () => {
return <p>Order status</p>;
const [orders] = useState([
{
id: 1,
user: { name: "Admin User 1" },
status: "APPROVED",
approvedDate: new Date().toISOString(),
request: {
products: [
{
product: { name: "Blue Whiteboard Marker" },
quantity: 5,
},
],
},
},
{
id: 2,
user: { name: "Admin User 2" },
status: "APPROVED",
approvedDate: new Date().toISOString(),
request: {
products: [
{
product: { name: "Red Whiteboard Marker" },
quantity: 10,
},
],
},
},
{
id: 3,
user: { name: "Admin User 3" },
status: "APPROVED",
approvedDate: new Date().toISOString(),
request: {
products: [
{
product: { name: "Green Whiteboard Marker" },
quantity: 3,
},
],
},
},
{
id: 4,
user: { name: "Admin User 4" },
status: "APPROVED",
approvedDate: new Date().toISOString(),
request: {
products: [
{
product: { name: "Black Whiteboard Marker" },
quantity: 7,
},
],
},
},
]);

const [searchTerm, setSearchTerm] = useState("");

const handleSearchChange = (event) => {
setSearchTerm(event.target.value);
};

const filteredOrders = orders.filter(order => {
const approvedDateString = new Date(order.approvedDate).toLocaleDateString();
return (
order.user.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
approvedDateString.includes(searchTerm) ||
order.request.products.some(product =>
product.product.name.toLowerCase().includes(searchTerm.toLowerCase())
)
);
});

return (
<Container maxWidth="md" style={{ marginTop: '2rem' }}>
<Typography variant="h3" gutterBottom style={{ fontWeight: 'bold', color: '#2c3e50' }}>
Order Status
</Typography>
<TextField
label="Search Orders"
value={searchTerm}
onChange={handleSearchChange}
fullWidth
style={{ marginBottom: '1rem' }}
/>
<Paper elevation={4} style={{ padding: '2rem', borderRadius: '12px', backgroundColor: '#ecf0f1' }}>
<List>
{filteredOrders.map((order) => (
<ListItem key={order.id} style={{ marginBottom: '1rem' }}>
<Box
sx={{
border: '1px solid #ccc',
borderRadius: '8px',
padding: '1rem',
width: '100%',
backgroundColor: '#ffffff',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
transition: 'transform 0.3s, box-shadow 0.3s',
'&:hover': {
transform: 'scale(1.03)',
boxShadow: '0 8px 16px rgba(0, 0, 0, 0.2)',
},
}}
>
<ListItemText
primary={`Order for ${order.request.products.map(product => `${product.product.name} (Quantity: ${product.quantity})`).join(', ')}`}
primaryTypographyProps={{ variant: 'h6', color: 'textPrimary' }}
secondary={
<>
<Typography component="span" variant="body2" color="textSecondary">
Status: {order.status} <br />
Approved by: {order.user.name} <br />
Approved on: {new Date(order.approvedDate).toLocaleDateString()}
</Typography>
</>
}
/>
</Box>
</ListItem>
))}
</List>
</Paper>
</Container>
);
};

export default OrderStatus;