2022-06-13 02:48:23 +00:00
|
|
|
import {buildHomeBanners} from 'app/client/components/Banners';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {beaconOpenMessage} from 'app/client/lib/helpScout';
|
|
|
|
import {AppModel, reportError} from 'app/client/models/AppModel';
|
|
|
|
import {BillingModel, BillingModelImpl, ISubscriptionModel} from 'app/client/models/BillingModel';
|
2022-06-08 17:54:00 +00:00
|
|
|
import {urlState} from 'app/client/models/gristUrlState';
|
2021-08-18 17:49:34 +00:00
|
|
|
import {AppHeader} from 'app/client/ui/AppHeader';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {BillingForm, IFormData} from 'app/client/ui/BillingForm';
|
|
|
|
import * as css from 'app/client/ui/BillingPageCss';
|
2022-07-08 19:09:22 +00:00
|
|
|
import {BillingPlanManagers} from 'app/client/ui/BillingPlanManagers';
|
|
|
|
import {createForbiddenPage} from 'app/client/ui/errorPages';
|
|
|
|
import {leftPanelBasic} from 'app/client/ui/LeftPanelCommon';
|
|
|
|
import {pagePanels} from 'app/client/ui/PagePanels';
|
2022-08-09 14:49:51 +00:00
|
|
|
import {showTeamUpgradeConfirmation} from 'app/client/ui/ProductUpgrades';
|
2022-07-08 19:09:22 +00:00
|
|
|
import {createTopBarHome} from 'app/client/ui/TopBar';
|
|
|
|
import {cssBreadcrumbs, cssBreadcrumbsLink, separator} from 'app/client/ui2018/breadcrumbs';
|
|
|
|
import {bigBasicButton, bigBasicButtonLink, bigPrimaryButton} from 'app/client/ui2018/buttons';
|
|
|
|
import {colors} from 'app/client/ui2018/cssVars';
|
|
|
|
import {IconName} from 'app/client/ui2018/IconList';
|
|
|
|
import {loadingSpinner} from 'app/client/ui2018/loaders';
|
|
|
|
import {confirmModal} from 'app/client/ui2018/modals';
|
|
|
|
import {BillingTask, IBillingCoupon} from 'app/common/BillingAPI';
|
|
|
|
import {displayPlanName, TEAM_FREE_PLAN, TEAM_PLAN} from 'app/common/Features';
|
|
|
|
import {capitalize} from 'app/common/gutil';
|
|
|
|
import {Organization} from 'app/common/UserAPI';
|
|
|
|
import {Disposable, dom, DomArg, IAttrObj, makeTestId, Observable} from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const testId = makeTestId('test-bp-');
|
2022-06-08 17:54:00 +00:00
|
|
|
const billingTasksNames = {
|
|
|
|
signUp: 'Sign Up', // task for payment page
|
|
|
|
signUpLite: 'Complete Sign Up', // task for payment page
|
|
|
|
updateDomain: 'Update Name', // task for summary page
|
|
|
|
cancelPlan: 'Cancel plan', // this is not a task, but a sub page
|
2022-06-29 10:19:20 +00:00
|
|
|
upgraded: 'Account',
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2022-06-08 17:54:00 +00:00
|
|
|
* Creates the billing page where users can manage their subscription and payment card.
|
2020-10-02 15:10:00 +00:00
|
|
|
*/
|
|
|
|
export class BillingPage extends Disposable {
|
2022-06-08 17:54:00 +00:00
|
|
|
private _model: BillingModel = new BillingModelImpl(this._appModel);
|
|
|
|
private _form: BillingForm | undefined = undefined;
|
2020-10-02 15:10:00 +00:00
|
|
|
private _formData: IFormData = {};
|
2022-06-08 17:54:00 +00:00
|
|
|
private _showConfirmPage: Observable<boolean> = Observable.create(this, false);
|
|
|
|
private _isSubmitting: Observable<boolean> = Observable.create(this, false);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
constructor(private _appModel: AppModel) {
|
|
|
|
super();
|
2022-06-06 16:21:26 +00:00
|
|
|
this._appModel.refreshOrgUsage().catch(reportError);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
// Exposed for tests.
|
|
|
|
public testBuildPaymentPage() {
|
|
|
|
return this._buildPaymentPage();
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
public buildDom() {
|
|
|
|
return dom.domComputed(this._model.isUnauthorized, (isUnauthorized) => {
|
|
|
|
if (isUnauthorized) {
|
|
|
|
return createForbiddenPage(this._appModel,
|
|
|
|
'Only billing plan managers may view billing account information. Plan managers may ' +
|
|
|
|
'be added in the billing summary by existing plan managers.');
|
|
|
|
} else {
|
|
|
|
const panelOpen = Observable.create(this, false);
|
|
|
|
return pagePanels({
|
|
|
|
leftPanel: {
|
|
|
|
panelWidth: Observable.create(this, 240),
|
|
|
|
panelOpen,
|
|
|
|
hideOpener: true,
|
2021-08-18 17:49:34 +00:00
|
|
|
header: dom.create(AppHeader, this._appModel.currentOrgName, this._appModel),
|
2020-10-02 15:10:00 +00:00
|
|
|
content: leftPanelBasic(this._appModel, panelOpen),
|
|
|
|
},
|
|
|
|
headerMain: this._createTopBarBilling(),
|
2022-06-13 02:48:23 +00:00
|
|
|
contentTop: buildHomeBanners(this._appModel),
|
2022-06-08 17:54:00 +00:00
|
|
|
contentMain: this._buildCurrentPageDom()
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the contentMain dom for the current billing page.
|
|
|
|
*/
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildCurrentPageDom() {
|
2022-06-29 10:19:20 +00:00
|
|
|
const page = css.billingWrapper(
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.domComputed(this._model.currentSubpage, (subpage) => {
|
|
|
|
if (!subpage) {
|
2022-06-08 17:54:00 +00:00
|
|
|
return this._buildSummaryPage();
|
2020-10-02 15:10:00 +00:00
|
|
|
} else if (subpage === 'payment') {
|
2022-06-08 17:54:00 +00:00
|
|
|
return this._buildPaymentPage();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2022-06-29 10:19:20 +00:00
|
|
|
if (this._model.currentTask.get() === 'upgraded') {
|
|
|
|
urlState().pushUrl({params: {}}, { replace: true }).catch(() => {});
|
|
|
|
showTeamUpgradeConfirmation(this);
|
|
|
|
}
|
|
|
|
return page;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildSummaryPage() {
|
2020-10-02 15:10:00 +00:00
|
|
|
const org = this._appModel.currentOrg;
|
|
|
|
// Fetch plan and card data.
|
|
|
|
this._model.fetchData(true).catch(reportError);
|
|
|
|
return css.billingPage(
|
2022-06-08 17:54:00 +00:00
|
|
|
dom.domComputed(this._model.currentTask, (task) => {
|
|
|
|
const pageText = task ? billingTasksNames[task] : 'Account';
|
|
|
|
return [
|
|
|
|
css.cardBlock(
|
|
|
|
css.billingHeader(pageText),
|
|
|
|
task !== 'updateDomain' ? [
|
|
|
|
dom.domComputed(this._model.subscription, () => [
|
|
|
|
this._buildDomainSummary(org ?? {}),
|
|
|
|
]),
|
|
|
|
// If this is not a personal org, create the plan manager list dom.
|
|
|
|
org && !org.owner ? dom.frag(
|
|
|
|
css.billingHeader('Plan Managers', { style: 'margin: 32px 0 16px 0;' }),
|
|
|
|
css.billingHintText(
|
|
|
|
'You may add additional billing contacts (for example, your accounting department). ' +
|
|
|
|
'All billing-related emails will be sent to this list of contacts.'
|
|
|
|
),
|
|
|
|
dom.create(BillingPlanManagers, this._model, org, this._appModel.currentValidUser)
|
|
|
|
) : null
|
|
|
|
] : dom.domComputed(this._showConfirmPage, (showConfirm) => {
|
|
|
|
if (showConfirm) {
|
|
|
|
return [
|
|
|
|
this._buildConfirm(this._formData),
|
|
|
|
this._buildButtons(pageText)
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return this._buildForms(org, task);
|
|
|
|
}
|
|
|
|
})
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
2022-06-08 17:54:00 +00:00
|
|
|
css.summaryBlock(
|
|
|
|
css.billingHeader('Billing Summary'),
|
|
|
|
this._buildSubscriptionSummary(),
|
|
|
|
)
|
|
|
|
];
|
|
|
|
})
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
// PRIVATE - exposed for tests
|
|
|
|
private _buildPaymentPage() {
|
2020-10-02 15:10:00 +00:00
|
|
|
const org = this._appModel.currentOrg;
|
|
|
|
// Fetch plan and card data if not already present.
|
|
|
|
this._model.fetchData().catch(this._model.reportBlockingError);
|
|
|
|
return css.billingPage(
|
|
|
|
dom.maybe(this._model.currentTask, task => {
|
2022-06-08 17:54:00 +00:00
|
|
|
const pageText = billingTasksNames[task];
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
|
|
|
css.cardBlock(
|
|
|
|
css.billingHeader(pageText),
|
|
|
|
dom.domComputed((use) => {
|
|
|
|
const err = use(this._model.error);
|
|
|
|
if (err) {
|
|
|
|
return css.errorBox(err, dom('br'), dom('br'), reportLink(this._appModel, "Report problem"));
|
|
|
|
}
|
|
|
|
const sub = use(this._model.subscription);
|
2022-06-08 17:54:00 +00:00
|
|
|
if (!sub) {
|
|
|
|
return css.spinnerBox(loadingSpinner());
|
|
|
|
}
|
|
|
|
if (task === 'cancelPlan') {
|
2020-10-02 15:10:00 +00:00
|
|
|
// If the selected plan is free, the user is cancelling their subscription.
|
|
|
|
return [
|
|
|
|
css.paymentBlock(
|
|
|
|
'On the subscription end date, your team site will remain available in ' +
|
|
|
|
'read-only mode for one month.',
|
|
|
|
),
|
|
|
|
css.paymentBlock(
|
|
|
|
'After the one month grace period, your team site will be removed along ' +
|
|
|
|
'with all documents inside.'
|
|
|
|
),
|
|
|
|
css.paymentBlock('Are you sure you would like to cancel the subscription?'),
|
2022-06-08 17:54:00 +00:00
|
|
|
this._buildButtons('Cancel Subscription')
|
2020-10-02 15:10:00 +00:00
|
|
|
];
|
2022-06-08 17:54:00 +00:00
|
|
|
} else { // tasks - signUpLite
|
2020-10-02 15:10:00 +00:00
|
|
|
return dom.domComputed(this._showConfirmPage, (showConfirm) => {
|
|
|
|
if (showConfirm) {
|
|
|
|
return [
|
2022-06-08 17:54:00 +00:00
|
|
|
this._buildConfirm(this._formData),
|
|
|
|
this._buildButtons(pageText)
|
2020-10-02 15:10:00 +00:00
|
|
|
];
|
|
|
|
} else {
|
2022-06-08 17:54:00 +00:00
|
|
|
return this._buildForms(org, task);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
),
|
|
|
|
css.summaryBlock(
|
|
|
|
css.billingHeader('Summary'),
|
|
|
|
css.summaryFeatures(
|
|
|
|
this._buildPaymentSummary(task),
|
|
|
|
testId('summary')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
];
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildSubscriptionSummary() {
|
|
|
|
return dom.domComputed(this._model.subscription, sub => {
|
|
|
|
if (!sub) {
|
|
|
|
return css.spinnerBox(loadingSpinner());
|
|
|
|
} else {
|
|
|
|
const moneyPlan = sub.upcomingPlan || sub.activePlan;
|
|
|
|
const changingPlan = sub.upcomingPlan && sub.upcomingPlan.amount > 0;
|
|
|
|
const cancellingPlan = sub.upcomingPlan && sub.upcomingPlan.amount === 0;
|
|
|
|
const validPlan = sub.isValidPlan;
|
|
|
|
const discountName = sub.discount && sub.discount.name;
|
|
|
|
const discountEnd = sub.discount && sub.discount.end_timestamp_ms;
|
|
|
|
const tier = discountName && discountName.includes(' Tier ');
|
2022-07-08 19:09:22 +00:00
|
|
|
const activePlanName = sub.activePlan?.nickname ??
|
|
|
|
displayPlanName[this._appModel.planName || ''] ?? this._appModel.planName;
|
2022-06-08 17:54:00 +00:00
|
|
|
const planName = tier ? discountName : activePlanName;
|
|
|
|
const appSumoInvoiced = this._appModel.currentOrg?.billingAccount?.externalOptions?.invoiceId;
|
|
|
|
const isPaidPlan = sub.billable;
|
2022-07-08 19:09:22 +00:00
|
|
|
// If subscription is canceled, we need to create a new one using Stripe Checkout.
|
2022-06-08 17:54:00 +00:00
|
|
|
const canRenew = (sub.status === 'canceled' && isPaidPlan);
|
|
|
|
// We can upgrade only free team plan at this moment.
|
|
|
|
const canUpgrade = !canRenew && !isPaidPlan;
|
2022-07-08 19:09:22 +00:00
|
|
|
// And we can manage team plan that is not canceled.
|
2022-06-08 17:54:00 +00:00
|
|
|
const canManage = !canRenew && isPaidPlan;
|
2022-07-08 19:09:22 +00:00
|
|
|
const isCanceled = sub.status === 'canceled';
|
|
|
|
const wasTeam = this._appModel.planName === TEAM_PLAN && isCanceled && !validPlan;
|
2022-06-08 17:54:00 +00:00
|
|
|
return [
|
|
|
|
css.summaryFeatures(
|
|
|
|
validPlan && planName ? [
|
|
|
|
makeSummaryFeature(['You are subscribed to the ', planName, ' plan'])
|
|
|
|
] : [
|
2022-07-08 19:09:22 +00:00
|
|
|
isCanceled ?
|
|
|
|
makeSummaryFeature(['You were subscribed to the ', planName, ' plan'], { isBad: true }) :
|
|
|
|
makeSummaryFeature(['This team site is not in good standing'], { isBad: true }),
|
2022-06-08 17:54:00 +00:00
|
|
|
],
|
|
|
|
// If the plan is changing, include the date the current plan ends
|
|
|
|
// and the plan that will be in effect afterwards.
|
|
|
|
changingPlan && isPaidPlan ? [
|
|
|
|
makeSummaryFeature(['Your current plan ends on ', dateFmt(sub.periodEnd)]),
|
|
|
|
makeSummaryFeature(['On this date, you will be subscribed to the ',
|
|
|
|
sub.upcomingPlan?.nickname ?? '-', ' plan'])
|
|
|
|
] : null,
|
|
|
|
cancellingPlan && isPaidPlan ? [
|
|
|
|
makeSummaryFeature(['Your subscription ends on ', dateFmt(sub.periodEnd)]),
|
2022-07-08 19:09:22 +00:00
|
|
|
makeSummaryFeature(['On this date, your team site will become read-only'])
|
2022-06-08 17:54:00 +00:00
|
|
|
] : null,
|
|
|
|
moneyPlan?.amount ? [
|
|
|
|
makeSummaryFeature([`Your team site has `, `${sub.userCount}`,
|
|
|
|
` member${sub.userCount !== 1 ? 's' : ''}`]),
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
tier ? this._makeAppSumoFeature(discountName) : null,
|
2022-06-08 17:54:00 +00:00
|
|
|
// Currently the subtotal is misleading and scary when tiers are in effect.
|
|
|
|
// In this case, for now, just report what will be invoiced.
|
|
|
|
!tier ? makeSummaryFeature([`Your ${moneyPlan.interval}ly subtotal is `,
|
|
|
|
getPriceString(moneyPlan.amount * sub.userCount)]) : null,
|
|
|
|
(discountName && !tier) ?
|
|
|
|
makeSummaryFeature([
|
|
|
|
`You receive the `,
|
|
|
|
discountName,
|
|
|
|
...(discountEnd !== null ? [' (until ', dateFmtFull(discountEnd), ')'] : []),
|
|
|
|
]) :
|
|
|
|
null,
|
|
|
|
// When on a free trial, Stripe reports trialEnd time, but it seems to always
|
|
|
|
// match periodEnd for a trialing subscription, so we just use that.
|
|
|
|
sub.isInTrial ? makeSummaryFeature(['Your free trial ends on ', dateFmtFull(sub.periodEnd)]) : null,
|
|
|
|
makeSummaryFeature([`Your next invoice is `, getPriceString(sub.nextTotal),
|
|
|
|
' on ', dateFmt(sub.periodEnd)]),
|
|
|
|
] : null,
|
|
|
|
appSumoInvoiced ? makeAppSumoLink(appSumoInvoiced) : null,
|
|
|
|
getSubscriptionProblem(sub),
|
|
|
|
testId('summary')
|
|
|
|
),
|
|
|
|
!canManage ? null :
|
|
|
|
makeActionLink('Manage billing', 'Settings', this._model.getCustomerPortalUrl(), testId('portal-link')),
|
2022-08-09 14:49:51 +00:00
|
|
|
!wasTeam ? null : makeActionButton('Downgrade plan', 'Settings',
|
|
|
|
() => this._confirmDowngradeToTeamFree(), testId('downgrade-free-link')),
|
2022-06-08 17:54:00 +00:00
|
|
|
!canRenew ? null :
|
|
|
|
makeActionLink('Renew subscription', 'Settings', this._model.renewPlan(), testId('renew-link')),
|
|
|
|
!canUpgrade ? null :
|
|
|
|
makeActionButton('Upgrade subscription', 'Settings',
|
|
|
|
() => this._appModel.showUpgradeModal(), testId('upgrade-link')),
|
|
|
|
!(validPlan && planName && isPaidPlan && !cancellingPlan) ? null :
|
|
|
|
makeActionLink(
|
|
|
|
'Cancel subscription',
|
|
|
|
'Settings',
|
|
|
|
urlState().setLinkUrl({
|
|
|
|
billing: 'payment',
|
|
|
|
params: {
|
|
|
|
billingTask: 'cancelPlan'
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
testId('cancel-subscription')
|
|
|
|
),
|
|
|
|
(sub.lastInvoiceUrl && sub.activeSubscription ?
|
|
|
|
makeActionLink('View last invoice', 'Page', sub.lastInvoiceUrl, testId('invoice-link'))
|
|
|
|
: null
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-08 19:09:22 +00:00
|
|
|
private _confirmDowngradeToTeamFree() {
|
|
|
|
confirmModal('Downgrade to Free Team Plan',
|
|
|
|
'Downgrade',
|
|
|
|
() => this._downgradeToTeamFree(),
|
|
|
|
dom('div', {style: `color: ${colors.dark}`}, testId('downgrade-confirm-modal'),
|
|
|
|
dom('div', 'Documents on free team plan are subject to the following limits. '
|
|
|
|
+'Any documents in excess of these limits will be put in read-only mode.'),
|
|
|
|
dom('ul',
|
|
|
|
dom('li', { style: 'margin-bottom: 0.6em'}, dom('strong', '5,000'), ' rows per document'),
|
|
|
|
dom('li', { style: 'margin-bottom: 0.6em'}, dom('strong', '10MB'), ' max document size'),
|
|
|
|
dom('li', 'API limit: ', dom('strong', '5k'), ' calls/day'),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async _downgradeToTeamFree() {
|
|
|
|
// Perform the downgrade operation.
|
|
|
|
await this._model.downgradePlan(TEAM_FREE_PLAN);
|
|
|
|
// Refresh app model
|
|
|
|
this._appModel.topAppModel.initialize();
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _makeAppSumoFeature(name: string) {
|
|
|
|
// TODO: move AppSumo plan knowledge elsewhere.
|
|
|
|
let users = 0;
|
|
|
|
switch (name) {
|
|
|
|
case 'AppSumo Tier 1':
|
|
|
|
users = 1;
|
|
|
|
break;
|
|
|
|
case 'AppSumo Tier 2':
|
|
|
|
users = 3;
|
|
|
|
break;
|
|
|
|
case 'AppSumo Tier 3':
|
|
|
|
users = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (users > 0) {
|
|
|
|
return makeSummaryFeature([`Your AppSumo plan covers `,
|
|
|
|
`${users}`,
|
|
|
|
` member${users > 1 ? 's' : ''}`]);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _buildForms(org: Organization | null, task: BillingTask) {
|
|
|
|
const isTeamSite = org && org.billingAccount && !org.billingAccount.individual;
|
|
|
|
const currentSettings = this._formData.settings ?? {
|
2021-08-18 01:44:11 +00:00
|
|
|
name: org!.name,
|
|
|
|
domain: org?.domain?.startsWith('o-') ? undefined : org?.domain || undefined,
|
2022-06-08 17:54:00 +00:00
|
|
|
};
|
|
|
|
const pageText = billingTasksNames[task];
|
2020-10-02 15:10:00 +00:00
|
|
|
// If there is an immediate charge required, require re-entering the card info.
|
|
|
|
// Show all forms on sign up.
|
2021-10-20 18:18:01 +00:00
|
|
|
this._form = new BillingForm(
|
|
|
|
org,
|
|
|
|
this._model,
|
|
|
|
{
|
2022-06-08 17:54:00 +00:00
|
|
|
settings: ['signUpLite', 'updateDomain'].includes(task),
|
|
|
|
domain: ['signUpLite', 'updateDomain'].includes(task)
|
2021-10-20 18:18:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
settings: currentSettings,
|
|
|
|
}
|
|
|
|
);
|
2020-10-02 15:10:00 +00:00
|
|
|
return dom('div',
|
|
|
|
dom.onDispose(() => {
|
|
|
|
if (this._form) {
|
|
|
|
this._form.dispose();
|
|
|
|
this._form = undefined;
|
|
|
|
}
|
|
|
|
}),
|
2022-06-08 17:54:00 +00:00
|
|
|
isTeamSite ? this._buildDomainSummary(currentSettings ?? {}) : null,
|
2020-10-02 15:10:00 +00:00
|
|
|
this._form.buildDom(),
|
2022-06-08 17:54:00 +00:00
|
|
|
this._buildButtons(pageText)
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildConfirm(formData: IFormData) {
|
2020-10-02 15:10:00 +00:00
|
|
|
const settings = formData.settings || null;
|
|
|
|
return [
|
2022-06-08 17:54:00 +00:00
|
|
|
this._buildDomainConfirmation(settings ?? {}, false),
|
2020-10-02 15:10:00 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private _createTopBarBilling() {
|
|
|
|
const org = this._appModel.currentOrg;
|
|
|
|
return dom.frag(
|
|
|
|
cssBreadcrumbs({ style: 'margin-left: 16px;' },
|
|
|
|
cssBreadcrumbsLink(
|
|
|
|
urlState().setLinkUrl({}),
|
|
|
|
'Home',
|
|
|
|
testId('home')
|
|
|
|
),
|
|
|
|
separator(' / '),
|
|
|
|
dom.domComputed(this._model.currentSubpage, (subpage) => {
|
|
|
|
if (subpage) {
|
|
|
|
return [
|
|
|
|
// Prevent navigating to the summary page if these pages are not associated with an org.
|
|
|
|
org && !org.owner ? cssBreadcrumbsLink(
|
|
|
|
urlState().setLinkUrl({ billing: 'billing' }),
|
|
|
|
'Billing',
|
|
|
|
testId('billing')
|
|
|
|
) : dom('span', 'Billing'),
|
|
|
|
separator(' / '),
|
|
|
|
dom('span', capitalize(subpage))
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return dom('span', 'Billing');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
),
|
|
|
|
createTopBarHome(this._appModel),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildDomainConfirmation(org: { name?: string | null, domain?: string | null }, showEdit: boolean = true) {
|
2020-10-02 15:10:00 +00:00
|
|
|
return css.summaryItem(
|
|
|
|
css.summaryHeader(
|
2022-06-08 17:54:00 +00:00
|
|
|
css.billingBoldText('Team Info'),
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
2022-06-08 17:54:00 +00:00
|
|
|
org?.name ? [
|
|
|
|
css.summaryRow(
|
|
|
|
{ style: 'margin-bottom: 0.6em' },
|
|
|
|
css.billingText(`Your team name: `,
|
|
|
|
dom('span', { style: 'font-weight: bold' }, org?.name, testId('org-name')),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
] : null,
|
|
|
|
org?.domain ? [
|
2020-10-02 15:10:00 +00:00
|
|
|
css.summaryRow(
|
|
|
|
css.billingText(`Your team site URL: `,
|
2022-06-08 17:54:00 +00:00
|
|
|
dom('span', { style: 'font-weight: bold' }, org?.domain),
|
2020-10-02 15:10:00 +00:00
|
|
|
`.getgrist.com`,
|
|
|
|
testId('org-domain')
|
2021-08-18 01:44:11 +00:00
|
|
|
),
|
|
|
|
showEdit ? css.billingTextBtn(css.billingIcon('Settings'), 'Change',
|
|
|
|
urlState().setLinkUrl({
|
2022-06-08 17:54:00 +00:00
|
|
|
billing: 'billing',
|
2021-08-18 01:44:11 +00:00
|
|
|
params: { billingTask: 'updateDomain' }
|
|
|
|
}),
|
|
|
|
testId('update-domain')
|
|
|
|
) : null
|
2020-10-02 15:10:00 +00:00
|
|
|
)
|
|
|
|
] : null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildDomainSummary(org: { name?: string | null, domain?: string | null }, showEdit: boolean = true) {
|
|
|
|
const task = this._model.currentTask.get();
|
|
|
|
if (task === 'signUpLite' || task === 'updateDomain') { return null; }
|
|
|
|
return this._buildDomainConfirmation(org, showEdit);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
// Summary panel for payment subpage.
|
2020-10-02 15:10:00 +00:00
|
|
|
private _buildPaymentSummary(task: BillingTask) {
|
2022-06-08 17:54:00 +00:00
|
|
|
if (task === 'signUpLite') {
|
|
|
|
return this._buildSubscriptionSummary();
|
2021-08-18 01:44:11 +00:00
|
|
|
} else if (task === 'updateDomain') {
|
2022-06-08 17:54:00 +00:00
|
|
|
return makeSummaryFeature('You are updating the site name and domain');
|
|
|
|
} else if (task === 'cancelPlan') {
|
|
|
|
return dom.domComputed(this._model.subscription, sub => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
|
|
|
makeSummaryFeature(['You are cancelling the subscription']),
|
|
|
|
sub ? makeSummaryFeature(['Your subscription will end on ', dateFmt(sub.periodEnd)]) : null
|
|
|
|
];
|
2022-06-08 17:54:00 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
private _buildButtons(submitText: string) {
|
2020-10-02 15:10:00 +00:00
|
|
|
const task = this._model.currentTask.get();
|
|
|
|
this._isSubmitting.set(false); // Reset status on build.
|
|
|
|
return css.paymentBtnRow(
|
2022-06-08 17:54:00 +00:00
|
|
|
task !== 'signUpLite' ? bigBasicButton('Back',
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.on('click', () => window.history.back()),
|
2022-06-08 17:54:00 +00:00
|
|
|
dom.show((use) => !use(this._showConfirmPage)),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.boolAttr('disabled', this._isSubmitting),
|
|
|
|
testId('back')
|
2022-06-08 17:54:00 +00:00
|
|
|
) : null,
|
|
|
|
task !== 'cancelPlan' ? bigBasicButtonLink('Edit',
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.show(this._showConfirmPage),
|
|
|
|
dom.on('click', () => this._showConfirmPage.set(false)),
|
|
|
|
dom.boolAttr('disabled', this._isSubmitting),
|
|
|
|
testId('edit')
|
2022-06-08 17:54:00 +00:00
|
|
|
) : null,
|
|
|
|
bigPrimaryButton({ style: 'margin-left: 10px;' },
|
|
|
|
dom.text(submitText),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.boolAttr('disabled', this._isSubmitting),
|
|
|
|
dom.on('click', () => this._doSubmit(task)),
|
|
|
|
testId('submit')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submit the active form.
|
|
|
|
private async _doSubmit(task?: BillingTask): Promise<void> {
|
|
|
|
if (this._isSubmitting.get()) { return; }
|
|
|
|
this._isSubmitting.set(true);
|
|
|
|
try {
|
2022-06-08 17:54:00 +00:00
|
|
|
if (task === 'cancelPlan') {
|
|
|
|
await this._model.cancelCurrentPlan();
|
|
|
|
this._showConfirmPage.set(false);
|
|
|
|
this._formData = {};
|
|
|
|
await urlState().pushUrl({ billing: 'billing', params: undefined });
|
|
|
|
return;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
// If the form is built, fetch the form data.
|
|
|
|
if (this._form) {
|
|
|
|
this._formData = await this._form.getFormData();
|
|
|
|
}
|
2022-06-08 17:54:00 +00:00
|
|
|
// In general, submit data to the server.
|
|
|
|
if (task === 'updateDomain' || this._showConfirmPage.get()) {
|
2020-10-02 15:10:00 +00:00
|
|
|
await this._model.submitPaymentPage(this._formData);
|
|
|
|
// On submit, reset confirm page and form data.
|
|
|
|
this._showConfirmPage.set(false);
|
|
|
|
this._formData = {};
|
|
|
|
} else {
|
|
|
|
this._showConfirmPage.set(true);
|
|
|
|
this._isSubmitting.set(false);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
2022-06-08 17:54:00 +00:00
|
|
|
// Note that submitPaymentPage are responsible for reporting errors.
|
2020-10-02 15:10:00 +00:00
|
|
|
// On failure the submit button isSubmitting state should be returned to false.
|
|
|
|
if (!this.isDisposed()) {
|
|
|
|
this._isSubmitting.set(false);
|
|
|
|
this._showConfirmPage.set(false);
|
2021-11-04 17:31:08 +00:00
|
|
|
// Focus the first element with an error.
|
|
|
|
this._form?.focusOnError();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
const statusText: { [key: string]: string } = {
|
2020-10-02 15:10:00 +00:00
|
|
|
incomplete: 'incomplete',
|
|
|
|
incomplete_expired: 'incomplete',
|
|
|
|
past_due: 'past due',
|
|
|
|
canceled: 'canceled',
|
|
|
|
unpaid: 'unpaid',
|
|
|
|
};
|
|
|
|
|
|
|
|
function getSubscriptionProblem(sub: ISubscriptionModel) {
|
|
|
|
const text = sub.status && statusText[sub.status];
|
|
|
|
if (!text) { return null; }
|
|
|
|
const result = [['Your subscription is ', text]];
|
|
|
|
if (sub.lastChargeError) {
|
|
|
|
const when = sub.lastChargeTime ? `on ${timeFmt(sub.lastChargeTime)} ` : '';
|
|
|
|
result.push([`Last charge attempt ${when} failed: ${sub.lastChargeError}`]);
|
|
|
|
}
|
2022-06-08 17:54:00 +00:00
|
|
|
return result.map(msg => makeSummaryFeature(msg, { isBad: true }));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 18:18:01 +00:00
|
|
|
interface PriceOptions {
|
|
|
|
taxRate?: number;
|
|
|
|
coupon?: IBillingCoupon;
|
|
|
|
refund?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultPriceOptions: PriceOptions = {
|
|
|
|
taxRate: 0,
|
|
|
|
coupon: undefined,
|
|
|
|
refund: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
function getPriceString(priceCents: number, options = defaultPriceOptions): string {
|
2022-06-08 17:54:00 +00:00
|
|
|
const { taxRate = 0, coupon, refund } = options;
|
2021-10-20 18:18:01 +00:00
|
|
|
if (coupon) {
|
|
|
|
if (coupon.amount_off) {
|
|
|
|
priceCents -= coupon.amount_off;
|
|
|
|
} else if (coupon.percent_off) {
|
|
|
|
priceCents -= (priceCents * (coupon.percent_off / 100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refund) {
|
|
|
|
priceCents -= refund;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we never display negative prices.
|
|
|
|
priceCents = Math.max(0, priceCents);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// TODO: Add functionality for other currencies.
|
|
|
|
return ((priceCents / 100) * (taxRate + 1)).toLocaleString('en-US', {
|
|
|
|
style: "currency",
|
|
|
|
currency: "USD",
|
|
|
|
minimumFractionDigits: 2
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
// Include a precise link back to AppSumo for changing plans.
|
|
|
|
function makeAppSumoLink(invoiceId: string) {
|
|
|
|
return dom('div',
|
|
|
|
css.billingTextBtn({ style: 'margin: 10px 0;' },
|
|
|
|
cssBreadcrumbsLink(
|
|
|
|
css.billingIcon('Plus'), 'Change your AppSumo plan',
|
|
|
|
{
|
|
|
|
href: `https://appsumo.com/account/redemption/${invoiceId}/#change-plan`,
|
|
|
|
target: '_blank'
|
|
|
|
},
|
|
|
|
testId('appsumo-link')
|
|
|
|
)
|
|
|
|
));
|
2021-10-20 18:18:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Make summary feature to include in:
|
|
|
|
* - Plan cards for describing features of the plan.
|
|
|
|
* - Summary lists describing what is being paid for and how much will be charged.
|
|
|
|
* - Summary lists describing the current subscription.
|
|
|
|
*
|
|
|
|
* Accepts text as an array where strings at every odd numbered index are bolded for emphasis.
|
|
|
|
* If isMissingFeature is set, no text is bolded and the optional attribute object is not applied.
|
|
|
|
* If isBad is set, a cross is used instead of a tick
|
|
|
|
*/
|
|
|
|
function makeSummaryFeature(
|
2022-06-08 17:54:00 +00:00
|
|
|
text: string | string[],
|
2020-10-02 15:10:00 +00:00
|
|
|
options: { isMissingFeature?: boolean, isBad?: boolean, attr?: IAttrObj } = {}
|
|
|
|
) {
|
|
|
|
const textArray = Array.isArray(text) ? text : [text];
|
|
|
|
if (options.isMissingFeature) {
|
|
|
|
return css.summaryMissingFeature(
|
|
|
|
textArray,
|
|
|
|
testId('summary-line')
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return css.summaryFeature(options.attr,
|
|
|
|
options.isBad ? css.billingBadIcon('CrossBig') : css.billingIcon('Tick'),
|
|
|
|
textArray.map((str, i) => (i % 2) ? css.focusText(str) : css.summaryText(str)),
|
|
|
|
testId('summary-line')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
function makeActionLink(text: string, icon: IconName, url: DomArg<HTMLElement>, ...args: DomArg<HTMLElement>[]) {
|
|
|
|
return dom('div',
|
|
|
|
css.billingTextBtn(
|
|
|
|
{ style: 'margin: 10px 0;' },
|
|
|
|
cssBreadcrumbsLink(
|
|
|
|
css.billingIcon(icon), text,
|
|
|
|
typeof url === 'string' ? { href: url } : url,
|
|
|
|
...args,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeActionButton(text: string, icon: IconName, handler: () => any, ...args: DomArg<HTMLElement>[]) {
|
|
|
|
return css.billingTextBtn(
|
|
|
|
{ style: 'margin: 10px 0;' },
|
|
|
|
css.billingIcon(icon), text,
|
|
|
|
dom.on('click', handler),
|
|
|
|
...args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
function reportLink(appModel: AppModel, text: string): HTMLElement {
|
2022-06-08 17:54:00 +00:00
|
|
|
return dom('a', { href: '#' }, text,
|
|
|
|
dom.on('click', (ev) => { ev.preventDefault(); beaconOpenMessage({ appModel }); })
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
function dateFmt(timestamp: number | null): string {
|
2020-10-02 15:10:00 +00:00
|
|
|
if (!timestamp) { return "unknown"; }
|
2022-06-08 17:54:00 +00:00
|
|
|
const date = new Date(timestamp);
|
|
|
|
if (date.getFullYear() !== new Date().getFullYear()) {
|
|
|
|
return dateFmtFull(timestamp);
|
|
|
|
}
|
|
|
|
return new Date(timestamp).toLocaleDateString('default', { month: 'long', day: 'numeric' });
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 17:54:00 +00:00
|
|
|
function dateFmtFull(timestamp: number | null): string {
|
2020-10-02 15:10:00 +00:00
|
|
|
if (!timestamp) { return "unknown"; }
|
2022-06-08 17:54:00 +00:00
|
|
|
return new Date(timestamp).toLocaleDateString('default', { month: 'short', day: 'numeric', year: 'numeric' });
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function timeFmt(timestamp: number): string {
|
|
|
|
return new Date(timestamp).toLocaleString('default',
|
2022-06-08 17:54:00 +00:00
|
|
|
{ month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' });
|
2020-10-26 14:45:31 +00:00
|
|
|
}
|