145 lines
3.6 KiB
TypeScript
145 lines
3.6 KiB
TypeScript
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<IForumComment>[] = [
|
|
{
|
|
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
|
|
? <Tag color="success">{t('forum.comment.status.1')}</Tag>
|
|
: <Tag color="error">{t('forum.comment.status.0')}</Tag>;
|
|
},
|
|
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<IForumComment> = {
|
|
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 (
|
|
<>
|
|
<div className="mb-5">
|
|
<Title level={3}>{t('forum.comment.page.title')}</Title>
|
|
<Text type="secondary">{t('forum.comment.page.description')}</Text>
|
|
</div>
|
|
<XinTable<IForumComment> {...tableProps} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Table;
|