import { useCallback, useEffect, useState } from 'react'; import { CheckCircle } from 'lucide-react'; import { Skeleton } from '../../../../components/ui/skeleton'; import { useAuthServiceContext } from '../../../../services/AuthService'; import { useBAAService } from '../../../../services/BAAService.tsx'; import { formatDayMonthYear } from '../../../../utils/dateUtils'; import type { MsaSummary } from '../../../../utils/msaAgreement'; import MsaAcceptForm from './MsaAcceptForm'; import { useMsaReadScope } from '../../../../hooks/useMsaOwnerEntry'; import { useOutletContext } from 'react-router-dom'; import type { MsaRecoveryOpening } from '../../../../hooks/useMsaRecovery'; import { MsaRecoveryAccess, MsaRecoveryPage } from './MsaRecovery'; // The owner's own place to read and accept the Master Subscription Agreement. It sits outside the Organization page, // which an owner without organization access cannot open, and it is the one practice page an overdue update leaves open. const FreshMsaAcceptPage = () => { const { wpOrganization } = useAuthServiceContext(); const { getBaa } = useBAAService(); const organizationId = wpOrganization.current?.id; const { key, start } = useMsaReadScope(organizationId); const [read, setRead] = useState<{ key: string; summary?: MsaSummary; failed: boolean }>(); const summary = read?.key === key ? read.summary : undefined; const failed = read?.key === key && read.failed; const [opening, setOpening] = useState(0); const load = useCallback(() => { setRead(undefined); setOpening((n) => n + 1); }, []); useEffect(() => { if (!organizationId) return undefined; const { operation, admit, belongs, transport } = start(); operation.step(() => getBaa(transport)) .then((record) => { admit(); setRead({ key, summary: record.msa, failed: !record.msa }); }) .catch(() => { if (belongs()) setRead({ key, failed: true }); }) .finally(() => operation.retire()); return () => operation.retire(); }, [getBaa, organizationId, opening, key, start]); const standing = summary?.standing; const unavailable = failed || standing?.state === 'unavailable'; return (
Accepted by the practice owner. It is separate from your Business Associate Agreement.
There is no Master Subscription Agreement to accept yet.
) : standing?.state === 'satisfied' ? (
{standing?.state === 'grace' ? 'MSA update available: accept by ' + formatDayMonthYear(standing.deadline) + '. Your existing MSA and Business Associate Agreement remain in place.' : summary.selected ? 'Updated agreement acceptance required. Your Business Associate Agreement is unchanged.' : 'Accept the Master Subscription Agreement before your practice signs its first Business Associate Agreement.'}