import type { TCachedLicense } from '@documenso/lib/types/license'; import { SUBSCRIPTION_CLAIM_FEATURE_FLAGS } from '@documenso/lib/types/subscription'; import { trpc } from '@documenso/trpc/react'; import { Badge } from '@documenso/ui/primitives/badge'; import { Button } from '@documenso/ui/primitives/button'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@documenso/ui/primitives/tooltip'; import { useToast } from '@documenso/ui/primitives/use-toast'; import { Trans, useLingui } from '@lingui/react/macro'; import { ArrowRightIcon, CheckCircle2Icon, EyeIcon, EyeOffIcon, KeyRoundIcon, Loader2Icon, RefreshCwIcon, XCircleIcon, } from 'lucide-react'; import { DateTime } from 'luxon'; import { useState } from 'react'; import { Link, useRevalidator } from 'react-router'; import { match } from 'ts-pattern'; import { CardMetric } from './metric-card'; type AdminLicenseCardProps = { licenseData: TCachedLicense | null; }; export const AdminLicenseCard = ({ licenseData }: AdminLicenseCardProps) => { const { t, i18n } = useLingui(); const [isLicenseKeyVisible, setIsLicenseKeyVisible] = useState(false); const { license } = licenseData || {}; if (!license) { return (
{licenseData?.requestedLicenseKey ? ( <>

Invalid License Key

{/* Don't need to hide invalid license keys. */}

{licenseData.requestedLicenseKey}

) : (

No License Configured

)} Learn more
); } const enabledFlags = Object.entries(license.flags).filter(([, enabled]) => enabled); return (

Documenso License

{match(license.status) .with('ACTIVE', () => ( Active )) .with('PAST_DUE', () => ( Past Due )) .with('EXPIRED', () => ( Expired )) .otherwise(() => null)}

License

{license.name}

Expires

{i18n.date(license.periodEnd, DateTime.DATE_MED)}

License Key

{isLicenseKeyVisible ? license.licenseKey : '•'.repeat(license.licenseKey.length)}

Features

{enabledFlags.length > 0 ? ( enabledFlags .map( ([flag]) => SUBSCRIPTION_CLAIM_FEATURE_FLAGS[ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions flag as keyof typeof SUBSCRIPTION_CLAIM_FEATURE_FLAGS ]?.label || flag, ) .join(', ') ) : ( No features enabled )}

); }; const AdminLicenseResyncButton = () => { const { t } = useLingui(); const { toast } = useToast(); const { revalidate } = useRevalidator(); const { mutate: resyncLicense, isPending: isResyncingLicense } = trpc.admin.license.resync.useMutation({ onSuccess: async () => { toast({ title: t`License synced`, }); await revalidate(); }, onError: () => { toast({ title: t`Failed to sync license`, variant: 'destructive', }); }, }); return ( Sync license from server ); };