Fix users page crash
Deploy Frontend / build-and-deploy (push) Successful in 29s
Details
Deploy Frontend / build-and-deploy (push) Successful in 29s
Details
This commit is contained in:
parent
31470f85cf
commit
fe585f421c
|
|
@ -61,13 +61,25 @@ export default function UserEditModal({ userId, opened, onClose }: UserEditModal
|
|||
department_id: user.department_id || null,
|
||||
is_blocked: user.is_blocked || false,
|
||||
is_fired: user.is_fired || false,
|
||||
role_ids: user.user_roles?.map((ur) => ur.role_id!) || [],
|
||||
// 🩹 ФИКС: user.user_roles?.map(...) защищал только от
|
||||
// null/undefined, но не от случая, когда пришёл не массив,
|
||||
// а объект-обёртка — именно это и роняло страницу с
|
||||
// "l?.map is not a function" (см. componentStack — крэш
|
||||
// внутри дочернего компонента UsersPage, коим и является
|
||||
// этот модал, он рендерится всегда, не только при opened).
|
||||
role_ids: Array.isArray(user.user_roles)
|
||||
? user.user_roles.map((ur) => ur.role_id!)
|
||||
: [],
|
||||
})
|
||||
}
|
||||
}, [user])
|
||||
|
||||
useEffect(() => {
|
||||
if (userRoles && userRoles.length > 0) {
|
||||
// 🩹 ФИКС: было `userRoles && userRoles.length > 0` — не роняло
|
||||
// страницу (не вызывает .map при не-массиве), но и не защищало
|
||||
// корректно от объекта-обёртки с полем length. Array.isArray
|
||||
// явный и однозначный.
|
||||
if (Array.isArray(userRoles) && userRoles.length > 0) {
|
||||
const roleIds = userRoles
|
||||
.map((ur) => ur.role?.id || ur.role_id)
|
||||
.filter((id): id is number => !!id)
|
||||
|
|
@ -103,16 +115,27 @@ export default function UserEditModal({ userId, opened, onClose }: UserEditModal
|
|||
setCopyRolesOpened(false)
|
||||
}
|
||||
|
||||
const departmentOptions = departments?.map((d) => ({
|
||||
value: String(d.id),
|
||||
label: d.name || '',
|
||||
})) || []
|
||||
// 🩹 ГЛАВНЫЙ ФИКС: было `departments?.map(...) || []` — optional
|
||||
// chaining защищает только от null/undefined, а не от случая, когда
|
||||
// departments пришёл не массивом (например, объектом-обёрткой вида
|
||||
// {data: [...], total_count} — судя по такой же явной проверке в
|
||||
// UsersPage.tsx для тех же хуков, это реально случающийся кейс).
|
||||
// Array.isArray — единственная надёжная защита от "map is not a function".
|
||||
const departmentOptions = Array.isArray(departments)
|
||||
? departments.map((d) => ({
|
||||
value: String(d.id),
|
||||
label: d.name || '',
|
||||
}))
|
||||
: []
|
||||
|
||||
const roleOptions = allRoles?.map((r) => ({
|
||||
value: String(r.id),
|
||||
label: r.name || '',
|
||||
description: r.description,
|
||||
})) || []
|
||||
// 🩹 То же самое для ролей.
|
||||
const roleOptions = Array.isArray(allRoles)
|
||||
? allRoles.map((r) => ({
|
||||
value: String(r.id),
|
||||
label: r.name || '',
|
||||
description: r.description,
|
||||
}))
|
||||
: []
|
||||
|
||||
const isLoading = userLoading || rolesLoading
|
||||
const isSubmitting = updateUser.isPending || assignRoles.isPending
|
||||
|
|
|
|||
Loading…
Reference in New Issue