|
|
|
@ -59,21 +59,29 @@ export default function IntroClient() { |
|
|
|
const handleOpenSteps = useCallback(() => { |
|
|
|
setIsStepsOpen(true); |
|
|
|
if (typeof window !== "undefined") { |
|
|
|
try { |
|
|
|
const url = new URL(window.location.href); |
|
|
|
url.searchParams.set("steps", "open"); |
|
|
|
window.history.replaceState({ steps: "open" }, "", url.toString()); |
|
|
|
} catch (e) { |
|
|
|
console.warn("Could not update URL history for steps:", e); |
|
|
|
} |
|
|
|
} |
|
|
|
}, []); |
|
|
|
|
|
|
|
const handleCloseSteps = useCallback(() => { |
|
|
|
setIsStepsOpen(false); |
|
|
|
if (typeof window !== "undefined") { |
|
|
|
try { |
|
|
|
const params = new URLSearchParams(window.location.search); |
|
|
|
if (params.get("steps") === "open") { |
|
|
|
const url = new URL(window.location.href); |
|
|
|
url.searchParams.delete("steps"); |
|
|
|
window.history.replaceState({}, "", url.toString()); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
console.warn("Could not clear URL history for steps:", e); |
|
|
|
} |
|
|
|
} |
|
|
|
}, []); |
|
|
|
|
|
|
|
@ -90,23 +98,26 @@ export default function IntroClient() { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
setIsSubmitting(true); |
|
|
|
|
|
|
|
try { |
|
|
|
// If user is not authenticated yet, open onboarding steps immediately (0ms delay)
|
|
|
|
if (!authBridge.isAuthenticated()) { |
|
|
|
const token = await authBridge.ensureToken(); |
|
|
|
if (!token) { |
|
|
|
console.warn( |
|
|
|
"No token from bridge – opening intro onboarding steps", |
|
|
|
); |
|
|
|
handleOpenSteps(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
setIsSubmitting(true); |
|
|
|
|
|
|
|
try { |
|
|
|
let profileResponse = profile; |
|
|
|
try { |
|
|
|
const { data: freshProfile } = await refetch(); |
|
|
|
// Race refetch against a 2-second timeout so slow network never hangs the button
|
|
|
|
const refetchPromise = refetch(); |
|
|
|
const timeoutPromise = new Promise<{ data?: undefined }>((resolve) => |
|
|
|
setTimeout(() => resolve({ data: undefined }), 2000), |
|
|
|
); |
|
|
|
const { data: freshProfile } = await Promise.race([ |
|
|
|
refetchPromise, |
|
|
|
timeoutPromise, |
|
|
|
]); |
|
|
|
profileResponse = freshProfile ?? profile; |
|
|
|
} catch (refetchError) { |
|
|
|
console.warn( |
|
|
|
|