Skip to content

Commit aa6b141

Browse files
authored
fix(ai-help): refetch quota after an ai error (#10615)
1 parent 2e06a1a commit aa6b141

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Diff for: client/src/plus/ai-help/use-ai.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { useCallback, useEffect, useReducer, useRef, useState } from "react";
55
import { useSearchParams } from "react-router-dom";
66

77
import { SSE } from "sse.js";
8-
import useSWR from "swr";
8+
import useSWR, { mutate } from "swr";
99
import { AIHelpLog } from "./rust-types";
1010
import { useGleanClick } from "../../telemetry/glean-context";
1111
import { AI_HELP } from "../../telemetry/constants";
1212
import { useAIHelpSettings } from "./utils";
1313
import { EVENT_TIMEOUT } from "./constants";
14+
import { AI_HELP_QUOTA_PATH } from "../common/api";
1415

1516
const RETRY_INTERVAL = 10000;
1617
const ERROR_TIMEOUT = 60000;
@@ -384,6 +385,7 @@ export function useAiChat({
384385
eventSourceRef.current?.close();
385386
eventSourceRef.current = undefined;
386387
setLoadingState("failed");
388+
mutate(AI_HELP_QUOTA_PATH);
387389
console.error(err);
388390
},
389391
[gleanClick]
@@ -694,18 +696,15 @@ export function useAiChat({
694696
}, [state, path, setMessages]);
695697

696698
function useRemoteQuota() {
697-
const { data } = useSWR<Quota>(
698-
"/api/v1/plus/ai/help/quota",
699-
async (url) => {
700-
const response = await fetch(url);
701-
if (!response.ok) {
702-
const text = await response.text();
703-
throw new Error(`${response.status} on ${url}: ${text}`);
704-
}
705-
const data = await response.json();
706-
return data.quota;
699+
const { data } = useSWR<Quota>(AI_HELP_QUOTA_PATH, async (url) => {
700+
const response = await fetch(url);
701+
if (!response.ok) {
702+
const text = await response.text();
703+
throw new Error(`${response.status} on ${url}: ${text}`);
707704
}
708-
);
705+
const data = await response.json();
706+
return data.quota;
707+
});
709708

710709
return data;
711710
}

Diff for: client/src/plus/common/api.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const STRIPE_PLANS_PATH = "/api/v1/stripe/plans";
22
export const SETTINGS_BASE_PATH = "/api/v1/plus/settings/";
33
export const NEWSLETTER_BASE_PATH = "/api/v1/plus/newsletter/";
4+
export const AI_HELP_QUOTA_PATH = "/api/v1/plus/ai/help/quota";
45

56
export type PLUS_SETTINGS = {
67
col_in_search: boolean;

0 commit comments

Comments
 (0)