From 7fe0873bbb570e2557a505175d9a3cb3dcdfb24a Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Thu, 24 Feb 2022 21:28:39 +0530 Subject: [PATCH] feat: redirect subscribers to dashboard instead of plans page (#897) --- .../components/ApplicationView.tsx | 5 +++- .../components/Premium/usePremiumModal.tsx | 24 +++++++++++++------ .../components/PremiumFeaturesModal.tsx | 16 +++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/components/ApplicationView.tsx b/app/assets/javascripts/components/ApplicationView.tsx index 36b95f40e22..7ba447673aa 100644 --- a/app/assets/javascripts/components/ApplicationView.tsx +++ b/app/assets/javascripts/components/ApplicationView.tsx @@ -207,7 +207,10 @@ export class ApplicationView extends PureComponent { const renderAppContents = !this.state.needsUnlock && this.state.launched; return ( - +
{renderAppContents && (
{ }; interface Props { - state: FeaturesState; + application: WebApplication; + appState: AppState; } export const PremiumModalProvider: FunctionalComponent = 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 && ( )} diff --git a/app/assets/javascripts/components/PremiumFeaturesModal.tsx b/app/assets/javascripts/components/PremiumFeaturesModal.tsx index e61e8eab1b9..a1601ea8c51 100644 --- a/app/assets/javascripts/components/PremiumFeaturesModal.tsx +++ b/app/assets/javascripts/components/PremiumFeaturesModal.tsx @@ -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 = ({ + application, featureName, + hasSubscription, onClose, showModal, }) => { const plansButtonRef = useRef(null); - const onClickPlans = () => { - if (window._plans_url) { + const handleClick = () => { + if (hasSubscription) { + openSubscriptionDashboard(application); + } else if (window._plans_url) { window.location.assign(window._plans_url); } }; @@ -61,11 +69,11 @@ export const PremiumFeaturesModal: FunctionalComponent = ({