/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useEffect, useMemo, useRef, useState } from 'react'; import { Banner, Button, Empty, Form, Select, Spin, Typography, } from '@douyinfe/semi-ui'; import { useTranslation } from 'react-i18next'; import CardPro from '../../components/common/ui/CardPro'; import CardTable from '../../components/common/ui/CardTable'; import CompactModeToggle from '../../components/common/ui/CompactModeToggle'; import { IllustrationNoResult, IllustrationNoResultDark, } from '../../components/common/illustrations'; import { createCardProPagination } from '../../helpers/utils'; import { useIsMobile } from '../../hooks/common/useIsMobile'; import { useTableCompactMode } from '../../hooks/common/useTableCompactMode'; import { fetchDemoReservations } from './reservationsApi'; const EMPTY_FILTERS = { name: '', contact: '', companyName: '' }; export default function DemoReservations() { const { t } = useTranslation(); const isMobile = useIsMobile(); const [compactMode, setCompactMode] = useTableCompactMode('demo-reservations'); const formRef = useRef(null); const [query, setQuery] = useState({ ...EMPTY_FILTERS, page: 1, pageSize: 10, }); const [result, setResult] = useState({ items: [], total: 0 }); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { let active = true; setLoading(true); setError(''); fetchDemoReservations(query) .then((data) => { if (active) setResult(data); }) .catch((error) => { if (active) { setError(error.message || '预约信息加载失败,请重新查询'); setResult({ items: [], total: 0 }); } }) .finally(() => { if (active) setLoading(false); }); return () => { active = false; }; }, [query]); const columns = useMemo( () => [ ['name', '姓名', 100], ['contact', '联系方式', 210], ['companyName', '公司名称', 180], ['position', '职位', 140], ['industry', '行业', 160], ['interest', '关注方向', 190], ['requirement', '需求', 360], ].map(([dataIndex, title, width]) => ({ title: t(title), dataIndex, key: dataIndex, ...(compactMode ? {} : { width }), render: (value) => dataIndex === 'requirement' && value ? (
{value}
) : ( {value || '—'} ), })), [t, compactMode], ); const reset = () => { formRef.current?.reset(); setQuery((previous) => ({ ...EMPTY_FILTERS, page: 1, pageSize: previous.pageSize, })); }; const changePageSize = (pageSize) => setQuery((previous) => ({ ...previous, page: 1, pageSize })); const pagination = createCardProPagination({ currentPage: result.page ?? query.page, pageSize: result.page_size ?? query.pageSize, total: result.total, onPageChange: (page) => setQuery((previous) => ({ ...previous, page })), onPageSizeChange: changePageSize, preventPageChangeOnPageSizeChange: true, isMobile, t, }); return (
{t('预约演示')} {t('查看官网访客提交的预约信息,支持模糊查询与分页。')}
} actionsArea={
(formRef.current = api)} onSubmit={(values) => setQuery((previous) => ({ name: (values.name || '').trim(), contact: (values.contact || '').trim(), companyName: (values.companyName || '').trim(), page: 1, pageSize: previous.pageSize, })) } allowEmpty autoComplete='off' layout='horizontal' className='w-full md:w-auto' >
{[ ['name', '请输入姓名'], ['contact', '请输入联系方式'], ['companyName', '请输入公司名称'], ].map(([field, placeholder]) => (
))}
} paginationArea={ isMobile && result.total > 0 ? (
{t('共')} {result.total} {t('条')}