From 3aba7f6208a24f9b40ff14d589fcf4fb0c32d562 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Mon, 20 Feb 2023 10:45:55 -0500 Subject: [PATCH] (core) set up a trialing list and a call scheduled flag for Grist SaaS Summary: This adds support for the automation described in https://grist.quip.com/rt3tAoEH4kuy/Automate-Sprouts-outreach-email Test Plan: added tests; will need manual testing and iterative integration work Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3804 --- app/client/models/AppModel.ts | 6 ++++++ app/client/ui/AppUI.ts | 2 +- app/common/BillingAPI.ts | 2 +- app/gen-server/lib/HomeDBManager.ts | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/client/models/AppModel.ts b/app/client/models/AppModel.ts index ff339c27..221d0d88 100644 --- a/app/client/models/AppModel.ts +++ b/app/client/models/AppModel.ts @@ -101,6 +101,7 @@ export interface AppModel { dismissedWelcomePopups: Observable; pageType: Observable; + needsOrg: Observable; notifier: Notifier; planName: string|null; @@ -253,6 +254,11 @@ export class AppModelImpl extends Disposable implements AppModel { public readonly pageType: Observable = Computed.create(this, urlState().state, (use, state) => (state.doc ? "doc" : (state.billing ? "billing" : (state.welcome ? "welcome" : "home")))); + public readonly needsOrg: Observable = Computed.create( + this, urlState().state, (use, state) => { + return !(Boolean(state.welcome) || state.billing === 'scheduled'); + }); + public readonly notifier = this.topAppModel.notifier; public readonly behavioralPromptsManager: BehavioralPromptsManager = diff --git a/app/client/ui/AppUI.ts b/app/client/ui/AppUI.ts index be7470f5..71485ca4 100644 --- a/app/client/ui/AppUI.ts +++ b/app/client/ui/AppUI.ts @@ -53,7 +53,7 @@ export function createAppUI(topAppModel: TopAppModel, appObj: App): IDisposable } function createMainPage(appModel: AppModel, appObj: App) { - if (!appModel.currentOrg && appModel.pageType.get() !== 'welcome') { + if (!appModel.currentOrg && appModel.needsOrg.get()) { const err = appModel.orgError; if (err && err.status === 404) { return createNotFoundPage(appModel); diff --git a/app/common/BillingAPI.ts b/app/common/BillingAPI.ts index 279271cd..9875f868 100644 --- a/app/common/BillingAPI.ts +++ b/app/common/BillingAPI.ts @@ -4,7 +4,7 @@ import {StringUnion} from 'app/common/StringUnion'; import {addCurrentOrgToPath} from 'app/common/urlUtils'; import {BillingAccount, ManagerDelta, OrganizationWithoutAccessInfo} from 'app/common/UserAPI'; -export const BillingSubPage = StringUnion('payment'); +export const BillingSubPage = StringUnion('payment', 'scheduled'); export type BillingSubPage = typeof BillingSubPage.type; export const BillingPage = StringUnion(...BillingSubPage.values, 'billing'); diff --git a/app/gen-server/lib/HomeDBManager.ts b/app/gen-server/lib/HomeDBManager.ts index 164096df..134931e9 100644 --- a/app/gen-server/lib/HomeDBManager.ts +++ b/app/gen-server/lib/HomeDBManager.ts @@ -83,6 +83,8 @@ export const NotifierEvents = StringUnion( 'addBillingManager', 'teamCreator', 'trialPeriodEndingSoon', + 'trialingSubscription', + 'scheduledCall', ); export type NotifierEvent = typeof NotifierEvents.type; @@ -467,6 +469,10 @@ export class HomeDBManager extends EventEmitter { return await User.findOne({where: {apiKey}, relations: ["logins"]}) || undefined; } + public async getUserByRef(ref: string): Promise { + return await User.findOne({where: {ref}, relations: ["logins"]}) || undefined; + } + public async getUser(userId: number): Promise { return await User.findOne({where: {id: userId}, relations: ["logins"]}) || undefined; }