import { useEffect, useMemo, useState } from 'react'; import { ArrowLeft } from 'lucide-react'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '../../../../components/ui/dialog'; import { DismissibleAlert } from '../../../../components/ui/dismissible-alert'; import { usePublicFormService } from '../../../../services/PublicFormService.tsx'; import { describePublicFormChanges, PublicFormSnapshot } from '../../../../utils/publicFormChanges.ts'; import { EmptyState } from '../../../../components/ui/empty-state'; interface Props { formHandle: string; draft: PublicFormSnapshot; publishing: boolean; error?: string; onBack: () => void; onClose?: () => void; onConfirm: () => void; } const VERB = { added: 'Added', removed: 'Removed', changed: 'Changed' } as const; export function PublishedFormUpdateReview({ formHandle, draft, publishing, error, onBack, onClose, onConfirm }: Props) { const { getPublishedSnapshot } = usePublicFormService(); const [live, setLive] = useState(); const [readFailed, setReadFailed] = useState(false); const [attempt, setAttempt] = useState(0); useEffect(() => { let current = true; setLive(undefined); setReadFailed(false); getPublishedSnapshot(formHandle) .then((snapshot) => current && setLive(snapshot)) .catch(() => current && setReadFailed(true)); return () => { current = false; }; }, [formHandle, attempt, getPublishedSnapshot]); const changes = useMemo(() => (live ? describePublicFormChanges(live, draft) : []), [live, draft]); return ( { if (!open) (onClose ?? onBack)(); }}> Update published form?
{error && (
{error}
)}

{draft.title}

{readFailed ? ( The published version could not be read, so the changes cannot be shown. Nothing has been updated.
) : !live ? (

Comparing with the published version...

) : changes.length === 0 ? ( ) : (
    {changes.map((change, index) => (
  • {VERB[change.kind]}: {change.label} {change.details.length > 0 && ( {change.details.join('; ')} )}
  • ))}
)}

This updates the form wherever it is already embedded. Existing submissions are retained. It does not create, edit or publish a WordPress page.

); }