forked from baron/baron-sso
fix: resolve TypeScript errors on sub_email ui (#917)
This commit is contained in:
@@ -95,7 +95,7 @@ import { resolvePersonalTenant } from "./utils/personalTenant";
|
||||
|
||||
type UserFormValues = Omit<UserUpdateRequest, "metadata"> & {
|
||||
email: string;
|
||||
metadata: Record<string, Record<string, string | number | boolean>> & {
|
||||
metadata: Record<string, Record<string, string | number | boolean | string[]> | string[] | undefined> & {
|
||||
sub_email?: string[];
|
||||
};
|
||||
};
|
||||
@@ -768,6 +768,7 @@ function UserDetailPage() {
|
||||
// Filter out undefined/null/empty strings from metadata
|
||||
const cleanMetadata = Object.fromEntries(
|
||||
Object.entries(data.metadata).map(([tenantId, fields]) => {
|
||||
if (!fields || Array.isArray(fields)) return [tenantId, fields];
|
||||
const cleanFields = Object.fromEntries(
|
||||
Object.entries(fields).filter(
|
||||
([_, v]) => v !== undefined && v !== null && v !== "",
|
||||
@@ -786,7 +787,9 @@ function UserDetailPage() {
|
||||
|
||||
// Parse sub_email
|
||||
let sub_email: string[] = [];
|
||||
if (typeof rawSubEmail === "string" && rawSubEmail.trim() !== "") {
|
||||
if (Array.isArray(rawSubEmail)) {
|
||||
sub_email = rawSubEmail.filter(e => typeof e === 'string' && e.includes("@"));
|
||||
} else if (typeof rawSubEmail === "string" && rawSubEmail.trim() !== "") {
|
||||
sub_email = rawSubEmail
|
||||
.split(/[;,\n\r\t]/)
|
||||
.map((e) => e.trim())
|
||||
@@ -982,13 +985,13 @@ function UserDetailPage() {
|
||||
<Mail size={14} className="text-primary/70" />
|
||||
{user.email}
|
||||
</div>
|
||||
{user.metadata?.sub_email &&
|
||||
{Boolean(user.metadata?.sub_email &&
|
||||
Array.isArray(user.metadata.sub_email) &&
|
||||
user.metadata.sub_email.length > 0 && (
|
||||
user.metadata.sub_email.length > 0) && (
|
||||
<div className="flex items-center gap-1.5 bg-background px-2.5 py-1 rounded-full border">
|
||||
<Mail size={14} className="text-primary/40" />
|
||||
<span className="text-[10px] font-bold">
|
||||
+{user.metadata.sub_email.length}
|
||||
+{Array.isArray(user.metadata?.sub_email) ? user.metadata.sub_email.length : 0}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user