'use client'; import Link from 'next/link'; import type { ColumnDef } from '@tanstack/react-table'; import { EllipsisIcon } from 'lucide-react'; import { getI18n } from 'react-i18next'; import type UserData from '@kit/session/types/user-data'; import { Avatar, AvatarFallback, AvatarImage } from '@kit/ui/avatar'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from '@kit/ui/dropdown-menu'; import { Tooltip, TooltipContent, TooltipTrigger } from '@kit/ui/tooltip'; import { DataTable } from '@/components/app/DataTable'; import If from '@/components/app/If'; type UserRow = { id: string; email: string | undefined; phone: string | undefined; createdAt: string; updatedAt: string | undefined; lastSignInAt: string | undefined; banDuration: string | undefined; data: UserData; }; const columns: ColumnDef[] = [ { header: '', id: 'avatar', size: 10, cell: ({ row }) => { const user = row.original; const data = user.data; const displayName = data?.displayName; const photoUrl = data?.photoUrl; const displayText = displayName ?? user.email ?? user.phone ?? ''; return ( {photoUrl ? : null} {displayText[0]} {displayText} ); }, }, { header: 'ID', id: 'id', size: 30, cell: ({ row }) => { const id = row.original.id; return ( {id} ); }, }, { header: 'Email', id: 'email', cell: ({ row }) => { const email = row.original.email; return ( {email} ); }, }, { header: 'Name', size: 50, id: 'displayName', cell: ({ row }) => { return row.original.data?.displayName ?? ''; }, }, { header: 'Created at', id: 'createdAt', cell: ({ row }) => { const date = new Date(row.original.createdAt); const i18n = getI18n(); const language = i18n.language ?? 'en'; const createdAtLabel = date.toLocaleDateString(language); return {createdAtLabel}; }, }, { header: 'Last sign in', id: 'lastSignInAt', cell: ({ row }) => { const lastSignInAt = row.original.lastSignInAt; if (!lastSignInAt) { return -; } const date = new Date(lastSignInAt); return {date.toLocaleString()}; }, }, { header: 'Status', id: 'status', cell: ({ row }) => { const banDuration = row.original.banDuration; if (!banDuration || banDuration === 'none') { return ( Active ); } return ( Banned ); }, }, { header: '', id: 'actions', cell: ({ row }) => { const user = row.original; const banDuration = row.original.banDuration; const isBanned = banDuration && banDuration !== 'none'; return (
Actions navigator.clipboard.writeText(user.id)} > Copy user ID Impersonate User Ban User Delete User Reactivate User
); }, }, ]; function UsersTable({ users, page, pageCount, perPage, }: React.PropsWithChildren<{ users: UserRow[]; pageCount: number; page: number; perPage: number; }>) { return ( ); } export default UsersTable;