Skip to content

Commit

Permalink
Merge pull request #1378 from tomivm/fix/update-trial-period-on-unlog…
Browse files Browse the repository at this point in the history
…ged-sessions

Fix/update trial period on unlogged sessions
  • Loading branch information
RodriSanchez1 authored Feb 22, 2023
2 parents 0da72d0 + 4c863f5 commit 603effe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ import {
ACTIVE
} from './SubscriptionProvider.constants';

import { isLogged } from '../../components/App/App.selectors';

export function updateIsOnTrialPeriod() {
return (dispatch, getState) => {
const userCreatedAt = getState().app.userData.createdAt;
const state = getState();
const userCreatedAt = state.app.userData.createdAt;
const { isSubscribed } = getState().subscription;
const isOnTrialPeriod = isUserOnTrialPeriod(userCreatedAt);
dispatch({
type: UPDATE_IS_ON_TRIAL_PERIOD,
isOnTrialPeriod
});

if (!isOnTrialPeriod && !isSubscribed)
if (!isOnTrialPeriod && !isSubscribed && isLogged(state))
dispatch(showPremiumRequired({ showTryPeriodFinishedMessages: true }));

function isUserOnTrialPeriod(createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,26 @@ export class SubscriptionProvider extends Component {
};

componentDidMount() {
const { isSubscribed, comprobeSubscription } = this.props;

const manageTrialPeriod = () => {
const { isLogged, updateIsOnTrialPeriod } = this.props;
if (isLogged) {
updateIsOnTrialPeriod();
}
};
const {
isSubscribed,
comprobeSubscription,
updateIsOnTrialPeriod
} = this.props;

if (isAndroid()) {
this.configInAppPurchasePlugin();
if (isSubscribed) {
comprobeSubscription();
}
onAndroidResume(() => comprobeSubscription());
manageTrialPeriod();
updateIsOnTrialPeriod();
}
}

componentDidUpdate = prevProps => {
if (isAndroid()) {
const {
isLogged,
isOnTrialPeriod,
updateIsOnTrialPeriod,
subscriberId,
androidSubscriptionState,
Expand All @@ -60,10 +56,8 @@ export class SubscriptionProvider extends Component {
)
comprobeSubscription();
}
if (isOnTrialPeriod === undefined || isOnTrialPeriod) {
updateIsOnTrialPeriod();
}
}
if (prevProps.isLogged !== isLogged) updateIsOnTrialPeriod();
}
};

Expand Down

0 comments on commit 603effe

Please sign in to comment.