import { type Admin, type ListAdminsRequest, services } from "@/services"; import type { ActionType, ProColumns, ProDescriptionsItemProps, } from "@ant-design/pro-components"; import { FooterToolbar, PageContainer, ProDescriptions, ProTable, } from "@ant-design/pro-components"; import { FormattedMessage, useIntl } from "@umijs/max"; import { Button, Drawer, message, Popconfirm } from "antd"; import React, { useCallback, useRef, useState } from "react"; import CreateForm from "./components/CreateForm"; import UpdateForm from "./components/UpdateForm"; type AdminQueryParams = { current?: number; pageSize?: number; name?: string; email?: string; phone?: string; }; const handleList = async (params: AdminQueryParams) => { const filters: string[] = []; if (params.name) { filters.push(`name="${params.name}"`); } if (params.email) { filters.push(`email="${params.email}"`); } if (params.phone) { filters.push(`phone="${params.phone}"`); } const requestParams: ListAdminsRequest = { pageSize: params.pageSize, pageToken: undefined, filter: filters.join(" AND ") || undefined, orderBy: undefined, }; const res = await services.admin.ListAdmins(requestParams); return { data: res.admins ?? [], success: true, }; }; const TableList: React.FC = () => { const actionRef = useRef(null); const [showDetail, setShowDetail] = useState(false); const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); const [deleteLoading, setDeleteLoading] = useState(false); const [messageApi, contextHolder] = message.useMessage(); const intl = useIntl(); /** * Delete node * * @param selectedRows */ const handleRemove = useCallback( async (selectedRows: Admin[]) => { try { setDeleteLoading(true); for (const row of selectedRows) { await services.admin.DeleteAdmin({ id: row.id }); } setSelectedRows([]); actionRef.current?.reloadAndRest?.(); messageApi.success("Deleted successfully and will refresh soon"); } catch { // Reporting is handled globally in requestErrorConfig. } finally { setDeleteLoading(false); } }, [messageApi] ); const columns: ProColumns[] = [ { title: ( ), dataIndex: "name", }, { title: ( ), dataIndex: "email", }, { title: ( ), dataIndex: "phone", }, { title: ( ), dataIndex: "access", }, { title: ( ), dataIndex: "createTime", valueType: "dateTime", }, { title: ( ), dataIndex: "updateTime", valueType: "dateTime", }, { title: ( ), dataIndex: "option", valueType: "option", render: (_, record) => [ } key="edit" onOk={actionRef.current?.reload} values={record} />, { handleRemove([record]); }} okText="Yes" cancelText="No" > , ], }, ]; return ( {contextHolder} headerTitle={intl.formatMessage({ id: "pages.searchTable.title", defaultMessage: "Enquiry form", })} actionRef={actionRef} rowKey="id" search={{ labelWidth: 120, }} toolBarRender={() => [ , ]} request={handleList} columns={columns} rowSelection={{ onChange: (_, selectedRows) => { setSelectedRows(selectedRows); }, }} /> {selectedRowsState?.length > 0 && ( {" "} {selectedRowsState.length}{" "} } > )} { setCurrentRow(undefined); setShowDetail(false); }} closable={false} > {currentRow?.name && ( column={2} title={currentRow?.name} request={async () => ({ data: currentRow || {}, })} params={{ id: currentRow?.name, }} columns={columns as ProDescriptionsItemProps[]} /> )} ); }; export default TableList;