Skip to content

Commit

Permalink
feat(console): add token exceed tag (#6904)
Browse files Browse the repository at this point in the history
add token exceed tag to tenant drop down item
  • Loading branch information
simeng-li authored Dec 24, 2024
1 parent ea5a62b commit c6495fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { type TenantResponse } from '@/cloud/types/router';
import DynamicT from '@/ds-components/DynamicT';
import Tag from '@/ds-components/Tag';
import { isPaidPlan } from '@/utils/subscription';

type Props = {
readonly tenantData: TenantResponse;
readonly className?: string;
};

function TenantStatusTag({ tenantData, className }: Props) {
const { usage, quota, openInvoices, isSuspended } = tenantData;
const {
usage,
quota,
openInvoices,
isSuspended,
subscription: { planId, isEnterprisePlan },
} = tenantData;

/**
* Tenant status priority:
* 1. suspend
* 2. overdue
* 3. mau exceeded
* 4. token exceeded
*/

if (isSuspended) {
Expand All @@ -33,11 +41,14 @@ function TenantStatusTag({ tenantData, className }: Props) {
);
}

const { activeUsers } = usage;
const isPaidTenant = isPaidPlan(planId, isEnterprisePlan);

const { mauLimit } = quota;
const { activeUsers, tokenUsage } = usage;

const { mauLimit, tokenLimit } = quota;

const isMauExceeded = mauLimit !== null && activeUsers >= mauLimit;
const isTokenExceeded = tokenLimit !== null && !isPaidTenant && tokenUsage >= tokenLimit;

if (isMauExceeded) {
return (
Expand All @@ -47,6 +58,14 @@ function TenantStatusTag({ tenantData, className }: Props) {
);
}

if (isTokenExceeded) {
return (
<Tag className={className}>
<DynamicT forKey="tenants.status.token_exceeded" />
</Tag>
);
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const tenants = {
create_tenant_button: 'Create tenant',
},
status: {
mau_exceeded: 'MAU Exceeded',
mau_exceeded: 'MAU exceeded',
token_exceeded: 'Token exceeded',
suspended: 'Suspended',
overdue: 'Overdue',
},
Expand Down

0 comments on commit c6495fc

Please sign in to comment.