Skip to content

Commit

Permalink
Order Item card update status
Browse files Browse the repository at this point in the history
  • Loading branch information
zntb committed Mar 4, 2024
1 parent 5c4bd31 commit 1ac8374
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/components/OrderItemCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Order } from '@/types';
import { Order, OrderStatus } from '@/types';
import { Card, CardContent, CardHeader, CardTitle } from './ui/card';
import { Separator } from './ui/separator';
import { Badge } from './ui/badge';
Expand All @@ -11,12 +11,29 @@ import {
SelectValue,
} from './ui/select';
import { ORDER_STATUS } from '@/config/order-status-config';
import { useUpdateMyRestaurantOrder } from '@/api/MyRestaurantApi';
import { useEffect, useState } from 'react';

type Props = {
order: Order;
};

const OrderItemCard = ({ order }: Props) => {
const { updateRestaurantStatus, isLoading } = useUpdateMyRestaurantOrder();
const [status, setStatus] = useState<OrderStatus>(order.status);

useEffect(() => {
setStatus(order.status);
}, [order.status]);

const handleStatusChange = async (newStatus: OrderStatus) => {
await updateRestaurantStatus({
orderId: order._id as string,
status: newStatus,
});
setStatus(newStatus);
};

const getTime = () => {
const orderDateTime = new Date(order.createdAt);

Expand Down Expand Up @@ -51,16 +68,16 @@ const OrderItemCard = ({ order }: Props) => {
<div>
Total Cost:
<span className="ml-2 font-normal">
£{(order.totalAmount / 100).toFixed(2)}
${(order.totalAmount / 100).toFixed(2)}
</span>
</div>
</CardTitle>
<Separator />
</CardHeader>
<CardContent className="flex flex-col gap-6">
<div className="flex flex-col gap-2">
{order.cartItems.map((cartItem) => (
<span>
{order.cartItems.map((cartItem, index) => (
<span key={index}>
<Badge variant="outline" className="mr-2">
{cartItem.quantity}
</Badge>
Expand All @@ -70,7 +87,11 @@ const OrderItemCard = ({ order }: Props) => {
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="status">What is the status of this order?</Label>
<Select>
<Select
value={status}
disabled={isLoading}
onValueChange={(value) => handleStatusChange(value as OrderStatus)}
>
<SelectTrigger id="status">
<SelectValue placeholder="Status" />
</SelectTrigger>
Expand Down

0 comments on commit 1ac8374

Please sign in to comment.