Update header row
This commit is contained in:
@@ -316,7 +316,7 @@ const ProductGrid = ({
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ScrollArea className="h-full">
|
<div className="h-[calc(100%-3.5rem)]">
|
||||||
{loading && !products.length ? (
|
{loading && !products.length ? (
|
||||||
<LoadingState />
|
<LoadingState />
|
||||||
) : error ? (
|
) : error ? (
|
||||||
@@ -332,137 +332,154 @@ const ProductGrid = ({
|
|||||||
<p className="text-sm text-muted-foreground">Try selecting a different time range</p>
|
<p className="text-sm text-muted-foreground">Try selecting a different time range</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Table>
|
<div className="rounded-md border h-full">
|
||||||
<TableHeader>
|
<div className="overflow-y-auto h-full">
|
||||||
<TableRow className="hover:bg-transparent">
|
<table className="w-full">
|
||||||
{columnVisibility.image && (
|
<thead>
|
||||||
<TableHead className="w-[50px] min-w-[50px]" />
|
<tr className="hover:bg-transparent">
|
||||||
)}
|
{columnVisibility.image && (
|
||||||
{columnVisibility.name && (
|
<th className="p-1.5 text-left font-medium sticky top-0 bg-white dark:bg-background z-10 w-[50px] min-w-[50px] border-b" />
|
||||||
<TableHead className="min-w-[200px] pr-0 pl-1">
|
)}
|
||||||
<Button
|
{columnVisibility.name && (
|
||||||
variant="ghost"
|
<th className="p-1.5 text-left font-medium sticky top-0 bg-white dark:bg-background z-10 min-w-[200px] border-b">
|
||||||
onClick={() => handleSort("name")}
|
<button
|
||||||
className="h-8 justify-start w-full font-medium hover:bg-transparent"
|
onClick={() => handleSort("name")}
|
||||||
>
|
className={cn(
|
||||||
Product
|
"inline-flex items-center justify-start w-full px-2 py-1 text-sm font-medium transition-colors rounded-md",
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
sorting.column === "name"
|
||||||
</Button>
|
? "bg-primary text-primary-foreground"
|
||||||
</TableHead>
|
: "hover:bg-accent hover:text-accent-foreground"
|
||||||
)}
|
)}
|
||||||
{columnVisibility.totalQuantity && (
|
|
||||||
<TableHead className="text-right px-0">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => handleSort("totalQuantity")}
|
|
||||||
className="h-8 justify-end w-full font-medium hover:bg-transparent"
|
|
||||||
>
|
|
||||||
Sold
|
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</TableHead>
|
|
||||||
)}
|
|
||||||
{columnVisibility.totalRevenue && (
|
|
||||||
<TableHead className="text-right px-0">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => handleSort("totalRevenue")}
|
|
||||||
className="h-8 justify-end w-full font-medium hover:bg-transparent"
|
|
||||||
>
|
|
||||||
Rev
|
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</TableHead>
|
|
||||||
)}
|
|
||||||
{columnVisibility.orderCount && (
|
|
||||||
<TableHead className="text-right px-0">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => handleSort("orderCount")}
|
|
||||||
className="h-8 justify-end w-full font-medium hover:bg-transparent"
|
|
||||||
>
|
|
||||||
Orders
|
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</TableHead>
|
|
||||||
)}
|
|
||||||
{columnVisibility.price && (
|
|
||||||
<TableHead className="text-right hidden md:table-cell">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => handleSort("price")}
|
|
||||||
className="h-8 justify-end w-full font-medium hover:bg-transparent"
|
|
||||||
>
|
|
||||||
Price
|
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</TableHead>
|
|
||||||
)}
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{filteredProducts.map((product) => (
|
|
||||||
<TableRow
|
|
||||||
key={product.id}
|
|
||||||
className="group hover:bg-muted/50"
|
|
||||||
>
|
|
||||||
{columnVisibility.image && (
|
|
||||||
<TableCell className="w-[50px] p-1">
|
|
||||||
{product.ImgThumb && (
|
|
||||||
<img
|
|
||||||
src={product.ImgThumb}
|
|
||||||
alt=""
|
|
||||||
width={50}
|
|
||||||
height={50}
|
|
||||||
className="rounded bg-muted"
|
|
||||||
onError={(e) => (e.target.style.display = "none")}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
)}
|
|
||||||
{columnVisibility.name && (
|
|
||||||
<TableCell className="min-w-[200px] px-0">
|
|
||||||
<div className="flex flex-col min-w-0">
|
|
||||||
<a
|
|
||||||
href={`https://backend.acherryontop.com/product/${product.id}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="font-medium hover:underline line-clamp-2 text-gray-900 dark:text-gray-100"
|
|
||||||
>
|
>
|
||||||
{product.name}
|
Product
|
||||||
</a>
|
</button>
|
||||||
<div className="flex gap-2 text-sm text-muted-foreground px-0">
|
</th>
|
||||||
<span>${product.price.toFixed(2)}</span>
|
)}
|
||||||
</div>
|
{columnVisibility.totalQuantity && (
|
||||||
</div>
|
<th className="p-1.5 font-medium text-center sticky top-0 bg-white dark:bg-background z-10 border-b">
|
||||||
</TableCell>
|
<button
|
||||||
)}
|
onClick={() => handleSort("totalQuantity")}
|
||||||
{columnVisibility.totalQuantity && (
|
className={cn(
|
||||||
<TableCell className="text-center font-medium px-0">
|
"inline-flex items-center justify-center w-full px-2 py-1 text-sm font-medium transition-colors rounded-md",
|
||||||
{product.totalQuantity}
|
sorting.column === "totalQuantity"
|
||||||
</TableCell>
|
? "bg-primary text-primary-foreground"
|
||||||
)}
|
: "hover:bg-accent hover:text-accent-foreground"
|
||||||
{columnVisibility.totalRevenue && (
|
)}
|
||||||
<TableCell className="text-center text-emerald-600 dark:text-emerald-400 font-medium px-0">
|
>
|
||||||
${product.totalRevenue.toFixed(2)}
|
Sold
|
||||||
</TableCell>
|
</button>
|
||||||
)}
|
</th>
|
||||||
{columnVisibility.orderCount && (
|
)}
|
||||||
<TableCell className="text-center text-muted-foreground px-0">
|
{columnVisibility.totalRevenue && (
|
||||||
{product.orderCount}
|
<th className="p-1.5 font-medium text-center sticky top-0 bg-white dark:bg-background z-10 border-b">
|
||||||
</TableCell>
|
<button
|
||||||
)}
|
onClick={() => handleSort("totalRevenue")}
|
||||||
{columnVisibility.price && (
|
className={cn(
|
||||||
<TableCell className="text-center hidden md:table-cell px-0">
|
"inline-flex items-center justify-center w-full px-2 py-1 text-sm font-medium transition-colors rounded-md",
|
||||||
${product.price.toFixed(2)}
|
sorting.column === "totalRevenue"
|
||||||
</TableCell>
|
? "bg-primary text-primary-foreground"
|
||||||
)}
|
: "hover:bg-accent hover:text-accent-foreground"
|
||||||
</TableRow>
|
)}
|
||||||
))}
|
>
|
||||||
</TableBody>
|
Rev
|
||||||
</Table>
|
</button>
|
||||||
|
</th>
|
||||||
|
)}
|
||||||
|
{columnVisibility.orderCount && (
|
||||||
|
<th className="p-1.5 font-medium text-center sticky top-0 bg-white dark:bg-background z-10 border-b">
|
||||||
|
<button
|
||||||
|
onClick={() => handleSort("orderCount")}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center justify-center w-full px-2 py-1 text-sm font-medium transition-colors rounded-md",
|
||||||
|
sorting.column === "orderCount"
|
||||||
|
? "bg-primary text-primary-foreground"
|
||||||
|
: "hover:bg-accent hover:text-accent-foreground"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
Orders
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
|
)}
|
||||||
|
{columnVisibility.price && (
|
||||||
|
<th className="p-1.5 font-medium text-center sticky top-0 bg-white dark:bg-background z-10 hidden md:table-cell border-b">
|
||||||
|
<button
|
||||||
|
onClick={() => handleSort("price")}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center justify-center w-full px-2 py-1 text-sm font-medium transition-colors rounded-md",
|
||||||
|
sorting.column === "price"
|
||||||
|
? "bg-primary text-primary-foreground"
|
||||||
|
: "hover:bg-accent hover:text-accent-foreground"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
Price
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-gray-200 dark:divide-gray-800">
|
||||||
|
{filteredProducts.map((product) => (
|
||||||
|
<tr
|
||||||
|
key={product.id}
|
||||||
|
className="hover:bg-muted/50 transition-colors"
|
||||||
|
>
|
||||||
|
{columnVisibility.image && (
|
||||||
|
<td className="p-1.5 align-middle w-[50px]">
|
||||||
|
{product.ImgThumb && (
|
||||||
|
<img
|
||||||
|
src={product.ImgThumb}
|
||||||
|
alt=""
|
||||||
|
width={50}
|
||||||
|
height={50}
|
||||||
|
className="rounded bg-muted"
|
||||||
|
onError={(e) => (e.target.style.display = "none")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
{columnVisibility.name && (
|
||||||
|
<td className="p-1.5 align-middle min-w-[200px]">
|
||||||
|
<div className="flex flex-col min-w-0">
|
||||||
|
<a
|
||||||
|
href={`https://backend.acherryontop.com/product/${product.id}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="font-sm hover:underline line-clamp-2 text-gray-900 dark:text-gray-100"
|
||||||
|
>
|
||||||
|
{product.name}
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
{columnVisibility.totalQuantity && (
|
||||||
|
<td className="p-1.5 align-middle text-center font-medium">
|
||||||
|
{product.totalQuantity}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
{columnVisibility.totalRevenue && (
|
||||||
|
<td className="p-1.5 align-middle text-center text-emerald-600 dark:text-emerald-400 font-medium">
|
||||||
|
${product.totalRevenue.toFixed(2)}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
{columnVisibility.orderCount && (
|
||||||
|
<td className="p-1.5 align-middle text-center text-muted-foreground">
|
||||||
|
{product.orderCount}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
{columnVisibility.price && (
|
||||||
|
<td className="p-1.5 align-middle text-center hidden md:table-cell">
|
||||||
|
${product.price.toFixed(2)}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</ScrollArea>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user