mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 05:12:38 +02:00
feat(chat): add userId to premium alert handling and improve alert visibility in UI
This commit is contained in:
parent
901de33684
commit
e6db050dfd
4 changed files with 21 additions and 6 deletions
|
|
@ -1581,7 +1581,7 @@ async def stream_new_chat(
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
yield streaming_service.format_error(
|
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",
|
error_code="PREMIUM_QUOTA_EXHAUSTED",
|
||||||
)
|
)
|
||||||
yield streaming_service.format_done()
|
yield streaming_service.format_done()
|
||||||
|
|
@ -2349,7 +2349,7 @@ async def stream_resume_chat(
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
yield streaming_service.format_error(
|
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",
|
error_code="PREMIUM_QUOTA_EXHAUSTED",
|
||||||
)
|
)
|
||||||
yield streaming_service.format_done()
|
yield streaming_service.format_done()
|
||||||
|
|
|
||||||
|
|
@ -1032,6 +1032,7 @@ export default function NewChatPage() {
|
||||||
setPremiumAlertForThread({
|
setPremiumAlertForThread({
|
||||||
threadId: currentThreadId,
|
threadId: currentThreadId,
|
||||||
message: premiumQuotaAlertMessage,
|
message: premiumQuotaAlertMessage,
|
||||||
|
userId: currentUser?.id ?? null,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.error("Failed to get response. Please try again.");
|
toast.error("Failed to get response. Please try again.");
|
||||||
|
|
@ -1334,6 +1335,7 @@ export default function NewChatPage() {
|
||||||
setPremiumAlertForThread({
|
setPremiumAlertForThread({
|
||||||
threadId: resumeThreadId,
|
threadId: resumeThreadId,
|
||||||
message: premiumQuotaAlertMessage,
|
message: premiumQuotaAlertMessage,
|
||||||
|
userId: currentUser?.id ?? null,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.error("Failed to resume. Please try again.");
|
toast.error("Failed to resume. Please try again.");
|
||||||
|
|
@ -1692,6 +1694,7 @@ export default function NewChatPage() {
|
||||||
setPremiumAlertForThread({
|
setPremiumAlertForThread({
|
||||||
threadId,
|
threadId,
|
||||||
message: premiumQuotaAlertMessage,
|
message: premiumQuotaAlertMessage,
|
||||||
|
userId: currentUser?.id ?? null,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.error("Failed to regenerate response. Please try again.");
|
toast.error("Failed to regenerate response. Please try again.");
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,25 @@ export const setPremiumAlertForThreadAtom = atom(
|
||||||
payload: {
|
payload: {
|
||||||
threadId: number;
|
threadId: number;
|
||||||
message: string;
|
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);
|
const current = get(premiumAlertByThreadAtom);
|
||||||
set(premiumAlertByThreadAtom, {
|
set(premiumAlertByThreadAtom, {
|
||||||
...current,
|
...current,
|
||||||
[payload.threadId]: { message: payload.message },
|
[payload.threadId]: { message: payload.message },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
localStorage.setItem(storageKey, "true");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,15 +161,15 @@ const PremiumQuotaPinnedAlert: FC = () => {
|
||||||
if (!alert) return null;
|
if (!alert) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-0 bg-amber-500/10 px-3 py-2 text-amber-100">
|
<div className="mx-0 overflow-hidden rounded-2xl border-input bg-muted px-4 py-4 text-foreground select-none">
|
||||||
<div className="flex items-start gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<AlertCircle className="mt-0.5 size-4 shrink-0 text-amber-300" />
|
<AlertCircle className="size-4 shrink-0 text-muted-foreground" />
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<p className="text-sm">{alert.message}</p>
|
<p className="text-sm">{alert.message}</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="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"
|
aria-label="Dismiss premium quota alert"
|
||||||
onClick={() => clearPremiumAlertForThread(currentThreadId)}
|
onClick={() => clearPremiumAlertForThread(currentThreadId)}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue