Fix sorting of order table, and keepOnline to thefront
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import { Inter } from "next/font/google"
|
import { Inter } from "next/font/google"
|
||||||
import "./globals.css"
|
import "./globals.css"
|
||||||
import { ThemeProvider } from "@/components/layout/theme-provider"
|
import { ThemeProvider } from "@/components/layout/theme-provider"
|
||||||
import type React from "react" // Import React
|
import type React from "react"
|
||||||
|
import KeepOnline from "@/components/KeepOnline"
|
||||||
|
|
||||||
const inter = Inter({ subsets: ["latin"] })
|
const inter = Inter({ subsets: ["latin"] })
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ export default function RootLayout({
|
|||||||
<html lang="en" suppressHydrationWarning>
|
<html lang="en" suppressHydrationWarning>
|
||||||
<body className={inter.className}>
|
<body className={inter.className}>
|
||||||
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem disableTransitionOnChange>
|
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem disableTransitionOnChange>
|
||||||
|
<KeepOnline />
|
||||||
{children}
|
{children}
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
24
components/KeepOnline.ts
Normal file
24
components/KeepOnline.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { clientFetch } from "@/lib/client-utils";
|
||||||
|
|
||||||
|
const KeepOnline = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
if(window.location.pathname.includes("/dashboard")){
|
||||||
|
const updateOnlineStatus = () => {
|
||||||
|
console.log("Updating online status...");
|
||||||
|
clientFetch("/auth/me");
|
||||||
|
}
|
||||||
|
|
||||||
|
updateOnlineStatus();
|
||||||
|
const interval = setInterval(updateOnlineStatus, 1000*60*1);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default KeepOnline;
|
||||||
@@ -37,11 +37,11 @@ interface Order {
|
|||||||
orderId: string;
|
orderId: string;
|
||||||
status: string;
|
status: string;
|
||||||
totalPrice: number;
|
totalPrice: number;
|
||||||
createdAt: string;
|
orderDate: Date;
|
||||||
telegramUsername?: string;
|
telegramUsername?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type SortableColumns = "orderId" | "totalPrice" | "status" | "createdAt";
|
type SortableColumns = "orderId" | "totalPrice" | "status" | "orderDate";
|
||||||
|
|
||||||
interface StatusConfig {
|
interface StatusConfig {
|
||||||
icon: React.ElementType;
|
icon: React.ElementType;
|
||||||
@@ -59,7 +59,7 @@ export default function OrderTable() {
|
|||||||
const [sortConfig, setSortConfig] = useState<{
|
const [sortConfig, setSortConfig] = useState<{
|
||||||
column: SortableColumns;
|
column: SortableColumns;
|
||||||
direction: "asc" | "desc";
|
direction: "asc" | "desc";
|
||||||
}>({ column: "createdAt", direction: "desc" });
|
}>({ column: "orderDate", direction: "desc" });
|
||||||
const [selectedOrders, setSelectedOrders] = useState<Set<string>>(new Set());
|
const [selectedOrders, setSelectedOrders] = useState<Set<string>>(new Set());
|
||||||
const ITEMS_PER_PAGE = 10;
|
const ITEMS_PER_PAGE = 10;
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ export default function OrderTable() {
|
|||||||
<TableHead className="cursor-pointer" onClick={() => handleSort("status")}>
|
<TableHead className="cursor-pointer" onClick={() => handleSort("status")}>
|
||||||
Status <ArrowUpDown className="ml-2 inline h-4 w-4" />
|
Status <ArrowUpDown className="ml-2 inline h-4 w-4" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="cursor-pointer" onClick={() => handleSort("createdAt")}>
|
<TableHead className="cursor-pointer" onClick={() => handleSort("orderDate")}>
|
||||||
Date <ArrowUpDown className="ml-2 inline h-4 w-4" />
|
Date <ArrowUpDown className="ml-2 inline h-4 w-4" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead>Buyer</TableHead>
|
<TableHead>Buyer</TableHead>
|
||||||
@@ -255,7 +255,7 @@ export default function OrderTable() {
|
|||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(order.createdAt).toLocaleDateString("en-GB")}
|
{new Date(order.orderDate).toLocaleDateString("en-GB")}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{order.telegramUsername ? `@${order.telegramUsername}` : "-"}
|
{order.telegramUsername ? `@${order.telegramUsername}` : "-"}
|
||||||
|
|||||||
Reference in New Issue
Block a user