Wrap licensing banners and modals in feature flag, disable logo
This commit is contained in:
parent
7018652445
commit
f699bf1b56
|
@ -8,6 +8,7 @@
|
||||||
import { ExpiringKeys } from "./constants"
|
import { ExpiringKeys } from "./constants"
|
||||||
import { getBanners } from "./licensingBanners"
|
import { getBanners } from "./licensingBanners"
|
||||||
import { banner } from "@budibase/bbui"
|
import { banner } from "@budibase/bbui"
|
||||||
|
import { FEATURE_FLAGS, isEnabled } from "../../../helpers/featureFlags"
|
||||||
|
|
||||||
const oneDayInSeconds = 86400
|
const oneDayInSeconds = 86400
|
||||||
|
|
||||||
|
@ -81,7 +82,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (userLoaded && licensingLoaded && loaded) {
|
$: if (
|
||||||
|
userLoaded &&
|
||||||
|
licensingLoaded &&
|
||||||
|
loaded &&
|
||||||
|
isEnabled(FEATURE_FLAGS.LICENSING)
|
||||||
|
) {
|
||||||
queuedModals = processModals()
|
queuedModals = processModals()
|
||||||
queuedBanners = getBanners()
|
queuedBanners = getBanners()
|
||||||
showNextModal()
|
showNextModal()
|
||||||
|
|
|
@ -3,10 +3,12 @@ import { API } from "api"
|
||||||
import { auth } from "stores/portal"
|
import { auth } from "stores/portal"
|
||||||
import { Constants } from "@budibase/frontend-core"
|
import { Constants } from "@budibase/frontend-core"
|
||||||
import { StripeStatus } from "components/portal/licensing/constants"
|
import { StripeStatus } from "components/portal/licensing/constants"
|
||||||
|
import { FEATURE_FLAGS, isEnabled } from "../../helpers/featureFlags"
|
||||||
|
|
||||||
export const createLicensingStore = () => {
|
export const createLicensingStore = () => {
|
||||||
const DEFAULT = {
|
const DEFAULT = {
|
||||||
plans: {},
|
plans: {},
|
||||||
|
usageMetrics: {},
|
||||||
}
|
}
|
||||||
const oneDayInMilliseconds = 86400000
|
const oneDayInMilliseconds = 86400000
|
||||||
|
|
||||||
|
@ -27,78 +29,80 @@ export const createLicensingStore = () => {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getUsageMetrics: async () => {
|
getUsageMetrics: async () => {
|
||||||
const quota = get(store).quotaUsage
|
if (isEnabled(FEATURE_FLAGS.LICENSING)) {
|
||||||
const license = get(auth).user.license
|
const quota = get(store).quotaUsage
|
||||||
const now = new Date()
|
const license = get(auth).user.license
|
||||||
|
const now = new Date()
|
||||||
|
|
||||||
const getMetrics = (keys, license, quota) => {
|
const getMetrics = (keys, license, quota) => {
|
||||||
if (!license || !quota || !keys) {
|
if (!license || !quota || !keys) {
|
||||||
return {}
|
return {}
|
||||||
|
}
|
||||||
|
return keys.reduce((acc, key) => {
|
||||||
|
const quotaLimit = license[key].value
|
||||||
|
const quotaUsed = (quota[key] / quotaLimit) * 100
|
||||||
|
acc[key] = quotaLimit > -1 ? Math.round(quotaUsed) : -1
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
}
|
}
|
||||||
return keys.reduce((acc, key) => {
|
const monthlyMetrics = getMetrics(
|
||||||
const quotaLimit = license[key].value
|
["dayPasses", "queries", "automations"],
|
||||||
const quotaUsed = (quota[key] / quotaLimit) * 100
|
license.quotas.usage.monthly,
|
||||||
acc[key] = quotaLimit > -1 ? Math.round(quotaUsed) : -1
|
quota.monthly.current
|
||||||
return acc
|
)
|
||||||
}, {})
|
const staticMetrics = getMetrics(
|
||||||
}
|
["apps", "rows"],
|
||||||
const monthlyMetrics = getMetrics(
|
license.quotas.usage.static,
|
||||||
["dayPasses", "queries", "automations"],
|
quota.usageQuota
|
||||||
license.quotas.usage.monthly,
|
|
||||||
quota.monthly.current
|
|
||||||
)
|
|
||||||
const staticMetrics = getMetrics(
|
|
||||||
["apps", "rows"],
|
|
||||||
license.quotas.usage.static,
|
|
||||||
quota.usageQuota
|
|
||||||
)
|
|
||||||
|
|
||||||
const getDaysBetween = (dateStart, dateEnd) => {
|
|
||||||
return dateEnd > dateStart
|
|
||||||
? Math.round(
|
|
||||||
(dateEnd.getTime() - dateStart.getTime()) / oneDayInMilliseconds
|
|
||||||
)
|
|
||||||
: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
const quotaResetDate = new Date(quota.quotaReset)
|
|
||||||
const quotaResetDaysRemaining = getDaysBetween(now, quotaResetDate)
|
|
||||||
|
|
||||||
const accountDowngraded =
|
|
||||||
license?.billing?.subscription?.downgradeAt &&
|
|
||||||
license?.billing?.subscription?.downgradeAt <= now.getTime() &&
|
|
||||||
license?.billing?.subscription?.status === StripeStatus.PAST_DUE &&
|
|
||||||
license?.plan.type === Constants.PlanType.FREE
|
|
||||||
|
|
||||||
const pastDueAtMilliseconds = license?.billing?.subscription?.pastDueAt
|
|
||||||
const downgradeAtMilliseconds =
|
|
||||||
license?.billing?.subscription?.downgradeAt
|
|
||||||
let pastDueDaysRemaining
|
|
||||||
let pastDueEndDate
|
|
||||||
|
|
||||||
if (pastDueAtMilliseconds && downgradeAtMilliseconds) {
|
|
||||||
pastDueEndDate = new Date(downgradeAtMilliseconds)
|
|
||||||
pastDueDaysRemaining = getDaysBetween(
|
|
||||||
new Date(pastDueAtMilliseconds),
|
|
||||||
pastDueEndDate
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
store.update(state => {
|
const getDaysBetween = (dateStart, dateEnd) => {
|
||||||
return {
|
return dateEnd > dateStart
|
||||||
...state,
|
? Math.round(
|
||||||
usageMetrics: { ...monthlyMetrics, ...staticMetrics },
|
(dateEnd.getTime() - dateStart.getTime()) / oneDayInMilliseconds
|
||||||
quotaResetDaysRemaining,
|
)
|
||||||
quotaResetDate,
|
: 0
|
||||||
accountDowngraded,
|
|
||||||
accountPastDue: pastDueAtMilliseconds != null,
|
|
||||||
pastDueEndDate,
|
|
||||||
pastDueDaysRemaining,
|
|
||||||
isFreePlan: () => {
|
|
||||||
return license?.plan.type === Constants.PlanType.FREE
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
const quotaResetDate = new Date(quota.quotaReset)
|
||||||
|
const quotaResetDaysRemaining = getDaysBetween(now, quotaResetDate)
|
||||||
|
|
||||||
|
const accountDowngraded =
|
||||||
|
license?.billing?.subscription?.downgradeAt &&
|
||||||
|
license?.billing?.subscription?.downgradeAt <= now.getTime() &&
|
||||||
|
license?.billing?.subscription?.status === StripeStatus.PAST_DUE &&
|
||||||
|
license?.plan.type === Constants.PlanType.FREE
|
||||||
|
|
||||||
|
const pastDueAtMilliseconds = license?.billing?.subscription?.pastDueAt
|
||||||
|
const downgradeAtMilliseconds =
|
||||||
|
license?.billing?.subscription?.downgradeAt
|
||||||
|
let pastDueDaysRemaining
|
||||||
|
let pastDueEndDate
|
||||||
|
|
||||||
|
if (pastDueAtMilliseconds && downgradeAtMilliseconds) {
|
||||||
|
pastDueEndDate = new Date(downgradeAtMilliseconds)
|
||||||
|
pastDueDaysRemaining = getDaysBetween(
|
||||||
|
new Date(pastDueAtMilliseconds),
|
||||||
|
pastDueEndDate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
store.update(state => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
usageMetrics: { ...monthlyMetrics, ...staticMetrics },
|
||||||
|
quotaResetDaysRemaining,
|
||||||
|
quotaResetDate,
|
||||||
|
accountDowngraded,
|
||||||
|
accountPastDue: pastDueAtMilliseconds != null,
|
||||||
|
pastDueEndDate,
|
||||||
|
pastDueDaysRemaining,
|
||||||
|
isFreePlan: () => {
|
||||||
|
return license?.plan.type === Constants.PlanType.FREE
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export const PlanType = {
|
export const PlanType = {
|
||||||
FREE: "free",
|
FREE: "free",
|
||||||
|
PRO: "pro",
|
||||||
TEAM: "team",
|
TEAM: "team",
|
||||||
BUSINESS: "business",
|
BUSINESS: "business",
|
||||||
ENTERPRISE: "enterprise",
|
ENTERPRISE: "enterprise",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { isFreePlan } from "./utils.js"
|
// import { isFreePlan } from "./utils.js"
|
||||||
|
|
||||||
export const logoEnabled = () => {
|
export const logoEnabled = () => {
|
||||||
return isFreePlan()
|
return false
|
||||||
|
// return isFreePlan()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue