From c2fbb20787dfcfe4bd8ad98a7828283b6b6c87d2 Mon Sep 17 00:00:00 2001 From: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com> Date: Fri, 17 May 2024 12:32:40 +0530 Subject: [PATCH] fix: survey overview is throwing a server-side error (#2638) --- .../components/MainNavigation.tsx | 7 ++++++- .../(app)/onboarding/components/onboarding.tsx | 11 ++++------- packages/ui/Survey/index.tsx | 16 +++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/components/MainNavigation.tsx b/apps/web/app/(app)/environments/[environmentId]/components/MainNavigation.tsx index 468db8d33e..19dbd12aa3 100644 --- a/apps/web/app/(app)/environments/[environmentId]/components/MainNavigation.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/components/MainNavigation.tsx @@ -78,7 +78,7 @@ export const MainNavigation = ({ const [currentTeamId, setCurrentTeamId] = useState(""); const [showAddProductModal, setShowAddProductModal] = useState(false); const [showCreateTeamModal, setShowCreateTeamModal] = useState(false); - const [isCollapsed, setIsCollapsed] = useState(localStorage.getItem("isMainNavCollapsed") === "true"); + const [isCollapsed, setIsCollapsed] = useState(true); const [isTextVisible, setIsTextVisible] = useState(true); const product = products.find((product) => product.id === environment.productId); @@ -90,6 +90,11 @@ export const MainNavigation = ({ localStorage.setItem("isMainNavCollapsed", isCollapsed ? "false" : "true"); }; + useEffect(() => { + const isCollapsedValueFromLocalStorage = localStorage.getItem("isMainNavCollapsed") === "true"; + setIsCollapsed(isCollapsedValueFromLocalStorage); + }, []); + useEffect(() => { const toggleTextOpacity = () => { setIsTextVisible(isCollapsed ? true : false); diff --git a/apps/web/app/(app)/onboarding/components/onboarding.tsx b/apps/web/app/(app)/onboarding/components/onboarding.tsx index 7836e798de..5997a5c6f9 100644 --- a/apps/web/app/(app)/onboarding/components/onboarding.tsx +++ b/apps/web/app/(app)/onboarding/components/onboarding.tsx @@ -82,14 +82,11 @@ export const Onboarding = ({ }, [iframeVisible, currentStep]); // Depend on iframeVisible and currentStep to re-evaluate when needed useEffect(() => { - if (typeof window !== "undefined") { - // Access localStorage only when window is available - const pathwayValueFromLocalStorage = localStorage.getItem("onboardingPathway"); - const currentStepValueFromLocalStorage = parseInt(localStorage.getItem("onboardingCurrentStep") ?? "1"); + const pathwayValueFromLocalStorage = localStorage.getItem("onboardingPathway"); + const currentStepValueFromLocalStorage = parseInt(localStorage.getItem("onboardingCurrentStep") ?? "1"); - setSelectedPathway(pathwayValueFromLocalStorage); - setCurrentStep(currentStepValueFromLocalStorage); - } + setSelectedPathway(pathwayValueFromLocalStorage); + setCurrentStep(currentStepValueFromLocalStorage); }, []); useEffect(() => { diff --git a/packages/ui/Survey/index.tsx b/packages/ui/Survey/index.tsx index 2ddef2690c..2cdff1c99f 100644 --- a/packages/ui/Survey/index.tsx +++ b/packages/ui/Survey/index.tsx @@ -23,17 +23,15 @@ export const SurveyInline = (props: Omit) => { useEffect(() => { const loadScript = async () => { - if (typeof window !== "undefined") { - if (!window.formbricksSurveys) { - try { - await loadSurveyScript(); - renderInline(); - } catch (error) { - console.error("Failed to load the surveys package: ", error); - } - } else { + if (!window.formbricksSurveys) { + try { + await loadSurveyScript(); renderInline(); + } catch (error) { + console.error("Failed to load the surveys package: ", error); } + } else { + renderInline(); } };