import { useQuery } from "@tanstack/react-query"; import { Alert, Group, Loader, Modal, Text } from "@mantine/core"; import { Info } from "lucide-react"; import { contractsService } from "@/services/contracts.service"; interface ContractPreviewModalProps { opened: boolean; onClose: () => void; contractId: string; } /** * Live preview of the contract document. Renders server-side HTML, not the * stored PDF — the PDF is only produced once the final approver approves, so * before that this is the document. Served in an iframe so the contract's own * styles stay sandboxed away from the app. */ export function ContractPreviewModal({ opened, onClose, contractId, }: ContractPreviewModalProps) { const { data, isLoading, isError } = useQuery({ queryKey: ["contracts", contractId, "contract-view"], queryFn: () => contractsService.getContractView(contractId), enabled: opened, // The document changes as approvers edit it, so never serve a stale render. staleTime: 0, }); return ( } color="blue" variant="light" mb="sm" p="xs" > Draft preview. The PDF is generated automatically once the final approver approves. {isLoading ? ( Rendering document… ) : isError || !data?.html ? ( The document could not be rendered. Check that the contract has a template and try again. ) : (