import { memo, useMemo } from 'react'; import { __ } from '@wordpress/i18n'; import { useNavigate, useRouterState } from '@tanstack/react-router'; import { Block } from '@/components/Blocks/Block'; import { BlockHeading } from '@/components/Blocks/BlockHeading'; import { BlockContent } from '@/components/Blocks/BlockContent'; import Icon from '@/utils/Icon'; import { BarDataTable } from '@/components/DataTable/BarDataTable'; import { useFormsData } from './useFormsData'; import { getFormsColumns } from './columns'; import useLicenseData from '@/hooks/useLicenseData'; import UpsellOverlay from '@/components/Upsell/UpsellOverlay'; import UpsellCopy from '@/components/Upsell/UpsellCopy'; type FormsBlockProps = { /** Additional CSS class names passed to the wrapping Block. */ className?: string; }; /** Maximum rows shown in the compact block view. */ const TOP_N = 5; /** * Compact dashboard block showing the top performing forms by submissions. * * Displays form title, submission count with a proportional bar, and * conversion rate (submissions / unique visitors). An expand button opens * the full table in the DataTableOverlay. * * @param {Object} props - Component props. * @param {string} props.className - Additional CSS classes for the Block wrapper. * @return {JSX.Element} The forms block. */ const FormsBlock = memo( ({ className = '' }: FormsBlockProps ) => { const { isLicenseValid } = useLicenseData(); const { data, isLoading } = useFormsData(); const navigate = useNavigate(); const location = useRouterState({ select: ( s ) => s.location }); const columns = useMemo( () => getFormsColumns(), []); const topData = useMemo( () => data.slice( 0, TOP_N ), [ data ]); const hasData = 0 < topData.length; /** * Navigate to the fullscreen overlay with the forms variant active. */ const handleExpand = () => { navigate({ to: '/table/$variant', params: { variant: 'forms' }, search: { from: location.pathname, allowed: 'forms', dataTableId: 'forms', ...location.search } }); }; if ( ! isLicenseValid ) { return ( { __( 'Form tracking is a Pro feature.', 'burst-statistics' ) } ); } return ( { __( 'Forms', 'burst-statistics' ) } { hasData && ( ) } > } /> `${ row.formProvider }:${ row.formId }` } barColumnKey="submissions" isLoading={ isLoading } emptyState={ __( 'No form submissions recorded yet.', 'burst-statistics' ) } /> ); }); FormsBlock.displayName = 'FormsBlock'; export default FormsBlock;
{ __( 'Form tracking is a Pro feature.', 'burst-statistics' ) }