"use client"; import { ColumnDef } from "@tanstack/react-table"; import { Badge } from "@/components/shadcn"; import { DateWithTime } from "@/components/shadcn/entities"; import { DataTableColumnHeader } from "@/components/shadcn/table"; import { isCloud } from "@/lib/shared/env"; import { UserProps } from "@/types"; import { USER_SIGN_IN_METHOD, type UserSignInMethod, type UserSignInMethodType, } from "@/types/users"; import { DataTableRowActions } from "./data-table-row-actions"; const getUserData = (row: { original: UserProps }) => { return row.original.attributes; }; type NonSamlSignInMethodType = Exclude< UserSignInMethodType, typeof USER_SIGN_IN_METHOD.SAML >; const SIGN_IN_METHOD_LABELS = { [USER_SIGN_IN_METHOD.EMAIL_PASSWORD]: "Email/password", [USER_SIGN_IN_METHOD.GOOGLE]: "Google", [USER_SIGN_IN_METHOD.GITHUB]: "GitHub", [USER_SIGN_IN_METHOD.PARTNER_SSO]: "Partner SSO", } as const satisfies Record; const getSignInMethodLabel = (signInMethod: UserSignInMethod) => { if (signInMethod.method === USER_SIGN_IN_METHOD.SAML) { return signInMethod.domain ? `SAML (${signInMethod.domain})` : "SAML"; } return SIGN_IN_METHOD_LABELS[signInMethod.method]; }; export const getColumnsUser = ( isCloudEnvironment: boolean, ): ColumnDef[] => [ { accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => { const data = getUserData(row); return

{data?.name || "N/A"}

; }, }, { accessorKey: "email", header: ({ column }) => ( ), cell: ({ row }) => { const { email } = getUserData(row); return

{email}

; }, }, { accessorKey: "role", header: ({ column }) => ( ), cell: ({ row }) => { const { role } = getUserData(row); return

{role?.name || "No Role"}

; }, enableSorting: false, }, ...(isCloudEnvironment ? [ { id: "sign_in_methods", header: ({ column }) => ( ), cell: ({ row }) => { const { sign_in_methods: signInMethods } = getUserData(row); if (!signInMethods?.length) { return -; } return (
    {signInMethods.map((signInMethod) => (
  • {getSignInMethodLabel(signInMethod)}
  • ))}
); }, enableSorting: false, enableColumnFilter: false, } satisfies ColumnDef, ] : []), { accessorKey: "company_name", header: ({ column }) => ( ), cell: ({ row }) => { const { company_name } = getUserData(row); return

{company_name}

; }, }, { accessorKey: "date_joined", header: ({ column }) => ( ), cell: ({ row }) => { const { date_joined } = getUserData(row); return ; }, }, { accessorKey: "actions", header: () => null, id: "actions", cell: ({ row }) => { const roles = row.original.roles; return ; }, enableSorting: false, }, ]; export const ColumnsUser = getColumnsUser(isCloud());