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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | 40x 59x 40x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 12x 59x 12x 59x 59x 59x 59x 59x 59x 59x 40x 453x 59x | import { Box, Stack } from "@mui/material";
import { TermsOfService } from "@pages/TermsOfService";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { getTOSVersionDate } from "features/Merchants/MerchantSidePanel/helpers";
import GiveText from "@shared/Text/GiveText";
import { styled } from "@theme/v2/Provider";
import { checkoutScrollbarStyles } from "@sections/PayBuilder/Checkout/helpers";
import { AGREEMENT_CHECKBOX_PROVIDER } from "../constants";
import GiveCheckbox from "@shared/GiveCheckbox/GiveCheckbox";
import useHandleScroll from "@features/Merchants/MerchantSidePanel/hooks/useHandleScroll";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { WARNING_MESSAGE } from "@features/GiveOnboarding/pages/Agreement/Sign/const";
import GiveSignAgreementSection from "@components/Merchants/CreateMerchantPanel/modals/components/MerchantAgreement/GiveSignAgreementSection";
import { useAppSelector } from "@redux/hooks";
import { selectUser } from "@redux/slices/auth/auth";
import { useEffect } from "react";
import {
GiveAgreementContentProps,
GiveProviderAgreementContentProps,
} from "@features/Merchants/MerchantSidePanel/AgreementAndSnapshot/agreements.types";
import GiveDisclaimer from "@features/Merchants/MerchantSidePanel/components/GiveDisclaimer/GiveDisclaimer";
import { useAgreementStatus } from "../modals/hooks/useAgreementStatus";
import type { TMerchantAgreementPayload } from "@components/Merchants/CreateMerchantPanel/hooks/TMerchantAgreementPayload";
import {
getLocalSignatureFile,
parseMerchantAgreementPayload,
} from "./helpers";
import PublishedLegalContent from "@components/PublishedLegalContent/PublishedLegalContent";
import AgreementDocumentLoader from "@components/PublishedLegalContent/AgreementDocumentLoader";
import { usePublishedDocumentByType } from "@pages/AcquirerPortal/LegalDocuments/api/usePublishedDocumentByType";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
//AGREEMENT USED IN PROVIDER SIDE PANEL
const GiveAgreementContent = ({
merchantAgreementVersion,
merchantName,
isEnterprise,
enabledAgreementCheckbox,
inView,
onToggleAgreement,
agreementCheckboxText,
containerRef,
onScroll,
viewRef,
scrollButton,
tosMinHeight,
tosMaxHeight,
hasSignature,
publishedContent,
hasPublished,
signatureSection,
isSidepanel,
isResolving,
}: GiveAgreementContentProps & { isResolving?: boolean }) => {
return (
<>
{/* Terms of Service Scrollable Section */}
<TOSWrapper
data-testid="agreement"
ref={containerRef}
onScroll={onScroll}
hasSignature={Boolean(hasSignature)}
tosMinHeight={tosMinHeight}
tosMaxHeight={tosMaxHeight}
isSidepanel={isSidepanel}
>
{/* Acquirer's published prose (AGR001) shares this scroll container.
When the acquirer has published prose it REPLACES the hardcoded
legacy Terms of Service — otherwise the new version would stack on
top of the previous (hardcoded) one. The hardcoded copy remains the
fallback for providers with nothing published.
While we are still resolving whether a published document exists,
show a loader instead — otherwise the hardcoded fallback flashes
before the published prose resolves. */}
{isResolving ? (
<AgreementDocumentLoader />
) : (
<>
{publishedContent}
{!hasPublished && (
<TermsOfService
merchantAgreementVersion={merchantAgreementVersion}
merchantName={merchantName}
isEnterPrise={isEnterprise}
/>
)}
</>
)}
{/* Invisible div to detect bottom */}
<div ref={viewRef} />
{/* Scroll button */}
{scrollButton}
</TOSWrapper>
{/* Agreement Checkbox */}
<Stack gap="12px" flexDirection="row" alignItems="flex-start">
<Box>
<GiveTooltip
title={WARNING_MESSAGE}
color="default"
disableHoverListener={inView || enabledAgreementCheckbox}
placement="top-start"
alignment="top"
fluidWidth
>
<GiveCheckbox
data-testid="agreement-confirmation-checkbox"
checked={enabledAgreementCheckbox}
onChange={() => {
if (inView) {
onToggleAgreement();
}
}}
disabled={!inView}
/>
</GiveTooltip>
</Box>
<Box>
<GiveText color="secondary" variant="bodyS">
Agreement Confirmation
</GiveText>
<GiveText mt="4px" color="secondary" variant="bodyXS">
{agreementCheckboxText}
</GiveText>
</Box>
</Stack>
{signatureSection}
</>
);
};
const GiveProviderAgreementContent = ({
data,
addSignature,
onEnabledAgreementCheckboxChange,
tosMinHeight = "640px",
isOnboarding = false,
isSidepanel = false,
onAgreementInViewChange,
signatureSectionRef,
}: GiveProviderAgreementContentProps & {
onAgreementInViewChange?: (inView: boolean) => void;
signatureSectionRef?: React.RefObject<HTMLDivElement>;
}) => {
const { merchantID, merchantName } = data?.merchantInfo || {};
const { data: APIData } = useGetMerchantById(undefined, true);
const { globalName } = useAppSelector(selectUser);
// Whether the acquirer has published a Provider Agreement. When it has, the
// published prose REPLACES the hardcoded legacy Terms of Service (rather than
// stacking on top of it). Fetched with the current account's OWN accID — an
// acquirer reads its own documents; a provider reads its parent acquirer's
// published documents (the backend resolves the hierarchy) — the same
// derivation PublishedLegalContent uses, so the two share one query.
const { isDocumentManagementEnabled, isFeatureFlagLoading } =
useGetFeatureFlagValues();
const accountID = APIData?.accID;
const { data: publishedProviderDoc, isResolving: isDocResolving } =
usePublishedDocumentByType(accountID, "provider_agreement", {
enabled: isDocumentManagementEnabled,
});
const hasPublished =
!!isDocumentManagementEnabled && !!publishedProviderDoc?.content;
// Still determining whether a published Provider Agreement exists (flags
// resolving or the fetch in flight) — the content section shows a loader
// instead of flashing the hardcoded legacy Terms of Service.
const isResolving = !!isFeatureFlagLoading || isDocResolving;
const isSigned = data?.merchantAgreement?.msaHadAgreed;
const isUpToDateSignedVersion =
data?.merchantAgreement?.msaLastAcceptedVersion ===
data?.merchantAgreement?.tcVersion;
const {
scrollButton,
containerRef,
enabledAgreementCheckbox,
viewRef,
setEnabledAgreementCheckbox,
inView,
handleScroll,
} = useHandleScroll({
defaultHasAgreed: Boolean(isSigned && isUpToDateSignedVersion),
});
useEffect(() => {
onEnabledAgreementCheckboxChange?.(enabledAgreementCheckbox);
}, [enabledAgreementCheckbox, onEnabledAgreementCheckboxChange]);
// Notify parent when user reaches the bottom of the agreement
useEffect(() => {
onAgreementInViewChange?.(inView);
}, [inView, onAgreementInViewChange]);
// Get current user name for signature section
const currentUserName = globalName
? `${globalName.firstName} ${globalName.lastName}`
: "";
const signatureURL = data?.merchantAgreement?.signatureURL;
const localSignature = getLocalSignatureFile(
(data as any)?.merchantAgreement,
);
const rawAgreement = data?.merchantAgreement;
const merchantAgreement: TMerchantAgreementPayload =
parseMerchantAgreementPayload({
rawAgreement,
apiData: APIData,
signedByFallback: currentUserName,
tcVersion: APIData?.msaVersion || rawAgreement?.tcVersion,
});
// Use agreement status hook
const { status, renderSubtitle } = useAgreementStatus({
data: merchantAgreement,
APIData,
signatureFile: localSignature,
globalName,
});
return (
<>
<GiveDisclaimer
disclaimerType={status}
customTitle={`Provider Agreement`}
customDescription={renderSubtitle()}
/>
<GiveAgreementContent
merchantAgreementVersion={{
version: APIData?.msaVersion || "",
lastUpdated: getTOSVersionDate(APIData?.acquirerTcDate, true),
}}
merchantName={merchantName}
isEnterprise
enabledAgreementCheckbox={enabledAgreementCheckbox}
inView={inView}
onToggleAgreement={() =>
setEnabledAgreementCheckbox(!enabledAgreementCheckbox)
}
agreementCheckboxText={AGREEMENT_CHECKBOX_PROVIDER}
containerRef={containerRef}
onScroll={handleScroll}
viewRef={viewRef}
scrollButton={scrollButton}
tosMinHeight={tosMinHeight}
hasSignature={Boolean(signatureURL) || Boolean(localSignature)}
isSidepanel={isSidepanel}
isResolving={isResolving}
// Acquirer's published Provider Agreement prose (Q-A=a), passed inside
// the scroll container so it shares the agreement's independent scroll.
// Inset to match the Terms of Service (its Wrapper is padded 20px) so
// the prose doesn't run flush to the scroll container's left/right edges.
hasPublished={hasPublished}
publishedContent={
<PublishedLegalContent
type="provider_agreement"
sx={{ px: "20px", pt: "20px" }}
/>
}
signatureSection={
<Box mt={3} ref={signatureSectionRef}>
<GiveSignAgreementSection
addSignature={addSignature}
status={signatureURL || localSignature ? "signed" : "not_signed"}
merchantId={merchantID}
isEnterprise
isOnboarding={isOnboarding}
isSidepanel={isSidepanel}
canSign={enabledAgreementCheckbox}
file={localSignature}
data={{
...data,
merchantAgreement: merchantAgreement,
status: {
statusName: data?.status?.statusName || "pending",
},
}}
/>
</Box>
}
/>
</>
);
};
const TOSWrapper = styled(Box, {
shouldForwardProp: (prop) =>
prop !== "hasSignature" &&
prop !== "tosMinHeight" &&
prop !== "tosMaxHeight" &&
prop !== "isSidepanel",
})<{
hasSignature: boolean;
tosMinHeight?: string;
tosMaxHeight?: string;
isSidepanel?: boolean;
}>(({ theme, hasSignature, tosMinHeight, tosMaxHeight, isSidepanel }) => ({
width: "auto",
height: "100%",
minHeight: tosMinHeight ?? "400px",
maxHeight: tosMaxHeight ?? `calc(100vh - ${hasSignature ? 730 : 500}px)`,
overflowY: "scroll",
position: "relative",
border: isSidepanel ? "none" : `1px solid ${theme.palette.border?.primary}`,
marginTop: "20px",
borderRadius: "20px",
button: {
color: "white",
bottom: "24px",
position: "sticky",
},
backgroundColor: theme.palette.background.paper,
...checkoutScrollbarStyles,
scrollbarWidth: "auto",
"&::-webkit-scrollbar": {
...checkoutScrollbarStyles["&::-webkit-scrollbar"],
width: "14px",
backgroundColor: "transparent",
},
"&::-webkit-scrollbar-track": {
...checkoutScrollbarStyles["&::-webkit-scrollbar-track"],
backgroundColor: "transparent",
borderRadius: "20px !important",
marginTop: "20px",
marginBottom: "20px",
},
"&::-webkit-scrollbar-thumb": {
...checkoutScrollbarStyles["&::-webkit-scrollbar-thumb"],
backgroundColor: theme.palette.primitive?.neutral[50],
borderRadius: "10px",
minHeight: "68px",
border: "4px solid transparent",
backgroundClip: "content-box",
"&:hover": {
...(checkoutScrollbarStyles["&::-webkit-scrollbar-thumb"]?.["&:hover"] ||
{}),
backgroundColor: theme.palette.grey[300],
},
},
}));
export default GiveProviderAgreementContent;
|