import type { TGetTeamAnalyticsTemplateUsageResponse } from '@documenso/trpc/server/team-router/get-team-analytics.types'; import { Button } from '@documenso/ui/primitives/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@documenso/ui/primitives/card'; import { Skeleton } from '@documenso/ui/primitives/skeleton'; import { useLingui } from '@lingui/react'; import { Plural, Trans } from '@lingui/react/macro'; import { FileTextIcon } from 'lucide-react'; import type { ReactNode } from 'react'; import { Link } from 'react-router'; import type { AnalyticsQueryResult } from '~/utils/analytics'; import { formatRelativeDate } from '~/utils/analytics'; import { AnalyticsQueryError } from './analytics-query-error'; /** The template shape shared by the team and organisation procedures. */ export type AnalyticsTemplate = TGetTeamAnalyticsTemplateUsageResponse['templates'][number]; export type AnalyticsTemplateUsageCardProps = { query: AnalyticsQueryResult<{ templates: TTemplate[] }>; /** Where the template title links to. Return null to render a plain title. */ getTemplateHref: (template: TTemplate) => string | null; /** Extra meta shown before the "Updated ..." label, e.g. the owning team name. */ renderTemplateMeta?: (template: TTemplate) => ReactNode; /** Link for the "View templates" button in the empty state. Omitted when there is no single templates page. */ templatesHref?: string; className?: string; }; export const AnalyticsTemplateUsageCard = ({ query, getTemplateHref, renderTemplateMeta, templatesHref, className, }: AnalyticsTemplateUsageCardProps) => { const { i18n } = useLingui(); const { data, isLoading, isError, refetch } = query; return ( Template usage Documents created from templates {isError ? ( ) : isLoading || !data ? (
    {Array.from({ length: 3 }, (_, index) => (
  • ))}
) : data.templates.length === 0 ? (

No documents were created from templates in this period

{templatesHref && ( )}
) : (
    {data.templates.map((template, index) => { const href = template.title === null ? null : getTemplateHref(template); const meta = renderTemplateMeta?.(template); return (
  1. {template.title === null ? ( Unavailable template ) : href !== null ? ( {template.title} ) : ( {template.title} )} {(meta || template.updatedAt !== null) && ( {meta} {meta && template.updatedAt !== null && ' ยท '} {template.updatedAt !== null && ( Updated {formatRelativeDate(template.updatedAt, i18n.locale)} )} )}
  2. ); })}
)}
); };