mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2026-03-13 10:00:26 +08:00
refactor: plan logic (#217)
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
* Include localhost:8000 to cover the default dev backend when APPFLOWY_BASE_URL isn't updated.
|
||||
* Self-hosted instances are not official hosts.
|
||||
*/
|
||||
import { Subscription, SubscriptionPlan } from '@/application/types';
|
||||
import { getConfigValue } from '@/utils/runtime-config';
|
||||
|
||||
const OFFICIAL_HOSTNAMES = new Set(['beta.appflowy.cloud', 'test.appflowy.cloud', 'localhost']);
|
||||
const PRO_ACCESS_PLANS = new Set([SubscriptionPlan.Pro, SubscriptionPlan.Team]);
|
||||
|
||||
function getBaseUrlHostname(): string | null {
|
||||
const baseUrl = getConfigValue('APPFLOWY_BASE_URL', '').trim();
|
||||
@@ -60,3 +62,15 @@ export function isAppFlowyHosted(): boolean {
|
||||
|
||||
return isOfficialHostname(resolveHostname());
|
||||
}
|
||||
|
||||
export function hasProAccessFromPlans(plans?: SubscriptionPlan[] | null): boolean {
|
||||
if (!plans || plans.length === 0) return false;
|
||||
return plans.some((plan) => PRO_ACCESS_PLANS.has(plan));
|
||||
}
|
||||
|
||||
export function getProAccessPlanFromSubscriptions(subscriptions?: Subscription[] | null): SubscriptionPlan {
|
||||
if (!subscriptions || subscriptions.length === 0) return SubscriptionPlan.Free;
|
||||
return subscriptions.some((subscription) => PRO_ACCESS_PLANS.has(subscription.plan))
|
||||
? SubscriptionPlan.Pro
|
||||
: SubscriptionPlan.Free;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user