import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; import dayjs from 'dayjs'; import relativeTime from 'dayjs/plugin/relativeTime'; import { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import RoundedImage from '~/components/common/rounded_image'; import TextEllipsis from '~/components/common/text_ellipsis'; import ContentLayout from '~/components/layouts/content_layout'; import { DATE_FORMAT } from '~/constants'; import { sortByCreationDate } from '~/lib/array'; import { UserWithRelationCount } from '~/types/app'; dayjs.extend(relativeTime); interface AdminDashboardProps { users: UserWithRelationCount[]; totalCollections: number; totalLinks: number; } const Cell = styled.div<{ column?: boolean; fixed?: boolean }>( ({ column, fixed }) => ({ width: '100%', display: 'flex', alignItems: 'center', justifyContent: fixed ? 'unset' : 'center', gap: column ? 0 : '0.35em', flexDirection: column ? 'column' : 'row', }) ); const ThemeProvider = (props: AdminDashboardProps) => ( ); export default ThemeProvider; function AdminDashboard({ users, totalCollections, totalLinks, }: AdminDashboardProps) { const { t } = useTranslation(); const theme = useTheme(); return (
#{t('common:name')}{t('common:email')} {t('common:collection.collections', { count: totalCollections })}{' '} ({totalCollections}) {t('common:link.links', { count: totalLinks })}{' '} ({totalLinks}) {t('admin:role')}{t('admin:created_at')}{t('admin:updated_at')} {users.length !== 0 && sortByCreationDate(users).map((user) => ( ))}
); } function TableUserRow({ user }: { user: UserWithRelationCount }) { const { t } = useTranslation(); const theme = useTheme(); const { id, fullname, avatarUrl, email, isAdmin, createdAt, updatedAt } = user; return ( {id} {avatarUrl && ( )} {fullname ?? '-'} {email} {user.count.collection} {user.count.link} {isAdmin ? ( {t('admin:admin')} ) : ( {t('admin:user')} )} {dayjs(createdAt.toString()).fromNow()} {dayjs(createdAt.toString()).format(DATE_FORMAT)} {dayjs(updatedAt.toString()).fromNow()} {dayjs(updatedAt.toString()).format(DATE_FORMAT)} ); } type TableItem = { children: ReactNode; type: 'td' | 'th'; fixed?: boolean; column?: boolean; }; function TableCell({ children, type, ...props }: TableItem) { const child = {children}; return type === 'td' ? {child} : {child}; }