PEP-100: popups blocked — a new-tab link instead of leaving Peppa

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Асель 2026-11-15 14:23:11 +05:00
parent bb7b1b4158
commit 60fa861303

View File

@ -14,6 +14,7 @@ export function OpenBotButton({ label, variant = "default", size = "sm" }: { lab
const router = useRouter();
const [waiting, setWaiting] = useState(false);
const [error, setError] = useState<string | null>(null);
const [link, setLink] = useState<string | null>(null);
useEffect(() => {
if (!waiting) return;
@ -35,8 +36,9 @@ export function OpenBotButton({ label, variant = "default", size = "sm" }: { lab
setError(r.error ?? "Не получилось открыть бота");
return;
}
// Popups blocked: never take Peppa away — show a link that opens in a new tab instead.
if (tab) tab.location.href = r.url;
else window.location.href = r.url;
else setLink(r.url);
setWaiting(true);
}
@ -45,6 +47,11 @@ export function OpenBotButton({ label, variant = "default", size = "sm" }: { lab
<Button type="button" variant={variant} size={size} onClick={() => void open()}>
{label}
</Button>
{link && (
<a href={link} target="_blank" rel="noreferrer" className="text-sm font-medium text-primary underline-offset-2 hover:underline">
Браузер не открыл новую вкладку — нажмите здесь, чтобы открыть бота
</a>
)}
{waiting && <span className="text-xs text-muted-foreground">Нажмите Start в Telegram и вернитесь сюда — шаг отметится сам.</span>}
{error && <span className="text-xs text-destructive">{error}</span>}
</span>