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"> & {
|
type UserFormValues = Omit<UserUpdateRequest, "metadata"> & {
|
||||||
email: string;
|
email: string;
|
||||||
metadata: Record<string, Record<string, string | number | boolean>> & {
|
metadata: Record<string, Record<string, string | number | boolean | string[]> | string[] | undefined> & {
|
||||||
sub_email?: string[];
|
sub_email?: string[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -768,6 +768,7 @@ function UserDetailPage() {
|
|||||||
// Filter out undefined/null/empty strings from metadata
|
// Filter out undefined/null/empty strings from metadata
|
||||||
const cleanMetadata = Object.fromEntries(
|
const cleanMetadata = Object.fromEntries(
|
||||||
Object.entries(data.metadata).map(([tenantId, fields]) => {
|
Object.entries(data.metadata).map(([tenantId, fields]) => {
|
||||||
|
if (!fields || Array.isArray(fields)) return [tenantId, fields];
|
||||||
const cleanFields = Object.fromEntries(
|
const cleanFields = Object.fromEntries(
|
||||||
Object.entries(fields).filter(
|
Object.entries(fields).filter(
|
||||||
([_, v]) => v !== undefined && v !== null && v !== "",
|
([_, v]) => v !== undefined && v !== null && v !== "",
|
||||||
@@ -786,7 +787,9 @@ function UserDetailPage() {
|
|||||||
|
|
||||||
// Parse sub_email
|
// Parse sub_email
|
||||||
let sub_email: string[] = [];
|
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
|
sub_email = rawSubEmail
|
||||||
.split(/[;,\n\r\t]/)
|
.split(/[;,\n\r\t]/)
|
||||||
.map((e) => e.trim())
|
.map((e) => e.trim())
|
||||||
@@ -982,13 +985,13 @@ function UserDetailPage() {
|
|||||||
<Mail size={14} className="text-primary/70" />
|
<Mail size={14} className="text-primary/70" />
|
||||||
{user.email}
|
{user.email}
|
||||||
</div>
|
</div>
|
||||||
{user.metadata?.sub_email &&
|
{Boolean(user.metadata?.sub_email &&
|
||||||
Array.isArray(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">
|
<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" />
|
<Mail size={14} className="text-primary/40" />
|
||||||
<span className="text-[10px] font-bold">
|
<span className="text-[10px] font-bold">
|
||||||
+{user.metadata.sub_email.length}
|
+{Array.isArray(user.metadata?.sub_email) ? user.metadata.sub_email.length : 0}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user