mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +00:00
fix(web): show used quota for unlimited API keys (#6224)
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from '@/components/ui/tooltip'
|
} from '@/components/ui/tooltip'
|
||||||
import { copyToClipboard } from '@/lib/copy-to-clipboard'
|
import { copyToClipboard } from '@/lib/copy-to-clipboard'
|
||||||
|
import { formatQuota } from '@/lib/format'
|
||||||
|
|
||||||
import type { ApiKey } from '../types'
|
import type { ApiKey } from '../types'
|
||||||
import { useApiKeys } from './api-keys-provider'
|
import { useApiKeys } from './api-keys-provider'
|
||||||
@@ -141,6 +142,40 @@ export function ApiKeyCell({ apiKey }: { apiKey: ApiKey }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UnlimitedQuotaBadgeProps = {
|
||||||
|
used: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UnlimitedQuotaBadge(props: UnlimitedQuotaBadgeProps) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const formattedUsed = formatQuota(props.used)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger
|
||||||
|
render={
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
className='focus-visible:ring-ring/50 -ml-1.5 cursor-help rounded-4xl focus-visible:ring-[3px] focus-visible:outline-none'
|
||||||
|
aria-label={`${t('Unlimited')}; ${t('Used:')} ${formattedUsed}`}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<StatusBadge
|
||||||
|
label={t('Unlimited')}
|
||||||
|
variant='neutral'
|
||||||
|
copyable={false}
|
||||||
|
/>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className='w-auto p-2' side='top'>
|
||||||
|
<span className='text-xs'>
|
||||||
|
{t('Used:')} {formattedUsed}
|
||||||
|
</span>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function ModelLimitsCell({ apiKey }: { apiKey: ApiKey }) {
|
export function ModelLimitsCell({ apiKey }: { apiKey: ApiKey }) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,9 @@ import type { ApiKey } from '../types'
|
|||||||
import { ApiKeyTimestampCell } from './api-key-timestamp-cell'
|
import { ApiKeyTimestampCell } from './api-key-timestamp-cell'
|
||||||
import {
|
import {
|
||||||
ApiKeyCell,
|
ApiKeyCell,
|
||||||
ModelLimitsCell,
|
|
||||||
IpRestrictionsCell,
|
IpRestrictionsCell,
|
||||||
|
ModelLimitsCell,
|
||||||
|
UnlimitedQuotaBadge,
|
||||||
} from './api-keys-cells'
|
} from './api-keys-cells'
|
||||||
import { DataTableRowActions } from './data-table-row-actions'
|
import { DataTableRowActions } from './data-table-row-actions'
|
||||||
|
|
||||||
@@ -145,14 +146,7 @@ export function useApiKeysColumns(now: number): ColumnDef<ApiKey>[] {
|
|||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const apiKey = row.original
|
const apiKey = row.original
|
||||||
if (apiKey.unlimited_quota) {
|
if (apiKey.unlimited_quota) {
|
||||||
return (
|
return <UnlimitedQuotaBadge used={apiKey.used_quota} />
|
||||||
<StatusBadge
|
|
||||||
label={t('Unlimited')}
|
|
||||||
variant='neutral'
|
|
||||||
copyable={false}
|
|
||||||
className='-ml-1.5'
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const used = apiKey.used_quota
|
const used = apiKey.used_quota
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ import {
|
|||||||
ERROR_MESSAGES,
|
ERROR_MESSAGES,
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
import type { ApiKey } from '../types'
|
import type { ApiKey } from '../types'
|
||||||
import { ApiKeyCell } from './api-keys-cells'
|
import { ApiKeyCell, UnlimitedQuotaBadge } from './api-keys-cells'
|
||||||
import { useApiKeysColumns } from './api-keys-columns'
|
import { useApiKeysColumns } from './api-keys-columns'
|
||||||
import { useApiKeys } from './api-keys-provider'
|
import { useApiKeys } from './api-keys-provider'
|
||||||
import { DataTableBulkActions } from './data-table-bulk-actions'
|
import { DataTableBulkActions } from './data-table-bulk-actions'
|
||||||
@@ -168,7 +168,7 @@ function ApiKeysMobileList({
|
|||||||
<div className='flex items-center justify-between gap-2 text-xs'>
|
<div className='flex items-center justify-between gap-2 text-xs'>
|
||||||
<span className='text-muted-foreground'>{t('Quota')}</span>
|
<span className='text-muted-foreground'>{t('Quota')}</span>
|
||||||
{apiKey.unlimited_quota ? (
|
{apiKey.unlimited_quota ? (
|
||||||
<span className='font-medium'>{t('Unlimited')}</span>
|
<UnlimitedQuotaBadge used={apiKey.used_quota} />
|
||||||
) : (
|
) : (
|
||||||
<span className='font-medium tabular-nums'>
|
<span className='font-medium tabular-nums'>
|
||||||
{formatQuota(apiKey.remain_quota)}
|
{formatQuota(apiKey.remain_quota)}
|
||||||
|
|||||||
Reference in New Issue
Block a user