import { Tag, Typography } from 'antd'; import React from 'react'; import XinTable from '@/components/XinTable'; import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings'; import type IPrinter from '@/domain/iPrinter'; 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('merchant.printer.id'), dataIndex: 'id', hideInForm: true, sorter: true, align: 'center', width: 80, }, { title: t('merchant.printer.name'), dataIndex: 'name', valueType: 'text', align: 'center', required: true, rules: [{ required: true, message: t('merchant.printer.name.required') }], }, { title: t('merchant.printer.merchant_id'), dataIndex: 'merchant_id', valueType: 'text', align: 'center', required: true, }, { title: t('merchant.printer.brand'), dataIndex: 'brand', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('merchant.printer.model'), dataIndex: 'model', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('merchant.printer.device_no'), dataIndex: 'device_no', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('merchant.printer.secret_key'), dataIndex: 'secret_key', valueType: 'password', hideInTable: true, hideInSearch: true, }, { title: t('merchant.printer.status'), dataIndex: 'status', valueType: 'radioButton', fieldProps: { options: [ { value: 0, label: t('merchant.printer.status.0') }, { value: 1, label: t('merchant.printer.status.1') }, { value: 2, label: t('merchant.printer.status.2') }, ], }, render: (value: number) => { const colorMap: Record = { 0: 'default', 1: 'success', 2: 'error' }; const labelMap: Record = { 0: t('merchant.printer.status.0'), 1: t('merchant.printer.status.1'), 2: t('merchant.printer.status.2'), }; return {labelMap[value] || '-'}; }, filters: [ { text: t('merchant.printer.status.0'), value: 0 }, { text: t('merchant.printer.status.1'), value: 1 }, { text: t('merchant.printer.status.2'), value: 2 }, ], align: 'center', }, { title: t('merchant.printer.created_at'), hideInForm: true, hideInSearch: true, dataIndex: 'created_at', align: 'center', render: (value: string) => (value ? dayjs(value).fromNow() : '-'), }, { title: t('merchant.printer.updated_at'), hideInForm: true, hideInSearch: true, dataIndex: 'updated_at', align: 'center', render: (value: string) => (value ? dayjs(value).fromNow() : '-'), }, ]; const tableProps: XinTableProps = { api: '/merchant/printer', columns, rowKey: 'id', accessName: 'merchant.printer', 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('merchant.printer.page.title')} {t('merchant.printer.page.description')}
{...tableProps} /> ); }; export default Table;