1
0
forked from baron/baron-sso

fix(adminfront): fix react hooks violation in UserDetailPage causing infinite loading

- Fix 'Rendered fewer hooks than expected' crash by moving useMemo hook definition above all early returns
- Resolves e2e test timeout failures in users_schema.spec.ts and users.spec.ts
This commit is contained in:
2026-04-10 17:44:00 +09:00
parent 6c6fab3ea3
commit 12b8958a72

View File

@@ -391,7 +391,12 @@ function UserDetailPage() {
phone: user.phone || "",
role: user.role,
status: user.status,
tenantSlug: user.companyCode || "",
tenantSlug:
user.companyCode ||
user.joinedTenants?.find(
(t) => t.type === "COMPANY" || t.type === "COMPANY_GROUP",
)?.slug ||
"",
department: user.department || "",
position: user.position || "",
jobTitle: user.jobTitle || "",
@@ -459,6 +464,16 @@ function UserDetailPage() {
}
};
const userAffiliatedTenants = React.useMemo(() => {
const joined = user?.joinedTenants || [];
const primary = user?.tenant;
const all = [...joined];
if (primary && !joined.some((t) => t.id === primary.id)) {
all.unshift(primary);
}
return all;
}, [user?.joinedTenants, user?.tenant]);
if (isLoading) {
return (
<div className="flex h-64 items-center justify-center">
@@ -484,16 +499,6 @@ function UserDetailPage() {
);
}
const userAffiliatedTenants = React.useMemo(() => {
const joined = user.joinedTenants || [];
const primary = user.tenant;
const all = [...joined];
if (primary && !joined.some((t) => t.id === primary.id)) {
all.unshift(primary);
}
return all;
}, [user.joinedTenants, user.tenant]);
return (
<div className="space-y-6">
{/* Header with back button and actions */}
@@ -533,6 +538,9 @@ function UserDetailPage() {
<Building2 size={12} className="mr-1.5" />
{user.tenant?.name ||
user.companyCode ||
user.joinedTenants?.find(
(t) => t.type === "COMPANY" || t.type === "COMPANY_GROUP",
)?.name ||
t("ui.admin.users.detail.form.tenant_global", "시스템 전역")}
</Badge>
<Badge