Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): normalize billing quota semantics in one place (#45117)

yyh0f22916d08d1
diff --git a/web/__tests__/billing/billing-integration.test.tsx b/web/__tests__/billing/billing-integration.test.tsx
index 6ef3b57cc2d..7d5f9c4bc82 100644
--- a/web/__tests__/billing/billing-integration.test.tsx
+++ b/web/__tests__/billing/billing-integration.test.tsx
@@ -463,9 +463,7 @@ describe('Capacity Full Components Integration', () => {
<TriggerEventsLimitModal
show={true}
onClose={vi.fn()}
- usage={18000}
- total={20000}
- resetInDays={5}
+ quota={{ usage: 18000, limit: 20000, resetInDays: 5 }}
/>,
)
@@ -484,7 +482,13 @@ describe('Capacity Full Components Integration', () => {
const onClose = vi.fn()
setupBilling({ billing: { subscription: { plan: 'professional' } } })
- render(<TriggerEventsLimitModal show={true} onClose={onClose} usage={20000} total={20000} />)
+ render(
+ <TriggerEventsLimitModal
+ show={true}
+ onClose={onClose}
+ quota={{ usage: 20000, limit: 20000 }}
+ />,
+ )
const upgradeBtn = screen.getByText(/triggerLimitModal\.upgrade/i)
await user.click(upgradeBtn)
diff --git a/web/app/components/billing/__tests__/quota.spec.ts b/web/app/components/billing/__tests__/quota.spec.ts
new file mode 100644
index 00000000000..3ccd2dc8215
--- /dev/null
+++ b/web/app/components/billing/__tests__/quota.spec.ts
@@ -0,0 +1,48 @@
+import { getAppRunsQuota, getCountQuota, getTriggerEventsQuota } from '../quota'
+
+describe('billing quotas', () => {
+ beforeEach(() => {
+ vi.useFakeTimers()
+ vi.setSystemTime(new Date(2026, 8, 7, 12))
+ })
+ afterEach(() => vi.useRealTimers())
+
+ const inSevenDays = new Date(2026, 8, 14).getTime() / 1000
+
+ it('treats a zero count limit as unlimited', () => {
+ expect(getCountQuota({ size: 3, limit: 0 })).toEqual({ usage: 3, limit: 'unlimited' })
+ expect(getCountQuota({ size: 3, limit: 5 })).toEqual({ usage: 3, limit: 5 })
+ })
+
+ it('treats -1 as unlimited and keeps zero as zero capacity for periodic quotas', () => {
+ expect(getAppRunsQuota({ usage: 9, limit: -1, reset_date: -1 }, 'team')).toEqual({
+ usage: 9,
+ limit: 'unlimited',
+ })
+ expect(getTriggerEventsQuota({ usage: 0, limit: 0, reset_date: -1 }, 'sandbox')).toEqual({
+ usage: 0,
+ limit: 0,
+ })
+ })
+
+ it('shows trigger event resets only for the Professional plan', () => {
+ const quota = { usage: 1, limit: 20000, reset_date: inSevenDays }
+
+ expect(getTriggerEventsQuota(quota, 'professional').resetInDays).toBe(7)
+ expect(getTriggerEventsQuota(quota, 'sandbox').resetInDays).toBeUndefined()
+ })
+
+ it('falls back to the end of the month for Sandbox App Runs without a reset date', () => {
+ expect(getAppRunsQuota({ usage: 1, limit: 5000, reset_date: inSevenDays }, 'sandbox')).toEqual({
+ usage: 1,
+ limit: 5000,
+ resetInDays: 7,
+ })
+ expect(getAppRunsQuota({ usage: 1, limit: 5000, reset_date: -1 }, 'sandbox').resetInDays).toBe(
+ 23,
+ )
+ expect(
+ getAppRunsQuota({ usage: 1, limit: 5000, reset_date: -1 }, 'professional').resetInDays,
+ ).toBeUndefined()
+ })
+})
diff --git a/web/app/components/billing/annotation-full/usage.tsx b/web/app/components/billing/annotation-full/usage.tsx
index 534ca75c3a1..600248504f1 100644
--- a/web/app/components/billing/annotation-full/usage.tsx
+++ b/web/app/components/billing/annotation-full/usage.tsx
@@ -4,8 +4,8 @@ import { useQuery } from '@tanstack/react-query'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { consoleQuery } from '@/service/console'
+import { getCountQuota } from '../quota'
import UsageInfo from '../usage-info'
-import { parseLimit } from '../utils'
type Props = Readonly<{
className?: string
@@ -24,8 +24,7 @@ const Usage: FC<Props> = ({ className }) => {
className={className}
iconClassName={'i-custom-vender-line-communication-message-fast-plus'}
name={t(($) => $['annotatedResponse.quotaTitle'], { ns: 'billing' })}
- usage={annotationQuota.size}
- total={parseLimit(annotationQuota.limit)}
+ quota={getCountQuota(annotationQuota)}
/>
)
}
diff --git a/web/app/components/billing/plan/index.tsx b/web/app/components/billing/plan/index.tsx
index d675425224a..f5c4438161b 100644
--- a/web/app/components/billing/plan/index.tsx
+++ b/web/app/components/billing/plan/index.tsx
@@ -12,12 +12,10 @@ import { isCurrentWorkspaceManagerAtom } from '@/context/workspace-state'
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
import Link from '@/next/link'
import { consoleQuery } from '@/service/console'
-import { getDaysUntilEndOfMonth } from '@/utils/time'
-import { NUM_INFINITE } from '../config'
import { useEducationDiscount } from '../hooks/use-education-discount'
+import { getAppRunsQuota, getCountQuota, getTriggerEventsQuota } from '../quota'
import UpgradeBtn from '../upgrade-btn'
import VectorSpaceInfo from '../usage-info/vector-space-info'
-import { getResetInDaysFromDate, parseLimit } from '../utils'
import { Professional, Sandbox, Team } from './assets'
type Props = Readonly<{
@@ -47,19 +45,7 @@ const PlanComp: FC<Props> = ({ loc }) => {
)
const { isAboutToExpire = false, isEducationAccount = false } = educationStatus ?? {}
const type = features.billing.subscription.plan
- const triggerEventsLimit = features.trigger_event.limit
- const apiRateLimit = features.api_rate_limit.limit
- const apiRateLimitReset = getResetInDaysFromDate(features.api_rate_limit.reset_date)
- const triggerEventsResetInDays =
- type === 'professional' && triggerEventsLimit !== NUM_INFINITE
- ? (getResetInDaysFromDate(features.trigger_event.reset_date) ?? undefined)
- : undefined
- const apiRateLimitResetInDays = (() => {
- if (apiRateLimit === NUM_INFINITE) return undefined
- if (typeof apiRateLimitReset === 'number') return apiRateLimitReset
- if (type === 'sandbox') return getDaysUntilEndOfMonth()
- return undefined
- })()
+ const appRunsQuota = getAppRunsQuota(features.api_rate_limit, type)
const { handleEducationDiscount, isEducationDiscountLoading } = useEducationDiscount()
return (
@@ -129,47 +115,39 @@ const PlanComp: FC<Props> = ({ loc }) => {
<UsageInfo
iconClassName="i-ri-apps-2-line"
name={t(($) => $['usagePage.buildApps'], { ns: 'billing' })}
- usage={features.apps.size}
- total={parseLimit(features.apps.limit)}
+ quota={getCountQuota(features.apps)}
/>
<UsageInfo
iconClassName="i-ri-group-line"
name={t(($) => $['usagePage.teamMembers'], { ns: 'billing' })}
- usage={features.members.size}
- total={parseLimit(features.members.limit)}
+ quota={getCountQuota(features.members)}
/>
<UsageInfo
iconClassName="i-ri-book-2-line"
name={t(($) => $['usagePage.documentsUploadQuota'], { ns: 'billing' })}
- usage={features.documents_upload_quota.size}
- total={parseLimit(features.documents_upload_quota.limit)}
+ quota={getCountQuota(features.documents_upload_quota)}
/>
<VectorSpaceInfo />
<UsageInfo
iconClassName="i-ri-file-edit-line"
name={t(($) => $['usagePage.annotationQuota'], { ns: 'billing' })}
- usage={features.annotation_quota_limit.size}
- total={parseLimit(features.annotation_quota_limit.limit)}
+ quota={getCountQuota(features.annotation_quota_limit)}
/>
<UsageInfo
iconClassName={'i-custom-vender-workflow-trigger-all'}
name={t(($) => $['usagePage.triggerEvents'], { ns: 'billing' })}
- usage={features.trigger_event.usage}
- total={triggerEventsLimit}
+ quota={getTriggerEventsQuota(features.trigger_event, type)}
tooltip={t(($) => $['plansCommon.triggerEvents.tooltip'], { ns: 'billing' }) as string}
- resetInDays={triggerEventsResetInDays}
/>
<UsageInfo
iconClassName={'i-custom-vender-workflow-api-aggregate'}
name={t(($) => $['plansCommon.apiRateLimit'], { ns: 'billing' })}
- usage={features.api_rate_limit.usage}
- total={apiRateLimit}
+ quota={appRunsQuota}
tooltip={
- apiRateLimit === NUM_INFINITE
+ appRunsQuota.limit === 'unlimited'
? undefined
: (t(($) => $['plansCommon.apiRateLimitTooltip'], { ns: 'billing' }) as string)
}
- resetInDays={apiRateLimitResetInDays}
/>
</div>
</div>
diff --git a/web/app/components/billing/quota.ts b/web/app/components/billing/quota.ts
new file mode 100644
index 00000000000..29dbb4ebd78
--- /dev/null
+++ b/web/app/components/billing/quota.ts
@@ -0,0 +1,60 @@
+import type {
+ CloudPlan,
+ LimitationModel,
+ Quota,
+ VectorSpaceLimitationModel,
+} from '@dify/contracts/api/console/features/types.gen'
+import dayjs from 'dayjs'
+import { getDaysUntilEndOfMonth } from '@/utils/time'
+
+export type BillingQuota = {
+ usage: number
+ limit: number | 'unlimited'
+ resetInDays?: number
+}
+
+// Next reset as a Unix timestamp in seconds; -1 means no reset.
+const getResetInDays = (resetDate: number) => {
+ if (resetDate <= 0) return undefined
+
+ const diff = dayjs.unix(resetDate).startOf('day').diff(dayjs().startOf('day'), 'day')
+ return diff >= 0 ? diff : undefined
+}
+
+// Apps, members, document uploads and annotations use 0 for unlimited.
+export const getCountQuota = ({ size, limit }: LimitationModel): BillingQuota => ({
+ usage: size,
+ limit: limit === 0 ? 'unlimited' : limit,
+})
+
+export const getVectorSpaceQuota = ({ size, limit }: VectorSpaceLimitationModel): BillingQuota => ({
+ usage: size,
+ limit: limit === -1 ? 'unlimited' : limit,
+})
+
+// Trigger events and App Runs use -1 for unlimited; 0 is zero capacity.
+const getPeriodicQuota = ({ usage, limit }: Quota) => ({
+ usage,
+ limit: limit < 0 ? ('unlimited' as const) : limit,
+})
+
+// Only the Professional trigger event quota renews with the subscription period.
+export const getTriggerEventsQuota = (quota: Quota, plan: CloudPlan): BillingQuota => {
+ const periodicQuota = getPeriodicQuota(quota)
+ if (periodicQuota.limit === 'unlimited' || plan !== 'professional') return periodicQuota
+
+ return { ...periodicQuota, resetInDays: getResetInDays(quota.reset_date) }
+}
+
+// Billing counts every app run against `api_rate_limit`; the Sandbox quota renews monthly.
+export const getAppRunsQuota = (quota: Quota, plan: CloudPlan): BillingQuota => {
+ const periodicQuota = getPeriodicQuota(quota)
+ if (periodicQuota.limit === 'unlimited') return periodicQuota
+
+ return {
+ ...periodicQuota,
+ resetInDays:
+ getResetInDays(quota.reset_date) ??
+ (plan === 'sandbox' ? getDaysUntilEndOfMonth() : undefined),
+ }
+}
diff --git a/web/app/components/billing/trigger-events-limit-modal/index.tsx b/web/app/components/billing/trigger-events-limit-modal/index.tsx
index 01fd35639bc..2048cbf7aaa 100644
--- a/web/app/components/billing/trigger-events-limit-modal/index.tsx
+++ b/web/app/components/billing/trigger-events-limit-modal/index.tsx
@@ -1,4 +1,5 @@
'use client'
+import type { BillingQuota } from '../quota'
import { useTranslation } from 'react-i18next'
import { PlanUpgradeModal } from '@/app/components/billing/plan-upgrade-modal'
import UsageInfo from '@/app/components/billing/usage-info'
@@ -6,18 +7,10 @@ import UsageInfo from '@/app/components/billing/usage-info'
type Props = Readonly<{
show: boolean
onClose: () => void
- usage: number
- total: number
- resetInDays?: number
+ quota: BillingQuota
}>
-export default function TriggerEventsLimitModal({
- show,
- onClose,
- usage,
- total,
- resetInDays,
-}: Props) {
+export default function TriggerEventsLimitModal({ show, onClose, quota }: Props) {
const { t } = useTranslation(['billing'])
return (
@@ -32,9 +25,7 @@ export default function TriggerEventsLimitModal({
className="mt-4 w-full rounded-xl bg-components-panel-on-panel-item-bg"
iconClassName={'i-custom-vender-workflow-trigger-all'}
name={t(($) => $['triggerLimitModal.usageTitle'], { ns: 'billing' })}
- usage={usage}
- total={total}
- resetInDays={resetInDays}
+ quota={quota}
hideIcon
/>
}
diff --git a/web/app/components/billing/usage-info/__tests__/index.spec.tsx b/web/app/components/billing/usage-info/__tests__/index.spec.tsx
index ca4cd43e54d..6f46660e376 100644
--- a/web/app/components/billing/usage-info/__tests__/index.spec.tsx
+++ b/web/app/components/billing/usage-info/__tests__/index.spec.tsx
@@ -7,8 +7,7 @@ const storageProps = {
name: 'Knowledge Data Storage',
tooltip: 'High quality documents use storage.',
storageTooltip: 'Detailed usage is shown once storage exceeds 50 MB.',
- usage: 20,
- total: 50,
+ quota: { usage: 20, limit: 50 },
unit: 'MB',
storageMode: true,
isSandboxPlan: true,
diff --git a/web/app/components/billing/usage-info/index.tsx b/web/app/components/billing/usage-info/index.tsx
index 439a417dc91..6ef10aa5103 100644
--- a/web/app/components/billing/usage-info/index.tsx
+++ b/web/app/components/billing/usage-info/index.tsx
@@ -1,24 +1,22 @@
'use client'
import type { MeterTone } from '@langgenius/dify-ui/meter'
import type { FC, ReactNode } from 'react'
+import type { BillingQuota } from '../quota'
import { cn } from '@langgenius/dify-ui/cn'
import { Infotip, InfotipContent, InfotipTrigger } from '@langgenius/dify-ui/infotip'
import { Meter, MeterIndicator, MeterTrack } from '@langgenius/dify-ui/meter'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
-import { NUM_INFINITE } from '../config'
type Props = Readonly<{
className?: string
iconClassName: string
name: string
tooltip?: string
- usage: number
- total: number
+ quota: BillingQuota
unit?: string
unitPosition?: 'inline' | 'suffix'
resetHint?: string
- resetInDays?: number
hideIcon?: boolean
// Props for the 50MB threshold display logic
storageMode?: boolean
@@ -33,12 +31,10 @@ const UsageInfo: FC<Props> = ({
iconClassName,
name,
tooltip,
- usage,
- total,
+ quota,
unit,
unitPosition = 'suffix',
resetHint,
- resetInDays,
hideIcon = false,
storageMode = false,
storageThreshold = 50,
@@ -49,23 +45,24 @@ const UsageInfo: FC<Props> = ({
const labelId = React.useId()
const { t } = useTranslation(['billing'])
+ const { usage, limit, resetInDays } = quota
const isBelowThreshold = !usageUnknown && storageMode && usage < storageThreshold
const isSandboxFull = !usageUnknown && storageMode && isSandboxPlan && usage >= storageThreshold
const storageHelp = !usageUnknown && storageMode ? storageTooltip : undefined
// Zero count quotas have no remaining capacity; storage keeps its separate limit convention.
- const isZeroQuota = !storageMode && total === 0
- const rawPercent = total > 0 ? (usage / total) * 100 : 0
+ const isZeroQuota = !storageMode && limit === 0
+ const rawPercent = limit !== 'unlimited' && limit > 0 ? (usage / limit) * 100 : 0
const effectivePercent = isSandboxFull || isZeroQuota ? 100 : Math.min(rawPercent, 100)
const tone: MeterTone =
effectivePercent >= 100 ? 'error' : effectivePercent >= 80 ? 'warning' : 'neutral'
- const isUnlimited = total === NUM_INFINITE
+ const isUnlimited = limit === 'unlimited'
let totalDisplay: string | number = isUnlimited
? t(($) => $['plansCommon.unlimited'], { ns: 'billing' })
- : total
- if (!isUnlimited && unit && unitPosition === 'inline') totalDisplay = `${total}${unit}`
+ : limit
+ if (!isUnlimited && unit && unitPosition === 'inline') totalDisplay = `${limit}${unit}`
const showUnit = !!unit && !isUnlimited && unitPosition === 'suffix'
const resetText =
resetHint ??
diff --git a/web/app/components/billing/usage-info/vector-space-info.tsx b/web/app/components/billing/usage-info/vector-space-info.tsx
index c5829baa4f5..6d98a99c5ee 100644
--- a/web/app/components/billing/usage-info/vector-space-info.tsx
+++ b/web/app/components/billing/usage-info/vector-space-info.tsx
@@ -4,6 +4,7 @@ import { useSuspenseQueries } from '@tanstack/react-query'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { consoleQuery } from '@/service/console'
+import { getVectorSpaceQuota } from '../quota'
import UsageInfo from '../usage-info'
import { getPlanVectorSpaceLimitMB } from '../utils'
@@ -31,8 +32,7 @@ const VectorSpaceInfo: FC<Props> = ({ className }) => {
iconClassName="i-ri-hard-drive-3-line"
name={t(($) => $['usagePage.vectorSpace'], { ns: 'billing' })}
tooltip={t(($) => $['usagePage.vectorSpaceTooltip'], { ns: 'billing' }) as string}
- usage={vectorSpace.size}
- total={vectorSpace.limit}
+ quota={getVectorSpaceQuota(vectorSpace)}
unit="MB"
unitPosition="inline"
storageMode
diff --git a/web/app/components/billing/utils/__tests__/index.spec.ts b/web/app/components/billing/utils/__tests__/index.spec.ts
index 0b7bdcacee8..bacd8d3b6b1 100644
--- a/web/app/components/billing/utils/__tests__/index.spec.ts
+++ b/web/app/components/billing/utils/__tests__/index.spec.ts
@@ -1,4 +1,4 @@
-import { getResetInDaysFromDate, parseLimit, parseVectorSpaceToMB } from '../index'
+import { parseVectorSpaceToMB } from '../index'
describe('billing utils', () => {
it.each([
@@ -11,30 +11,4 @@ describe('billing utils', () => {
])('converts vector storage %s to %i MB', (value, expected) => {
expect(parseVectorSpaceToMB(value)).toBe(expected)
})
-
- describe('quota reset dates', () => {
- beforeEach(() => {
- vi.useFakeTimers()
- vi.setSystemTime(new Date(2026, 8, 7, 12))
- })
- afterEach(() => vi.useRealTimers())
- it('handles Unix timestamps in seconds and milliseconds', () => {
- const resetDate = new Date(2026, 8, 14).getTime()
- expect(getResetInDaysFromDate(resetDate)).toBe(7)
- expect(getResetInDaysFromDate(resetDate / 1000)).toBe(7)
- })
- it('handles calendar dates and omits absent or past resets', () => {
- expect(getResetInDaysFromDate(20260914)).toBe(7)
- expect(getResetInDaysFromDate(0)).toBeNull()
- expect(getResetInDaysFromDate(-1)).toBeNull()
- expect(getResetInDaysFromDate(20260901)).toBeNull()
- })
- })
-
- describe('quota display', () => {
- it('displays zero count limits as unlimited', () => {
- expect(parseLimit(0)).toBe(-1)
- expect(parseLimit(10)).toBe(10)
- })
- })
})
diff --git a/web/app/components/billing/utils/index.ts b/web/app/components/billing/utils/index.ts
index 740da620893..7eb51998db0 100644
--- a/web/app/components/billing/utils/index.ts
+++ b/web/app/components/billing/utils/index.ts
@@ -1,6 +1,5 @@
import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
-import dayjs from 'dayjs'
-import { ALL_PLANS, NUM_INFINITE } from '@/app/components/billing/config'
+import { ALL_PLANS } from '@/app/components/billing/config'
/**
* Parse vectorSpace string from ALL_PLANS config and convert to MB
@@ -22,40 +21,3 @@ export const parseVectorSpaceToMB = (vectorSpace: string): number => {
export const getPlanVectorSpaceLimitMB = (planType: CloudPlan): number => {
return parseVectorSpaceToMB(ALL_PLANS[planType].vectorSpace)
}
-
-// App, member, document upload, and annotation quotas use 0 for unlimited.
-// Event and API quotas use -1 for unlimited and must preserve 0 as zero capacity.
-export const parseLimit = (limit: number) => {
- if (limit === 0) return NUM_INFINITE
-
- return limit
-}
-
-const normalizeResetDate = (resetDate: number) => {
- if (resetDate <= 0) return null
-
- if (resetDate >= 1e12) return dayjs(resetDate)
-
- if (resetDate >= 1e9) return dayjs(resetDate * 1000)
-
- const digits = resetDate.toString()
- if (digits.length === 8) {
- const year = digits.slice(0, 4)
- const month = digits.slice(4, 6)
- const day = digits.slice(6, 8)
- const parsed = dayjs(`${year}-${month}-${day}`)
- return parsed.isValid() ? parsed : null
- }
-
- return null
-}
-
-export const getResetInDaysFromDate = (resetDate: number) => {
- const resetDay = normalizeResetDate(resetDate)
- if (!resetDay) return null
-
- const diff = resetDay.startOf('day').diff(dayjs().startOf('day'), 'day')
- if (Number.isNaN(diff) || diff < 0) return null
-
- return diff
-}
diff --git a/web/context/hooks/use-trigger-events-limit-modal.ts b/web/context/hooks/use-trigger-events-limit-modal.ts
index c19b9adab2f..18e30dbb824 100644
--- a/web/context/hooks/use-trigger-events-limit-modal.ts
+++ b/web/context/hooks/use-trigger-events-limit-modal.ts
@@ -1,20 +1,15 @@
+import type { BillingQuota } from '@/app/components/billing/quota'
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
import dayjs from 'dayjs'
import { useAtomValue } from 'jotai'
import { useEffect, useState } from 'react'
-import { getResetInDaysFromDate } from '@/app/components/billing/utils'
+import { getTriggerEventsQuota } from '@/app/components/billing/quota'
import { currentWorkspaceIdAtom } from '@/context/workspace-state'
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
import { consoleQuery } from '@/service/console'
-type TriggerEventsLimitModalContent = {
- usage: number
- total: number
- resetInDays?: number
-}
-
type UseTriggerEventsLimitModalResult = {
- triggerEventsLimitModal: TriggerEventsLimitModalContent | null
+ triggerEventsLimitModal: BillingQuota | null
dismissTriggerEventsLimitModal: () => void
}
@@ -26,31 +21,31 @@ export const useTriggerEventsLimitModal = (): UseTriggerEventsLimitModalResult =
...systemFeaturesQueryOptions(),
select: ({ deployment_edition }) => deployment_edition,
})
- const { data: quota } = useQuery(
+ const { data: triggerEvents } = useQuery(
consoleQuery.features.get.queryOptions({
enabled: deploymentEdition === 'CLOUD',
select: ({ billing, trigger_event }) => ({
plan: billing.subscription.plan,
- ...trigger_event,
+ quota: getTriggerEventsQuota(trigger_event, billing.subscription.plan),
}),
}),
)
const [dismissedCycles, setDismissedCycles] = useState<Record<string, boolean>>({})
- const resetInDays = quota ? getResetInDaysFromDate(quota.reset_date) : null
+ const resetInDays = triggerEvents?.quota.resetInDays
const cycleTag =
- resetInDays !== null
+ resetInDays !== undefined
? dayjs().startOf('day').add(resetInDays, 'day').format('YYYY-MM-DD')
- : quota?.plan === 'sandbox'
+ : triggerEvents?.plan === 'sandbox'
? dayjs().endOf('month').format('YYYY-MM-DD')
: 'none'
const storageKey =
deploymentEdition === 'CLOUD' &&
currentWorkspaceId &&
- quota &&
- quota.plan !== 'team' &&
- quota.limit >= 0 &&
- quota.usage >= quota.limit
- ? `${TRIGGER_EVENTS_LOCALSTORAGE_PREFIX}-${currentWorkspaceId}-${quota.plan}-${quota.limit}-${cycleTag}`
+ triggerEvents &&
+ triggerEvents.plan !== 'team' &&
+ triggerEvents.quota.limit !== 'unlimited' &&
+ triggerEvents.quota.usage >= triggerEvents.quota.limit
+ ? `${TRIGGER_EVENTS_LOCALSTORAGE_PREFIX}-${currentWorkspaceId}-${triggerEvents.plan}-${triggerEvents.quota.limit}-${cycleTag}`
: null
const dismissed = storageKey ? dismissedCycles[storageKey] : undefined
@@ -79,13 +74,7 @@ export const useTriggerEventsLimitModal = (): UseTriggerEventsLimitModalResult =
return {
triggerEventsLimitModal:
- storageKey && dismissed === false && quota
- ? {
- usage: quota.usage,
- total: quota.limit,
- resetInDays: quota.plan === 'professional' ? (resetInDays ?? undefined) : undefined,
- }
- : null,
+ storageKey && dismissed === false && triggerEvents ? triggerEvents.quota : null,
dismissTriggerEventsLimitModal,
}
}
diff --git a/web/context/modal-context-provider.tsx b/web/context/modal-context-provider.tsx
index 3919c148606..ca1a9429a17 100644
--- a/web/context/modal-context-provider.tsx
+++ b/web/context/modal-context-provider.tsx
@@ -282,9 +282,7 @@ export const ModalContextProvider = ({ children }: ModalContextProviderProps) =>
{!!triggerEventsLimitModal && (
<TriggerEventsLimitModal
show
- usage={triggerEventsLimitModal.usage}
- total={triggerEventsLimitModal.total}
- resetInDays={triggerEventsLimitModal.resetInDays}
+ quota={triggerEventsLimitModal}
onClose={dismissTriggerEventsLimitModal}
/>
)}