From 7ec17cfd7382128009adbdcf543b81ad116faec5 Mon Sep 17 00:00:00 2001 From: g Date: Sun, 9 Feb 2025 01:43:24 +0000 Subject: [PATCH] Fix sorting of order table, and keepOnline to thefront --- app/layout.tsx | 4 +++- components/KeepOnline.ts | 24 ++++++++++++++++++++++++ components/tables/order-table.tsx | 10 +++++----- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 components/KeepOnline.ts diff --git a/app/layout.tsx b/app/layout.tsx index bd2e76d..95d1d0e 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,7 +1,8 @@ import { Inter } from "next/font/google" import "./globals.css" 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"] }) @@ -19,6 +20,7 @@ export default function RootLayout({ + {children} diff --git a/components/KeepOnline.ts b/components/KeepOnline.ts new file mode 100644 index 0000000..b4dc4ce --- /dev/null +++ b/components/KeepOnline.ts @@ -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; \ No newline at end of file diff --git a/components/tables/order-table.tsx b/components/tables/order-table.tsx index 5220cbe..3560806 100644 --- a/components/tables/order-table.tsx +++ b/components/tables/order-table.tsx @@ -37,11 +37,11 @@ interface Order { orderId: string; status: string; totalPrice: number; - createdAt: string; + orderDate: Date; telegramUsername?: string; } -type SortableColumns = "orderId" | "totalPrice" | "status" | "createdAt"; +type SortableColumns = "orderId" | "totalPrice" | "status" | "orderDate"; interface StatusConfig { icon: React.ElementType; @@ -59,7 +59,7 @@ export default function OrderTable() { const [sortConfig, setSortConfig] = useState<{ column: SortableColumns; direction: "asc" | "desc"; - }>({ column: "createdAt", direction: "desc" }); + }>({ column: "orderDate", direction: "desc" }); const [selectedOrders, setSelectedOrders] = useState>(new Set()); const ITEMS_PER_PAGE = 10; @@ -213,7 +213,7 @@ export default function OrderTable() { handleSort("status")}> Status - handleSort("createdAt")}> + handleSort("orderDate")}> Date Buyer @@ -255,7 +255,7 @@ export default function OrderTable() { - {new Date(order.createdAt).toLocaleDateString("en-GB")} + {new Date(order.orderDate).toLocaleDateString("en-GB")} {order.telegramUsername ? `@${order.telegramUsername}` : "-"}