From 305ffdf9847cfe67e2d022f84c1e2443b4bc2c76 Mon Sep 17 00:00:00 2001 From: Mo Date: Thu, 3 Nov 2022 06:35:06 -0500 Subject: [PATCH] fix: correctly refresh cta banner --- .../src/javascripts/Components/Footer/Footer.tsx | 1 + .../javascripts/Components/Footer/UpgradeNow.tsx | 8 +++++--- .../src/javascripts/Components/Tags/Navigation.tsx | 6 +++++- .../Subscription/SubscriptionController.ts | 14 +++++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/web/src/javascripts/Components/Footer/Footer.tsx b/packages/web/src/javascripts/Components/Footer/Footer.tsx index 32dc8615b..015bca0b5 100644 --- a/packages/web/src/javascripts/Components/Footer/Footer.tsx +++ b/packages/web/src/javascripts/Components/Footer/Footer.tsx @@ -386,6 +386,7 @@ class Footer extends AbstractComponent { {this.state.showBetaWarning && ( diff --git a/packages/web/src/javascripts/Components/Footer/UpgradeNow.tsx b/packages/web/src/javascripts/Components/Footer/UpgradeNow.tsx index 5c036adff..e49543dc5 100644 --- a/packages/web/src/javascripts/Components/Footer/UpgradeNow.tsx +++ b/packages/web/src/javascripts/Components/Footer/UpgradeNow.tsx @@ -1,18 +1,20 @@ import { WebApplication } from '@/Application/Application' import { FeaturesController } from '@/Controllers/FeaturesController' +import { SubscriptionController } from '@/Controllers/Subscription/SubscriptionController' import { observer } from 'mobx-react-lite' import { loadPurchaseFlowUrl } from '../PurchaseFlow/PurchaseFlowFunctions' type Props = { application: WebApplication featuresController: FeaturesController + subscriptionContoller: SubscriptionController } -const UpgradeNow = ({ application, featuresController }: Props) => { +const UpgradeNow = ({ application, featuresController, subscriptionContoller }: Props) => { const shouldShowCTA = !featuresController.hasFolders - const hasAccount = application.hasAccount() + const hasAccount = subscriptionContoller.hasAccount - if (hasAccount && application.hideSubscriptionMarketing) { + if (hasAccount && subscriptionContoller.hideSubscriptionMarketing) { return null } diff --git a/packages/web/src/javascripts/Components/Tags/Navigation.tsx b/packages/web/src/javascripts/Components/Tags/Navigation.tsx index 0e51f5a12..4688c3635 100644 --- a/packages/web/src/javascripts/Components/Tags/Navigation.tsx +++ b/packages/web/src/javascripts/Components/Tags/Navigation.tsx @@ -69,7 +69,11 @@ const Navigation: FunctionComponent = ({ application }) => { label="Go to items list" icon="chevron-left" /> - + { diff --git a/packages/web/src/javascripts/Controllers/Subscription/SubscriptionController.ts b/packages/web/src/javascripts/Controllers/Subscription/SubscriptionController.ts index 62f32ba51..de5375683 100644 --- a/packages/web/src/javascripts/Controllers/Subscription/SubscriptionController.ts +++ b/packages/web/src/javascripts/Controllers/Subscription/SubscriptionController.ts @@ -9,7 +9,7 @@ import { SubscriptionClientInterface, Uuid, } from '@standardnotes/snjs' -import { action, computed, makeObservable, observable } from 'mobx' +import { action, computed, makeObservable, observable, runInAction } from 'mobx' import { WebApplication } from '../../Application/Application' import { AbstractViewController } from '../Abstract/AbstractViewController' import { AvailableSubscriptions } from './AvailableSubscriptionsType' @@ -21,6 +21,8 @@ export class SubscriptionController extends AbstractViewController { userSubscription: Subscription | undefined = undefined availableSubscriptions: AvailableSubscriptions | undefined = undefined subscriptionInvitations: Invitation[] | undefined = undefined + hideSubscriptionMarketing: boolean + hasAccount: boolean override deinit() { super.deinit() @@ -37,11 +39,15 @@ export class SubscriptionController extends AbstractViewController { private subscriptionManager: SubscriptionClientInterface, ) { super(application, eventBus) + this.hideSubscriptionMarketing = application.hideSubscriptionMarketing + this.hasAccount = application.hasAccount() makeObservable(this, { userSubscription: observable, availableSubscriptions: observable, subscriptionInvitations: observable, + hideSubscriptionMarketing: observable, + hasAccount: observable, userSubscriptionName: computed, userSubscriptionExpirationDate: computed, @@ -61,6 +67,9 @@ export class SubscriptionController extends AbstractViewController { this.getSubscriptionInfo().catch(console.error) this.reloadSubscriptionInvitations().catch(console.error) } + runInAction(() => { + this.hasAccount = application.hasAccount() + }) }, ApplicationEvent.Launched), ) @@ -68,6 +77,9 @@ export class SubscriptionController extends AbstractViewController { application.addEventObserver(async () => { this.getSubscriptionInfo().catch(console.error) this.reloadSubscriptionInvitations().catch(console.error) + runInAction(() => { + this.hasAccount = application.hasAccount() + }) }, ApplicationEvent.SignedIn), )