Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | 55x 55x 55x 55x 55x 55x 13x 42x 1x 41x 18x | import { Box, SxProps, Theme } from "@mui/material";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import DocumentViewer from "@pages/AcquirerPortal/LegalDocuments/LegalDocumentDetail/components/DocumentViewer";
import { usePublishedDocumentByType } from "@pages/AcquirerPortal/LegalDocuments/api/usePublishedDocumentByType";
import { TermsOfService } from "@pages/TermsOfService";
import AgreementLogoHeader from "./AgreementLogoHeader";
import AgreementDocumentLoader from "./AgreementDocumentLoader";
interface PublishedLegalContentProps {
/** Legal document type, e.g. "merchant_agreement", "provider_agreement". */
type: string;
/**
* Optional styles for the wrapper around the rendered prose. Applied only
* when there IS published content, so the "renders nothing when empty"
* guarantee is preserved. Used to align the prose with sibling content
* inside a shared scroll container (e.g. the provider agreement's Terms of
* Service, which is inset 20px).
*/
sx?: SxProps<Theme>;
/**
* Version + "Last updated" shown by the static (fe_static_merchant_agreement)
* rendering. Data-driven — the consumer supplies it from the merchant
* payload (tcVersion / tcVersionUpdatedAt), same as the legacy fallback
* surfaces. Ignored on the published path (no version chip there).
*/
merchantAgreementVersion?: { version: string; lastUpdated: string };
}
/**
* Renders the acquirer's published prose for a legal-document type above the
* existing data-driven agreement blocks. Renders nothing when there is no
* published content (or the viewer lacks read permission), so it is safe to
* drop into the existing agreement surfaces.
*
* Agreement types are not public, so the content is read from the
* authenticated legal-document endpoints keyed by the current account's OWN
* accID: an acquirer reads its own documents; a merchant/provider reads its
* parent acquirer's published documents (the backend resolves the hierarchy).
*/
export default function PublishedLegalContent({
type,
sx,
merchantAgreementVersion,
}: PublishedLegalContentProps) {
const {
isDocumentManagementEnabled,
isStaticMerchantAgreementEnabled,
isFeatureFlagLoading,
} = useGetFeatureFlagValues();
const { data: merchant } = useGetMerchantById();
const accountID = merchant?.accID;
// fe_static_merchant_agreement: render the hardcoded v3.5 merchant agreement
// (TermsOfServiceContentMerchant, incl. the fee-schedule tables) INSTEAD of
// the editor-published document. Merchant agreement only — the provider
// agreement and public docs keep the published path.
const useStaticAgreement =
isStaticMerchantAgreementEnabled && type === "merchant_agreement";
const { data, isResolving } = usePublishedDocumentByType(accountID, type, {
enabled: isDocumentManagementEnabled && !useStaticAgreement,
});
// Still determining whether there is a published document (flags resolving or
// the list/version fetch in flight) — show a loader so the hardcoded fallback
// in sibling agreement surfaces does not flash before the published prose.
if (isFeatureFlagLoading || isResolving)
return <AgreementDocumentLoader sx={sx} />;
if (useStaticAgreement) {
return (
<Box data-testid="static-merchant-agreement" sx={sx}>
{/* TermsOfService carries its own GiveCorporation logo header. Version
and date stay data-driven, supplied by the consumer (they come from
the merchant payload, same as the legacy fallback surfaces). */}
<TermsOfService
merchantAgreementVersion={merchantAgreementVersion}
isEnterPrise={false}
/>
</Box>
);
}
if (!isDocumentManagementEnabled || !data?.content) return null;
return (
<Box data-testid="published-legal-content" sx={sx}>
{/* GiveCorporation branding — the published prose replaces the hardcoded
Terms of Service (which carries this logo), so we render it here too so
every agreement, published or legacy, is branded. */}
<AgreementLogoHeader />
<DocumentViewer content={data.content} />
</Box>
);
}
|