Skip to content

Commit

Permalink
feat: redirect subscribers to dashboard instead of plans page (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored Feb 24, 2022
1 parent f9fafec commit 7fe0873
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
5 changes: 4 additions & 1 deletion app/assets/javascripts/components/ApplicationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ export class ApplicationView extends PureComponent<Props, State> {
const renderAppContents = !this.state.needsUnlock && this.state.launched;

return (
<PremiumModalProvider state={this.appState?.features}>
<PremiumModalProvider
application={this.application}
appState={this.appState}
>
<div className={this.platformString + ' main-ui-view sn-component'}>
{renderAppContents && (
<div
Expand Down
24 changes: 17 additions & 7 deletions app/assets/javascripts/components/Premium/usePremiumModal.tsx
Original file line number Diff line number Diff line change
@@ -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 { FunctionalComponent } from 'preact';
import { useContext } from 'preact/hooks';
Expand All @@ -24,24 +25,33 @@ export const usePremiumModal = (): PremiumModalContextData => {
};

interface Props {
state: FeaturesState;
application: WebApplication;
appState: AppState;
}

export const PremiumModalProvider: FunctionalComponent<Props> = observer(
({ state, children }) => {
const featureName = state._premiumAlertFeatureName;
const activate = state.showPremiumAlert;
const close = state.closePremiumAlert;
({ application, appState, children }) => {
const featureName = appState.features._premiumAlertFeatureName;
const activate = appState.features.showPremiumAlert;
const close = appState.features.closePremiumAlert;

const showModal = !!featureName;

const hasSubscription = Boolean(
appState.subscription.userSubscription &&
!appState.subscription.isUserSubscriptionExpired &&
!appState.subscription.isUserSubscriptionCanceled
);

return (
<>
{showModal && (
<PremiumFeaturesModal
showModal={!!featureName}
application={application}
featureName={featureName}
hasSubscription={hasSubscription}
onClose={close}
showModal={!!featureName}
/>
)}
<PremiumModalProvider_ value={{ activate }}>
Expand Down
16 changes: 12 additions & 4 deletions app/assets/javascripts/components/PremiumFeaturesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ import { FunctionalComponent } from 'preact';
import { Icon } from './Icon';
import { PremiumIllustration } from '@standardnotes/stylekit';
import { useRef } from 'preact/hooks';
import { WebApplication } from '@/ui_models/application';
import { openSubscriptionDashboard } from '@/hooks/manageSubscription';

type Props = {
application: WebApplication;
featureName: string;
hasSubscription: boolean;
onClose: () => void;
showModal: boolean;
};

export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
application,
featureName,
hasSubscription,
onClose,
showModal,
}) => {
const plansButtonRef = useRef<HTMLButtonElement>(null);

const onClickPlans = () => {
if (window._plans_url) {
const handleClick = () => {
if (hasSubscription) {
openSubscriptionDashboard(application);
} else if (window._plans_url) {
window.location.assign(window._plans_url);
}
};
Expand Down Expand Up @@ -61,11 +69,11 @@ export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
</AlertDialogDescription>
<div className="p-4">
<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"
ref={plansButtonRef}
>
See Plans
{hasSubscription ? 'Upgrade Plan' : 'See Plans'}
</button>
</div>
</div>
Expand Down

0 comments on commit 7fe0873

Please sign in to comment.