-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ToggleEnterpriseWidget: new frontend toggle for the admin
Strongly patterned after SupportGristPage. In fact, it has almost the same structure. Perhaps one day it would be possible to synchronise the logic between the two toggles even further, but I couldn't see a simple way to do so now. For now, some code structure duplication seemed easiest in lieau of more abstractions.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {makeT} from 'app/client/lib/localization'; | ||
import {Computed, Disposable, dom, makeTestId} from "grainjs"; | ||
import {commonUrls} from "app/common/gristUrls"; | ||
import {cssLink} from 'app/client/ui2018/links'; | ||
import {ToggleEnterpriseModel} from 'app/client/models/ToggleEnterpriseModel'; | ||
import { | ||
cssOptInButton, | ||
cssOptInOutMessage, | ||
cssOptOutButton, | ||
cssParagraph, | ||
cssSection, | ||
} from 'app/client/ui/AdminTogglesCss'; | ||
|
||
|
||
const t = makeT('ToggleEnterprsiePage'); | ||
const testId = makeTestId('test-toggle-enterprise-page-'); | ||
|
||
export class ToggleEnterpriseWidget extends Disposable { | ||
private readonly _model: ToggleEnterpriseModel = new ToggleEnterpriseModel(); | ||
private readonly _isEnterprise = Computed.create(this, this._model.edition, (_use, edition) => { | ||
return edition === 'enterprise'; | ||
}).onWrite(async (enabled) => { | ||
await this._model.updateEnterpriseToggle(enabled ? 'enterprise' : 'core'); | ||
}); | ||
|
||
constructor() { | ||
super(); | ||
this._model.fetchEnterpriseToggle().catch(reportError); | ||
} | ||
|
||
public getEnterpriseToggleObservable() { | ||
return this._isEnterprise; | ||
} | ||
|
||
public buildEnterpriseSection() { | ||
return cssSection( | ||
dom.domComputed(this._isEnterprise, () => { | ||
return [ | ||
cssParagraph( | ||
t('Activation keys are used to run Grist Enterprise after a trial period ' + | ||
'of 30 days has expired. Get an activation key by signing up for Grist ' + | ||
'Enterprise. You do not need an activation key to run Grist Core.') | ||
), | ||
cssParagraph(t('Learn more in our {{link}}.', { | ||
link: enterpriseHelpCenterLink(), | ||
})), | ||
this._buildEnterpriseSectionButtons(), | ||
]; | ||
}), | ||
testId('enterprise-opt-in-section'), | ||
); | ||
} | ||
|
||
public _buildEnterpriseSectionButtons() { | ||
return dom.domComputed(this._isEnterprise, (enterpriseEnabled) => { | ||
if (enterpriseEnabled) { | ||
return [ | ||
cssOptInOutMessage( | ||
t('Grist Enterprise Edition is enabled.'), | ||
testId('enterprise-opt-out-message'), | ||
), | ||
cssOptOutButton(t('Disable Grist Enterprise Edition'), | ||
dom.on('click', () => this._isEnterprise.set(false)), | ||
), | ||
]; | ||
} else { | ||
return [ | ||
cssOptInButton(t('Enable Grist Enterprise Edition'), | ||
dom.on('click', () => this._isEnterprise.set(true)), | ||
), | ||
]; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function enterpriseHelpCenterLink() { | ||
return cssLink( | ||
t('Help Center'), | ||
{href: commonUrls.helpEnterpriseOptIn, target: '_blank'}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters