Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | "use client";
import React, { useState } from "react";
import OrderActions from "./OrderActions";
import OrderModal from "./OrderModal";
import { formatCurrency } from "@/lib/core";
interface OrderItem {
id: string;
orderId: string;
createdAt: string;
status: "delivered" | "on-hold" | "processing" | string;
title: string;
total: string | number;
}
interface SingleOrderProps {
orderItem: OrderItem;
smallView?: boolean;
}
const SingleOrder: React.FC<SingleOrderProps> = ({ orderItem, smallView = false }) => {
const [showDetails, setShowDetails] = useState(false);
const [showEdit, setShowEdit] = useState(false);
const toggleDetails = () => {
setShowDetails((prev) => !prev);
};
const toggleEdit = () => {
setShowEdit((prev) => !prev);
};
const toggleModal = (status: boolean) => {
setShowDetails(status);
setShowEdit(status);
};
return (
<>
{!smallView && (
<div className="items-center justify-between border-t border-gray-3 py-5 px-7.5 hidden md:flex">
<div className="min-w-[111px]">
<p className="text-custom-sm text-red">#{orderItem.id.slice(-8)}</p>
</div>
<div className="min-w-[175px]">
<p className="text-custom-sm text-dark">{orderItem.createdAt}</p>
</div>
<div className="min-w-[128px]">
<p
className={`inline-block text-custom-sm py-0.5 px-2.5 rounded-[30px] capitalize ${orderItem.status === "delivered"
? "text-green bg-green-light-6"
: orderItem.status === "on-hold"
? "text-red bg-red-light-6"
: orderItem.status === "processing"
? "text-yellow bg-yellow-light-4"
: "Unknown Status"
}`}
>
{orderItem.status}
</p>
</div>
<div className="min-w-[213px]">
<p className="text-custom-sm text-dark">{orderItem.title}</p>
</div>
<div className="min-w-[113px]">
<p className="text-custom-sm text-dark">{formatCurrency(typeof orderItem.total === 'string' ? parseFloat(orderItem.total) : orderItem.total)}</p>
</div>
<div className="flex gap-5 items-center">
<OrderActions toggleDetails={toggleDetails} toggleEdit={toggleEdit} />
</div>
</div>
)}
{smallView && (
<div className="block md:hidden">
<div className="py-4.5 px-7.5">
<div>
<p className="text-custom-sm text-dark">
<span className="font-bold pr-2"> Order:</span> #{orderItem.id.slice(-8)}
</p>
</div>
<div>
<p className="text-custom-sm text-dark">
<span className="font-bold pr-2">Date:</span> {orderItem.createdAt}
</p>
</div>
<div>
<p className="text-custom-sm text-dark">
<span className="font-bold pr-2">Status:</span>{" "}
<span
className={`inline-block text-custom-sm py-0.5 px-2.5 rounded-[30px] capitalize ${orderItem.status === "delivered"
? "text-green bg-green-light-6"
: orderItem.status === "on-hold"
? "text-red bg-red-light-6"
: orderItem.status === "processing"
? "text-yellow bg-yellow-light-4"
: "Unknown Status"
}`}
>
{orderItem.status}
</span>
</p>
</div>
<div>
<p className="text-custom-sm text-dark">
<span className="font-bold pr-2">Title:</span> {orderItem.title}
</p>
</div>
<div>
<p className="text-custom-sm text-dark">
<span className="font-bold pr-2">Total:</span> {formatCurrency(typeof orderItem.total === 'string' ? parseFloat(orderItem.total) : orderItem.total)}
</p>
</div>
<div>
<p className="text-custom-sm text-dark flex items-center">
<span className="font-bold pr-2">Actions:</span>{" "}
<OrderActions toggleDetails={toggleDetails} toggleEdit={toggleEdit} />
</p>
</div>
</div>
</div>
)}
<OrderModal
showDetails={showDetails}
showEdit={showEdit}
toggleModal={toggleModal}
order={orderItem}
/>
</>
);
};
export default SingleOrder;
|