From 56fd4d17659d85137e9f47e4619577574b2c0879 Mon Sep 17 00:00:00 2001 From: LauraPinilla <54566275+LauraPinilla@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:53:03 -0600 Subject: [PATCH] Fix paywall Issue (#1824) * fixing ArcP.run * attending feedback * attending feedback * attending feedback * attending feedback * attending feedback --- .../components/usePaywall.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/blocks/subscriptions-block/components/usePaywall.js b/blocks/subscriptions-block/components/usePaywall.js index 45f975858f..bc319940aa 100644 --- a/blocks/subscriptions-block/components/usePaywall.js +++ b/blocks/subscriptions-block/components/usePaywall.js @@ -21,7 +21,6 @@ const usePaywall = () => { const { Identity, isInitialized: isIdentityInitialized } = useIdentity(); // eslint-disable-next-line no-underscore-dangle - const rules = (!isServerSide() && window?.ArcP?._rules) || []; const apiOrigin = api?.retail?.origin; useEffect(() => { @@ -45,7 +44,7 @@ const usePaywall = () => { setIsPaywalled(true); }, section: globalContent.taxonomy?.primary_section._id, - }) + }), ); }; @@ -54,14 +53,27 @@ const usePaywall = () => { contentIdentifier && contentRestriction && isIdentityInitialized && - !isPaywalled && - !isServerSide() + !isPaywalled ) { - runPaywall(); + setTimeout(() => runPaywall(), 1000); } - }, [apiOrigin, globalContent, Identity, isIdentityInitialized, isPaywalled]); + }, [ + apiOrigin, + globalContent, + Identity, + isIdentityInitialized, + isPaywalled, + contentIdentifier, + contentRestriction, + contentType, + ]); + + useEffect(() => { + // eslint-disable-next-line no-underscore-dangle + const rules = window?.ArcP?._rules || []; + if (results?.triggered && rules?.length) { const { id: triggerId, rc: triggerCount } = results.triggered; @@ -83,13 +95,13 @@ const usePaywall = () => { .find(withRestrictedStatus); setTriggeredRule( - paywallableRule && paywallableRule !== triggeringRule ? paywallableRule : triggeringRule + paywallableRule && paywallableRule !== triggeringRule ? paywallableRule : triggeringRule, ); } else { setTriggeredRule(triggeringRule); } } - }, [results, rules, isLoggedIn]); + }, [results, isLoggedIn]); if (isServerSide()) { return {