From f480979020059edc96ab8436c949f6fcf6a8c566 Mon Sep 17 00:00:00 2001 From: Yashwin Date: Mon, 22 Jun 2026 09:59:13 +0530 Subject: [PATCH] fix: update getUserInitials to handle null/undefined inputs and return fallback character --- src/components/superadmin/PlatformUsersTable.tsx | 6 ++++-- src/components/superadmin/UsersTable.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/superadmin/PlatformUsersTable.tsx b/src/components/superadmin/PlatformUsersTable.tsx index c8a70fb..0385c86 100644 --- a/src/components/superadmin/PlatformUsersTable.tsx +++ b/src/components/superadmin/PlatformUsersTable.tsx @@ -32,8 +32,10 @@ import { formatDate } from "@/utils/format-date"; import { usePermissions } from "@/hooks/usePermissions"; // Helper function to get user initials -const getUserInitials = (firstName: string, lastName: string): string => { - return `${firstName[0] || ""}${lastName[0] || ""}`.toUpperCase(); +const getUserInitials = (firstName: string | null | undefined, lastName: string | null | undefined): string => { + const first = (firstName || "").trim().slice(0, 1); + const last = (lastName || "").trim().slice(0, 1); + return `${first}${last}`.toUpperCase() || "?"; }; // Helper function to get status badge variant diff --git a/src/components/superadmin/UsersTable.tsx b/src/components/superadmin/UsersTable.tsx index f0929ab..d64f83e 100644 --- a/src/components/superadmin/UsersTable.tsx +++ b/src/components/superadmin/UsersTable.tsx @@ -30,8 +30,10 @@ import { useAppTheme } from "@/hooks/useAppTheme"; import { usePermissions } from "@/hooks/usePermissions"; // Helper function to get user initials -const getUserInitials = (firstName: string, lastName: string): string => { - return `${firstName[0]}${lastName[0]}`.toUpperCase(); +const getUserInitials = (firstName: string | null | undefined, lastName: string | null | undefined): string => { + const first = (firstName || "").trim().slice(0, 1); + const last = (lastName || "").trim().slice(0, 1); + return `${first}${last}`.toUpperCase() || "?"; }; // Helper function to get status badge variant