fix: scroll to start of tariffs section and wait for data to load

This commit is contained in:
c0mrade
2026-02-02 07:02:50 +03:00
parent 3613294a78
commit c815ac29ea

View File

@@ -519,15 +519,16 @@ export default function Subscription() {
// Auto-scroll to tariffs section when coming from Dashboard "Продлить" button
useEffect(() => {
const state = location.state as { scrollToExtend?: boolean } | null;
if (state?.scrollToExtend && tariffsCardRef.current) {
// Wait for tariffs to load before scrolling
if (state?.scrollToExtend && tariffsCardRef.current && tariffs.length > 0) {
const timer = setTimeout(() => {
tariffsCardRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' });
}, 300);
tariffsCardRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 100);
// Clear the state to prevent re-scrolling on subsequent renders
window.history.replaceState({}, document.title);
return () => clearTimeout(timer);
}
}, [location.state]);
}, [location.state, tariffs.length]);
const copyUrl = () => {
if (subscription?.subscription_url) {