add screen to funnel
This commit is contained in:
parent
4a97bf67f6
commit
36c45f3521
@ -285,23 +285,48 @@ export function FunnelRuntime({ funnel, initialScreenId }: FunnelRuntimeProps) {
|
||||
const backTarget: string | undefined = currentScreen.navigation?.onBackScreenId;
|
||||
if (!backTarget) return;
|
||||
|
||||
// Флаг для предотвращения множественных срабатываний
|
||||
let isRedirecting = false;
|
||||
|
||||
const pushTrap = () => {
|
||||
try {
|
||||
window.history.pushState({ __trap: true }, "", window.location.href);
|
||||
window.history.pushState(
|
||||
{ __trap: true, __screenId: currentScreen.id },
|
||||
"",
|
||||
window.location.href
|
||||
);
|
||||
} catch {}
|
||||
};
|
||||
|
||||
// Добавляем trap state в историю
|
||||
pushTrap();
|
||||
|
||||
function isTrapState(state: unknown): state is { __trap?: boolean } {
|
||||
return typeof state === "object" && state !== null && "__trap" in (state as Record<string, unknown>);
|
||||
}
|
||||
const handlePopState = () => {
|
||||
// Проверяем наличие backTarget на момент события
|
||||
const currentBackTarget = currentScreen.navigation?.onBackScreenId;
|
||||
if (!currentBackTarget || isRedirecting) return;
|
||||
|
||||
const handlePopState = (e: PopStateEvent) => {
|
||||
if (isTrapState(e.state) && e.state.__trap) {
|
||||
pushTrap();
|
||||
router.replace(`/${funnel.meta.id}/${backTarget}`);
|
||||
}
|
||||
isRedirecting = true;
|
||||
|
||||
// Перемещаемся вперед на 1 шаг чтобы отменить переход назад
|
||||
window.history.go(1);
|
||||
|
||||
// Небольшая задержка для завершения history.go
|
||||
setTimeout(() => {
|
||||
try {
|
||||
// Выполняем редирект на целевой экран
|
||||
router.replace(`/${funnel.meta.id}/${currentBackTarget}`);
|
||||
|
||||
// Сбрасываем флаг
|
||||
setTimeout(() => {
|
||||
isRedirecting = false;
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
// Fallback: если router.replace не сработал, используем нативную навигацию
|
||||
console.error('Router replace failed, using fallback navigation:', error);
|
||||
window.location.href = `/${funnel.meta.id}/${currentBackTarget}`;
|
||||
}
|
||||
}, 10);
|
||||
};
|
||||
|
||||
window.addEventListener("popstate", handlePopState);
|
||||
|
||||
@ -50,7 +50,6 @@ export function SpecialOfferTemplate({
|
||||
const paywallId = placement?.paywallId || "";
|
||||
const trialPrice = variant?.trialPrice || 0;
|
||||
const price = variant?.price || 0;
|
||||
const oldPrice = variant?.price || 0;
|
||||
const oldTrialPeriod = "DAY"; // TODO: from main product
|
||||
const oldTrialInterval = 7; // TODO: from main product
|
||||
const oldTrialPrice = 100; // TODO: from main product
|
||||
|
||||
Loading…
Reference in New Issue
Block a user