From 1001911691c5322a0c90314e9f0238a91f294a4c Mon Sep 17 00:00:00 2001 From: g Date: Fri, 28 Nov 2025 20:04:57 +0000 Subject: [PATCH] Add Telegram Users admin page and sidebar link Introduces a new admin page for managing Telegram users, displaying user statistics and allowing user actions. Updates the admin sidebar to include a link to the new Telegram Users page. Also updates git-info.json with the latest build metadata. --- app/dashboard/admin/users/page.tsx | 223 +++++++++++++++++++++++++++++ config/admin-sidebar.ts | 3 +- public/git-info.json | 4 +- 3 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 app/dashboard/admin/users/page.tsx diff --git a/app/dashboard/admin/users/page.tsx b/app/dashboard/admin/users/page.tsx new file mode 100644 index 0000000..fd76af8 --- /dev/null +++ b/app/dashboard/admin/users/page.tsx @@ -0,0 +1,223 @@ +import React from "react"; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { Search, Ban, UserCheck, UserX, Package, DollarSign } from "lucide-react"; +import { fetchServer } from "@/lib/api"; + +interface TelegramUser { + telegramUserId: string; + telegramUsername: string; + totalOrders: number; + totalSpent: number; + paidOrders: number; + completedOrders: number; + firstOrderDate: string | null; + lastOrderDate: string | null; + isBlocked: boolean; + blockedReason: string | null; + createdAt?: string; +} + +function formatCurrency(amount: number): string { + return new Intl.NumberFormat('en-GB', { + style: 'currency', + currency: 'GBP', + }).format(amount); +} + +export default async function AdminUsersPage() { + let users: TelegramUser[] = []; + let error: string | null = null; + + try { + users = await fetchServer("/admin/users"); + } catch (err) { + console.error("Failed to fetch users:", err); + error = "Failed to load users"; + } + + if (error) { + return ( +
+
+

Telegram Users

+

Manage Telegram user accounts

+
+ + +
+

{error}

+
+
+
+
+ ); + } + + const usersWithOrders = users.filter(u => u.totalOrders > 0); + const blockedUsers = users.filter(u => u.isBlocked); + const totalSpent = users.reduce((sum, u) => sum + u.totalSpent, 0); + const totalOrders = users.reduce((sum, u) => sum + u.totalOrders, 0); + + return ( +
+
+

Telegram Users

+

Manage Telegram user accounts and view statistics

+
+ + {/* Stats Cards */} +
+ + + Total Users + + +
{users.length}
+

Registered users

+
+
+ + + Users with Orders + + +
{usersWithOrders.length}
+

+ {users.length > 0 ? Math.round((usersWithOrders.length / users.length) * 100) : 0}% conversion rate +

+
+
+ + + Total Revenue + + +
{formatCurrency(totalSpent)}
+

{totalOrders} total orders

+
+
+ + + Blocked Users + + +
{blockedUsers.length}
+

+ {users.length > 0 ? Math.round((blockedUsers.length / users.length) * 100) : 0}% blocked rate +

+
+
+
+ + {/* Search and Filters */} + + +
+
+ User Management + View and manage all Telegram user accounts +
+
+
+ + +
+
+
+
+ + + + + User ID + Username + Orders + Total Spent + Status + First Order + Last Order + Actions + + + + {users.map((user) => ( + + +
{user.telegramUserId}
+
+ +
+ {user.telegramUsername !== "Unknown" ? `@${user.telegramUsername}` : "Unknown"} +
+
+ +
+ + {user.totalOrders} + {user.completedOrders > 0 && ( + + {user.completedOrders} completed + + )} +
+
+ +
+ + {formatCurrency(user.totalSpent)} +
+
+ +
+ {user.isBlocked ? ( + + + Blocked + + ) : user.totalOrders > 0 ? ( + Active + ) : ( + No Orders + )} + {user.blockedReason && ( + {user.blockedReason} + )} +
+
+ + {user.firstOrderDate + ? new Date(user.firstOrderDate).toLocaleDateString() + : 'N/A'} + + + {user.lastOrderDate + ? new Date(user.lastOrderDate).toLocaleDateString() + : 'N/A'} + + +
+ {!user.isBlocked ? ( + + ) : ( + + )} +
+
+
+ ))} +
+
+
+
+
+ ); +} + diff --git a/config/admin-sidebar.ts b/config/admin-sidebar.ts index bdc3176..38a1743 100644 --- a/config/admin-sidebar.ts +++ b/config/admin-sidebar.ts @@ -1,4 +1,4 @@ -import { Home, Shield, Users, Ban, UserPlus, Package, BarChart3 } from "lucide-react" +import { Home, Shield, Users, Ban, UserPlus, Package, BarChart3, UserCircle } from "lucide-react" export const adminSidebarConfig = [ { @@ -12,6 +12,7 @@ export const adminSidebarConfig = [ title: "User Management", items: [ { name: "All Vendors", href: "/dashboard/admin/vendors", icon: Users }, + { name: "Telegram Users", href: "/dashboard/admin/users", icon: UserCircle }, { name: "Invite Vendor", href: "/dashboard/admin/invite", icon: UserPlus }, { name: "Ban Users", href: "/dashboard/admin/ban", icon: Ban }, ], diff --git a/public/git-info.json b/public/git-info.json index 6b43518..2c243cf 100644 --- a/public/git-info.json +++ b/public/git-info.json @@ -1,4 +1,4 @@ { - "commitHash": "f212859", - "buildTime": "2025-11-28T18:47:55.501Z" + "commitHash": "3548cc3", + "buildTime": "2025-11-28T20:00:38.186Z" } \ No newline at end of file