'use client'; import { ProTable, ProTableActions } from '@/components/pro-table'; import { createApplication, deleteApplication, getApplication, updateApplication, } from '@/services/admin/system'; import { Button } from '@workspace/ui/components/button'; import { ConfirmButton } from '@workspace/ui/custom-components/confirm-button'; import { useTranslations } from 'next-intl'; import Image from 'next/legacy/image'; import { useRef, useState } from 'react'; import { toast } from 'sonner'; import ConfigForm from './config'; import SubscribeAppForm from './form'; export default function SubscribeApp() { const t = useTranslations('product.app'); const [loading, setLoading] = useState(false); const ref = useRef(null); return ( > action={ref} header={{ title: t('appList'), toolbar: (
trigger={t('create')} title={t('createApp')} loading={loading} onSubmit={async (values) => { setLoading(true); try { await createApplication(values); toast.success(t('createSuccess')); ref.current?.refresh(); setLoading(false); return true; } catch (error) { setLoading(false); return false; } }} />
), }} request={async (_pagination, filters) => { const { data } = await getApplication(); return { list: data.data?.applications || [], total: 0, }; }} columns={[ { accessorKey: 'icon', header: t('appIcon'), cell: ({ row }) => ( {row.getValue('name')} ), }, { accessorKey: 'name', header: t('appName'), }, { accessorKey: 'subscribe_type', header: t('subscriptionProtocol'), cell: ({ row }) => row.getValue('subscribe_type'), }, ]} actions={{ render: (row) => [ key='edit' trigger={} title={t('editApp')} loading={loading} initialValues={{ ...row, }} onSubmit={async (values) => { setLoading(true); try { await updateApplication({ ...values, id: row.id, }); toast.success(t('updateSuccess')); ref.current?.refresh(); setLoading(false); return true; } catch (error) { setLoading(false); return false; } }} />, {t('delete')}} title={t('confirmDelete')} description={t('deleteWarning')} onConfirm={async () => { await deleteApplication({ id: row.id! }); toast.success(t('deleteSuccess')); ref.current?.refresh(); }} cancelText={t('cancel')} confirmText={t('confirm')} />, ], batchRender: (rows) => [ {t('batchDelete')}} title={t('confirmDelete')} description={t('deleteWarning')} onConfirm={async () => { await Promise.all(rows.map((row) => deleteApplication({ id: row.id! }))); toast.success(t('deleteSuccess')); ref.current?.reset(); }} cancelText={t('cancel')} confirmText={t('confirm')} />, ], }} /> ); }