feat: check quota correctly (#6561)

This commit is contained in:
darkskygit
2024-04-16 09:41:48 +00:00
parent 0ca8a23dd8
commit 1b0864eb60
26 changed files with 309 additions and 95 deletions

View File

@@ -70,7 +70,9 @@ export const AIUsagePanelNotSubscripted = () => {
const { data: quota } = useQuery({
query: getCopilotQuotaQuery,
});
const { limit = 10, used = 0 } = quota.currentUser?.copilot.quota || {};
const { limit: nullableLimit, used = 0 } =
quota.currentUser?.copilot.quota || {};
const limit = nullableLimit || 10;
const percent = Math.min(
100,
Math.max(0.5, Number(((used / limit) * 100).toFixed(4)))

View File

@@ -62,6 +62,7 @@ export interface CreateCheckoutSessionInput {
export enum FeatureType {
Copilot = 'Copilot',
EarlyAccess = 'EarlyAccess',
UnlimitedCopilot = 'UnlimitedCopilot',
UnlimitedWorkspace = 'UnlimitedWorkspace',
}
@@ -387,7 +388,11 @@ export type GetCopilotQuotaQuery = {
__typename?: 'UserType';
copilot: {
__typename?: 'Copilot';
quota: { __typename?: 'CopilotQuota'; limit: number; used: number };
quota: {
__typename?: 'CopilotQuota';
limit: number | null;
used: number;
};
};
} | null;
};