feat: redirect subscribers to dashboard instead of plans page (#897)
This commit is contained in:
@@ -207,7 +207,10 @@ export class ApplicationView extends PureComponent<Props, State> {
|
|||||||
const renderAppContents = !this.state.needsUnlock && this.state.launched;
|
const renderAppContents = !this.state.needsUnlock && this.state.launched;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PremiumModalProvider state={this.appState?.features}>
|
<PremiumModalProvider
|
||||||
|
application={this.application}
|
||||||
|
appState={this.appState}
|
||||||
|
>
|
||||||
<div className={this.platformString + ' main-ui-view sn-component'}>
|
<div className={this.platformString + ' main-ui-view sn-component'}>
|
||||||
{renderAppContents && (
|
{renderAppContents && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { FeaturesState } from '@/ui_models/app_state/features_state';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
|
import { AppState } from '@/ui_models/app_state';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { FunctionalComponent } from 'preact';
|
import { FunctionalComponent } from 'preact';
|
||||||
import { useContext } from 'preact/hooks';
|
import { useContext } from 'preact/hooks';
|
||||||
@@ -24,24 +25,33 @@ export const usePremiumModal = (): PremiumModalContextData => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
state: FeaturesState;
|
application: WebApplication;
|
||||||
|
appState: AppState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PremiumModalProvider: FunctionalComponent<Props> = observer(
|
export const PremiumModalProvider: FunctionalComponent<Props> = observer(
|
||||||
({ state, children }) => {
|
({ application, appState, children }) => {
|
||||||
const featureName = state._premiumAlertFeatureName;
|
const featureName = appState.features._premiumAlertFeatureName;
|
||||||
const activate = state.showPremiumAlert;
|
const activate = appState.features.showPremiumAlert;
|
||||||
const close = state.closePremiumAlert;
|
const close = appState.features.closePremiumAlert;
|
||||||
|
|
||||||
const showModal = !!featureName;
|
const showModal = !!featureName;
|
||||||
|
|
||||||
|
const hasSubscription = Boolean(
|
||||||
|
appState.subscription.userSubscription &&
|
||||||
|
!appState.subscription.isUserSubscriptionExpired &&
|
||||||
|
!appState.subscription.isUserSubscriptionCanceled
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{showModal && (
|
{showModal && (
|
||||||
<PremiumFeaturesModal
|
<PremiumFeaturesModal
|
||||||
showModal={!!featureName}
|
application={application}
|
||||||
featureName={featureName}
|
featureName={featureName}
|
||||||
|
hasSubscription={hasSubscription}
|
||||||
onClose={close}
|
onClose={close}
|
||||||
|
showModal={!!featureName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<PremiumModalProvider_ value={{ activate }}>
|
<PremiumModalProvider_ value={{ activate }}>
|
||||||
|
|||||||
@@ -7,22 +7,30 @@ import { FunctionalComponent } from 'preact';
|
|||||||
import { Icon } from './Icon';
|
import { Icon } from './Icon';
|
||||||
import { PremiumIllustration } from '@standardnotes/stylekit';
|
import { PremiumIllustration } from '@standardnotes/stylekit';
|
||||||
import { useRef } from 'preact/hooks';
|
import { useRef } from 'preact/hooks';
|
||||||
|
import { WebApplication } from '@/ui_models/application';
|
||||||
|
import { openSubscriptionDashboard } from '@/hooks/manageSubscription';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
application: WebApplication;
|
||||||
featureName: string;
|
featureName: string;
|
||||||
|
hasSubscription: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
showModal: boolean;
|
showModal: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
|
export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
|
||||||
|
application,
|
||||||
featureName,
|
featureName,
|
||||||
|
hasSubscription,
|
||||||
onClose,
|
onClose,
|
||||||
showModal,
|
showModal,
|
||||||
}) => {
|
}) => {
|
||||||
const plansButtonRef = useRef<HTMLButtonElement>(null);
|
const plansButtonRef = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
const onClickPlans = () => {
|
const handleClick = () => {
|
||||||
if (window._plans_url) {
|
if (hasSubscription) {
|
||||||
|
openSubscriptionDashboard(application);
|
||||||
|
} else if (window._plans_url) {
|
||||||
window.location.assign(window._plans_url);
|
window.location.assign(window._plans_url);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -61,11 +69,11 @@ export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
|
|||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<button
|
<button
|
||||||
onClick={onClickPlans}
|
onClick={handleClick}
|
||||||
className="w-full rounded no-border py-2 font-bold bg-info color-info-contrast hover:brightness-130 focus:brightness-130 cursor-pointer"
|
className="w-full rounded no-border py-2 font-bold bg-info color-info-contrast hover:brightness-130 focus:brightness-130 cursor-pointer"
|
||||||
ref={plansButtonRef}
|
ref={plansButtonRef}
|
||||||
>
|
>
|
||||||
See Plans
|
{hasSubscription ? 'Upgrade Plan' : 'See Plans'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user