import { useState, useCallback } from 'react' import { trpc } from '@/trpc/client' export function UserConnectRoute() { const [search, setSearch] = useState('') const [searchInput, setSearchInput] = useState('') const [currentPage, setCurrentPage] = useState(1) const [visitedCursors, setVisitedCursors] = useState<(number | undefined)[]>([undefined]) const [itemsPerPage, setItemsPerPage] = useState(50) const cursor = visitedCursors[currentPage - 1] const { data, isLoading, error } = trpc.admin.user.getAllUsers.useQuery({ limit: itemsPerPage, cursor, search, }) const handleSearch = () => { setSearch(searchInput) setCurrentPage(1) setVisitedCursors([undefined]) } const handleNextPage = () => { if (data?.nextCursor) { const newCursors = [...visitedCursors] newCursors[currentPage] = data.nextCursor setVisitedCursors(newCursors) setCurrentPage(currentPage + 1) } } const handlePrevPage = () => { if (currentPage > 1) { setCurrentPage(currentPage - 1) } } const handlePageSelect = (page: number) => { setCurrentPage(page) } const handleClearSearch = () => { setSearch('') setSearchInput('') setCurrentPage(1) setVisitedCursors([undefined]) } const handleItemsPerPageChange = (newLimit: number) => { setItemsPerPage(newLimit) setCurrentPage(1) setVisitedCursors([undefined]) } const totalPages = Math.min(currentPage + (data?.hasMore ? 3 : 0), 20) const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1) if (isLoading) { return (
Loading users...
Error loading users: {error.message}
View all registered users and their contact information
Page {currentPage} • Showing {data?.users.length || 0} users
| ID | Name | Mobile | Total Orders | Last Order | Status |
|---|---|---|---|---|---|
| {user.id} | {user.name || '-'} | {user.mobile ? ( {user.mobile} ) : ( - )} | {user.totalOrders} | {user.lastOrderDate ? new Date(user.lastOrderDate).toLocaleDateString() : '-'} | {user.isSuspended ? ( Suspended ) : ( Active )} |
No users found
)}Page {currentPage} • Showing {data?.users.length || 0} users