feat(chat): add userId to premium alert handling and improve alert visibility in UI

This commit is contained in:
Anish Sarkar 2026-04-29 21:58:17 +05:30
parent 901de33684
commit e6db050dfd
4 changed files with 21 additions and 6 deletions

View file

@ -1581,7 +1581,7 @@ async def stream_new_chat(
)
else:
yield streaming_service.format_error(
"Buy more tokens to continue with this model, or switch to a free model.",
"Buy more tokens to continue with this model, or switch to a free model",
error_code="PREMIUM_QUOTA_EXHAUSTED",
)
yield streaming_service.format_done()
@ -2349,7 +2349,7 @@ async def stream_resume_chat(
)
else:
yield streaming_service.format_error(
"Buy more tokens to continue with this model, or switch to a free model.",
"Buy more tokens to continue with this model, or switch to a free model",
error_code="PREMIUM_QUOTA_EXHAUSTED",
)
yield streaming_service.format_done()

View file

@ -1032,6 +1032,7 @@ export default function NewChatPage() {
setPremiumAlertForThread({
threadId: currentThreadId,
message: premiumQuotaAlertMessage,
userId: currentUser?.id ?? null,
});
} else {
toast.error("Failed to get response. Please try again.");
@ -1334,6 +1335,7 @@ export default function NewChatPage() {
setPremiumAlertForThread({
threadId: resumeThreadId,
message: premiumQuotaAlertMessage,
userId: currentUser?.id ?? null,
});
} else {
toast.error("Failed to resume. Please try again.");
@ -1692,6 +1694,7 @@ export default function NewChatPage() {
setPremiumAlertForThread({
threadId,
message: premiumQuotaAlertMessage,
userId: currentUser?.id ?? null,
});
} else {
toast.error("Failed to regenerate response. Please try again.");

View file

@ -14,13 +14,25 @@ export const setPremiumAlertForThreadAtom = atom(
payload: {
threadId: number;
message: string;
userId?: string | null;
}
) => {
const storageKey = `surfsense-premium-alert-seen-v1:${payload.userId ?? "anonymous"}`;
if (typeof window !== "undefined") {
const hasSeen = localStorage.getItem(storageKey) === "true";
if (hasSeen) return;
}
const current = get(premiumAlertByThreadAtom);
set(premiumAlertByThreadAtom, {
...current,
[payload.threadId]: { message: payload.message },
});
if (typeof window !== "undefined") {
localStorage.setItem(storageKey, "true");
}
}
);

View file

@ -161,15 +161,15 @@ const PremiumQuotaPinnedAlert: FC = () => {
if (!alert) return null;
return (
<div className="mx-0 bg-amber-500/10 px-3 py-2 text-amber-100">
<div className="flex items-start gap-2">
<AlertCircle className="mt-0.5 size-4 shrink-0 text-amber-300" />
<div className="mx-0 overflow-hidden rounded-2xl border-input bg-muted px-4 py-4 text-foreground select-none">
<div className="flex items-center gap-2">
<AlertCircle className="size-4 shrink-0 text-muted-foreground" />
<div className="min-w-0 flex-1">
<p className="text-sm">{alert.message}</p>
</div>
<button
type="button"
className="inline-flex size-6 items-center justify-center text-amber-200 transition-colors hover:text-amber-50"
className="inline-flex size-6 items-center justify-center text-muted-foreground transition-colors hover:text-foreground"
aria-label="Dismiss premium quota alert"
onClick={() => clearPremiumAlertForThread(currentThreadId)}
>