import { MERCHANT_REPORT_TYPES_MAP } from '@ballerine/common'; import { Badge, ContentTooltip, TextWithNAFallback, WarningFilledSvg } from '@ballerine/ui'; import { createColumnHelper, RowData } from '@tanstack/react-table'; import dayjs from 'dayjs'; import timezone from 'dayjs/plugin/timezone'; import utc from 'dayjs/plugin/utc'; import { useMemo } from 'react'; import { ctw } from '@/common/utils/ctw/ctw'; import { TIdentityVerificationCheck } from '@/domains/identity-verification/fetchers'; import { titleCase } from 'string-ts'; dayjs.extend(utc); dayjs.extend(timezone); // https://tanstack.com/table/v8/docs/api/core/column-def#meta declare module '@tanstack/react-table' { interface ColumnMeta { conditional?: true; showColumn?: boolean; } } const columnHelper = createColumnHelper(); const SCAN_TYPES = { ONBOARDING: 'Onboarding', MONITORING: 'Monitoring', } as const; const REPORT_TYPE_TO_SCAN_TYPE = { [MERCHANT_REPORT_TYPES_MAP.MERCHANT_REPORT_T1]: SCAN_TYPES.ONBOARDING, [MERCHANT_REPORT_TYPES_MAP.ONGOING_MERCHANT_REPORT_T1]: SCAN_TYPES.MONITORING, } as const; export const useColumns = ({ isDemoAccount = false }) => { return useMemo(() => { const columns = [ columnHelper.accessor('firstName', { cell: info => { const firstName = info.getValue(); const lastName = info.row.original.lastName; const fullName = `${firstName} ${lastName}`; return (
{fullName}
); }, header: 'Full Name', }), columnHelper.accessor('data', { cell: ({ getValue }) => { const website = (getValue() as { website?: string })?.website || 'https://example.com'; return ( {website} ); }, header: 'Website', }), columnHelper.accessor('issues', { cell: info => { const issues = info.getValue() || []; // Mock issues if none exist const violations = issues.length > 0 ? issues : [ { id: 'issue-1', name: 'Suspicious activity detected', riskLevel: 'critical', }, { id: 'issue-2', name: 'Document verification failed', riskLevel: 'critical', }, { id: 'issue-3', name: 'Address mismatch', riskLevel: 'moderate', }, { id: 'issue-4', name: 'Identity information incomplete', riskLevel: 'moderate', }, { id: 'issue-5', name: 'Multiple verification attempts', riskLevel: 'moderate', }, ]; return (

Issues

{violations.slice(0, 4).map((violation, index) => (
{typeof violation === 'object' ? violation.name : violation}
))} {violations.length > 4 && (
+ {violations.length - 4} additional finding {violations.length - 4 > 1 ? 's' : ''}
)} } props={{ tooltipTrigger: { className: 'mx-auto pr-0' }, tooltipContent: { align: 'center', side: 'top', className: 'bg-background text-primary', }, }} >
typeof v === 'object' && v.riskLevel === 'critical', ), 'bg-slate-500/20 text-slate-500': !violations.some( v => typeof v === 'object' && v.riskLevel === 'critical', ), }, )} > {violations.length}
); }, header: () =>

Issues

, }), columnHelper.accessor('createdAt', { cell: info => { const displayDate = info.getValue(); // Convert UTC time to local browser time const localDateTime = dayjs.utc(displayDate).local(); const date = localDateTime.format('MMM DD, YYYY'); const time = localDateTime.format('HH:mm'); return (
{date} {time}
); }, header: 'Created At', }), columnHelper.accessor('checkId', { cell: info => { const checkId = info.getValue(); return {checkId}; }, header: 'Check ID', }), columnHelper.accessor('status', { cell: ({ getValue }) => { const status = getValue(); const statusToLabelMap = { pending: 'Pending', verified: 'Verified', rejected: 'Rejected', }; return (   {statusToLabelMap[status] ?? titleCase(status ?? '')} ); }, header: 'Status', }), ]; return columns.filter(column => { const meta = column.meta; if (meta?.conditional) { return meta.showColumn; } return true; }); }, [isDemoAccount]); };