import type { Dispatch, SetStateAction } from 'react'; import { ActionIcon, Badge, Checkbox, Group, Text, Tooltip } from '@mantine/core'; import { IconLogout } from '@tabler/icons-react'; import type { TFunction } from 'i18next'; import type { AdvancedColumn } from '@ema-platform/ui'; import type { MySession } from '../../hooks/useSessions'; interface Opts { t: TFunction; sessions: MySession[]; selected: string[]; setSelected: Dispatch>; /** Undefined when the token carries no session claim — then no row is "this device". */ currentId?: string; showDate: (value: string) => string; onRevoke: (session: MySession) => void; } export function sessionColumns({ t, sessions, selected, setSelected, currentId, showDate, onRevoke, }: Opts): AdvancedColumn[] { // The current session is never selectable, so "all" means "all the others". const selectable = sessions.filter((s) => s.id !== currentId); const allSelected = selectable.length > 0 && selectable.every((s) => selected.includes(s.id)); return [ { header: ( 0 && !allSelected} disabled={selectable.length === 0} onChange={() => setSelected(allSelected ? [] : selectable.map((s) => s.id))} /> ), label: t('profile.sessions.select'), size: 40, cell: ({ row }) => { const isCurrent = row.original.id === currentId; return ( { const checked = e.currentTarget.checked; setSelected((prev) => checked ? [...prev, row.original.id] : prev.filter((id) => id !== row.original.id), ); }} /> ); }, }, { header: t('profile.sessions.columns.device'), cell: ({ row }) => ( {row.original.device || '—'} {row.original.id === currentId && ( {t('profile.sessions.thisDevice')} )} ), }, { header: t('profile.sessions.columns.signedIn'), cell: ({ row }) => {showDate(row.original.createdAt)}, }, { header: t('profile.sessions.columns.expires'), cell: ({ row }) => {showDate(row.original.expiryTime)}, }, { header: t('profile.sessions.columns.status'), cell: ({ row }) => ( {row.original.status} ), }, { header: t('profile.sessions.columns.actions'), size: 70, align: 'center', cell: ({ row }) => { const isCurrent = row.original.id === currentId; return (
onRevoke(row.original)} >
); }, }, ]; }