Skip to content

Commit

Permalink
Fix paywall Issue (#1824)
Browse files Browse the repository at this point in the history
* fixing ArcP.run

* attending feedback

* attending feedback

* attending feedback

* attending feedback

* attending feedback
  • Loading branch information
LauraPinilla authored Dec 5, 2023
1 parent 32f6095 commit 56fd4d1
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions blocks/subscriptions-block/components/usePaywall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -45,7 +44,7 @@ const usePaywall = () => {
setIsPaywalled(true);
},
section: globalContent.taxonomy?.primary_section._id,
})
}),
);
};

Expand All @@ -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;

Expand All @@ -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 {
Expand Down

0 comments on commit 56fd4d1

Please sign in to comment.