diff --git a/components/users/UserTable.tsx b/components/users/UserTable.tsx index 36809d5..dd9b762 100644 --- a/components/users/UserTable.tsx +++ b/components/users/UserTable.tsx @@ -23,11 +23,13 @@ import { useReactTable, } from "@tanstack/react-table"; import { format } from "date-fns"; -import { LucideMessageCircle } from "lucide-react"; +import { Eye, EyeOff, LucideMessageCircle } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useMemo, useState } from "react"; import { DataTablePagination } from "../DataTablePagination"; import { Input } from "../ui/input"; +import Link from "next/link"; +import { Button } from "../ui/button"; const columns: ColumnDef[] = [ { @@ -35,7 +37,40 @@ const columns: ColumnDef[] = [ header: "User Id", cell: ({ row }) => { const value = row.getValue("user_id") as string; - return
{truncateEmail(value)}
; + const [showEmail, setShowEmail] = useState(false); + const toggleEmail = (event: any) => { + event.stopPropagation(); + setShowEmail(!showEmail); + }; + return ( +
+ +
+ + ) : ( +
+ {truncateEmail(value)}{" "} + +
+ )} + + {showEmail &&
{row.getValue("email")}
} + + ); }, }, { @@ -198,7 +233,7 @@ export function UserTable({ from, to }: UserTableProps) { className="h-8 px-2 lg:px-3" > Reset - + )} */} {/*
@@ -227,13 +262,13 @@ export function UserTable({ from, to }: UserTableProps) { >
*/} -
+
{table.getHeaderGroups().map((headerGroup) => ( @@ -269,7 +304,7 @@ export function UserTable({ from, to }: UserTableProps) { className="cursor-pointer hover:bg-gray-100" > {row.getVisibleCells().map((cell) => ( - + {flexRender( cell.column.columnDef.cell, cell.getContext() diff --git a/lib/utils.ts b/lib/utils.ts index 963a38a..b5b3c3c 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -6,6 +6,22 @@ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } +// export const truncateEmail = (email: string | null) => { +// if (!email) return ""; + +// if (!email.includes("@")) { +// return email; // return the original string if it doesn't look like an email +// } + +// const [local, domain] = email.split("@"); + +// let truncatedLocal = +// local.length <= 2 +// ? local +// : local[0] + "*".repeat(local.length - 2) + local[local.length - 1]; + +// return `${truncatedLocal}@${domain}`; +// }; export const truncateEmail = (email: string | null) => { if (!email) return ""; @@ -15,12 +31,15 @@ export const truncateEmail = (email: string | null) => { const [local, domain] = email.split("@"); - let truncatedLocal = - local.length <= 2 - ? local - : local[0] + "*".repeat(local.length - 2) + local[local.length - 1]; + const firstChar = local.slice(0, 1); + const lastChar = local.slice(-1); - return `${truncatedLocal}@${domain}`; + const truncatedLocal = firstChar + "*".repeat(local.length - 2) + lastChar; + const [domainName, domainExtension] = domain.split("."); + const domainFirstChar = domainName.slice(0, 1); + const truncatedDomainName = + domainFirstChar + "*".repeat(domainName.length - 1); + return `${truncatedLocal}@${truncatedDomainName}.${domainExtension}`; }; export const truncate = (str: string, length: number) => {