122 lines
3.4 KiB
TypeScript
122 lines
3.4 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 IMerchantCategory from '@/domain/iMerchantCategory';
|
|
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<IMerchantCategory>[] = [
|
|
{
|
|
title: t('merchant.category.id'),
|
|
dataIndex: 'id',
|
|
hideInForm: true,
|
|
sorter: true,
|
|
align: 'center',
|
|
width: 80,
|
|
},
|
|
{
|
|
title: t('merchant.category.name'),
|
|
dataIndex: 'name',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
required: true,
|
|
rules: [{ required: true, message: t('merchant.category.name.required') }],
|
|
},
|
|
{
|
|
title: t('merchant.category.slug'),
|
|
dataIndex: 'slug',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
required: true,
|
|
rules: [{ required: true, message: t('merchant.category.slug.required') }],
|
|
},
|
|
{
|
|
title: t('merchant.category.description'),
|
|
dataIndex: 'description',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
hideInSearch: true,
|
|
},
|
|
{
|
|
title: t('merchant.category.sort'),
|
|
dataIndex: 'sort',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
hideInSearch: true,
|
|
},
|
|
{
|
|
title: t('merchant.category.status'),
|
|
dataIndex: 'status',
|
|
valueType: 'radioButton',
|
|
fieldProps: {
|
|
options: [
|
|
{ value: 0, label: t('merchant.category.status.0') },
|
|
{ value: 1, label: t('merchant.category.status.1') },
|
|
],
|
|
},
|
|
render: (value: number) => {
|
|
return value === 1
|
|
? <Tag color="success">{t('merchant.category.status.1')}</Tag>
|
|
: <Tag color="error">{t('merchant.category.status.0')}</Tag>;
|
|
},
|
|
filters: [
|
|
{ text: t('merchant.category.status.0'), value: 0 },
|
|
{ text: t('merchant.category.status.1'), value: 1 },
|
|
],
|
|
align: 'center',
|
|
},
|
|
{
|
|
title: t('merchant.category.created_at'),
|
|
hideInForm: true,
|
|
hideInSearch: true,
|
|
dataIndex: 'created_at',
|
|
align: 'center',
|
|
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
|
|
},
|
|
{
|
|
title: t('merchant.category.updated_at'),
|
|
hideInForm: true,
|
|
hideInSearch: true,
|
|
dataIndex: 'updated_at',
|
|
align: 'center',
|
|
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
|
|
},
|
|
];
|
|
|
|
const tableProps: XinTableProps<IMerchantCategory> = {
|
|
api: '/merchant/category',
|
|
columns,
|
|
rowKey: 'id',
|
|
accessName: 'merchant.category',
|
|
formProps: {
|
|
grid: true,
|
|
colProps: { span: 12 },
|
|
rowProps: { gutter: [30, 0] },
|
|
layout: 'vertical',
|
|
},
|
|
modalProps: { width: 600 },
|
|
cardProps: { variant: 'borderless' },
|
|
pagination: { size: 'small', style: { marginBottom: 0 } },
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className="mb-5">
|
|
<Title level={3}>{t('merchant.category.page.title')}</Title>
|
|
<Text type="secondary">{t('merchant.category.page.description')}</Text>
|
|
</div>
|
|
<XinTable<IMerchantCategory> {...tableProps} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Table;
|