import { Tag, Typography } from 'antd'; import React from 'react'; import XinTable from '@/components/XinTable'; import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings'; import type IForumComment from '@/domain/iForumComment'; import { useTranslation } from 'react-i18next'; import dayjs from 'dayjs'; import relativeTime from 'dayjs/plugin/relativeTime'; const { Title, Text } = Typography; dayjs.extend(relativeTime); const Table: React.FC = () => { const { t } = useTranslation(); const columns: XinTableColumn[] = [ { title: t('forum.comment.id'), dataIndex: 'id', hideInForm: true, sorter: true, align: 'center', width: 80, }, { title: t('forum.comment.post_id'), dataIndex: 'post_id', valueType: 'text', align: 'center', required: true, }, { title: t('forum.comment.user_id'), dataIndex: 'user_id', valueType: 'text', align: 'center', required: true, hideInSearch: true, }, { title: t('forum.comment.parent_id'), dataIndex: 'parent_id', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('forum.comment.reply_to'), dataIndex: 'reply_to', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('forum.comment.content'), dataIndex: 'content', valueType: 'text', hideInTable: true, hideInSearch: true, required: true, rules: [{ required: true, message: t('forum.comment.content.required') }], }, { title: t('forum.comment.like_count'), dataIndex: 'like_count', hideInForm: true, hideInSearch: true, align: 'center', }, { title: t('forum.comment.status'), dataIndex: 'status', valueType: 'radioButton', fieldProps: { options: [ { value: 0, label: t('forum.comment.status.0') }, { value: 1, label: t('forum.comment.status.1') }, ], }, render: (value: number) => { return value === 1 ? {t('forum.comment.status.1')} : {t('forum.comment.status.0')}; }, filters: [ { text: t('forum.comment.status.0'), value: 0 }, { text: t('forum.comment.status.1'), value: 1 }, ], align: 'center', }, { title: t('forum.comment.created_at'), hideInForm: true, hideInSearch: true, dataIndex: 'created_at', align: 'center', render: (value: string) => (value ? dayjs(value).fromNow() : '-'), }, { title: t('forum.comment.updated_at'), hideInForm: true, hideInSearch: true, dataIndex: 'updated_at', align: 'center', render: (value: string) => (value ? dayjs(value).fromNow() : '-'), }, ]; const tableProps: XinTableProps = { api: '/forum/comment', columns, rowKey: 'id', accessName: 'forum.comment', scroll: { x: 1200 }, formProps: { grid: true, colProps: { span: 12 }, rowProps: { gutter: [30, 0] }, layout: 'vertical', }, modalProps: { width: 700, }, cardProps: { variant: 'borderless', }, pagination: { size: 'small', style: { marginBottom: 0 }, }, }; return ( <>
{t('forum.comment.page.title')} {t('forum.comment.page.description')}
{...tableProps} /> ); }; export default Table;