feat: handling SSR on home page
This commit is contained in:
36
components/home/client-wrapper.tsx
Normal file
36
components/home/client-wrapper.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useUser } from "@/hooks/use-user-context";
|
||||
import { UserEvaluation, Team } from "@/lib/types";
|
||||
|
||||
interface ClientWrapperProps {
|
||||
userEvaluation: UserEvaluation | null;
|
||||
teams: Team[];
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function ClientWrapper({
|
||||
userEvaluation,
|
||||
teams,
|
||||
children,
|
||||
}: ClientWrapperProps) {
|
||||
const { setUserInfo } = useUser();
|
||||
|
||||
// Update user info in navigation when user evaluation is loaded
|
||||
useEffect(() => {
|
||||
if (userEvaluation) {
|
||||
const teamName =
|
||||
teams.find((t) => t.id === userEvaluation.profile.teamId)?.name || "";
|
||||
setUserInfo({
|
||||
firstName: userEvaluation.profile.firstName,
|
||||
lastName: userEvaluation.profile.lastName,
|
||||
teamName,
|
||||
});
|
||||
} else {
|
||||
setUserInfo(null);
|
||||
}
|
||||
}, [userEvaluation, teams, setUserInfo]);
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user