import React, { useCallback, useEffect, useState } from "react"; import { Pressable, ScrollView, useWindowDimensions, View } from "react-native"; import { useAuth } from "../../hooks/useAuth"; import { cn } from "../../utils/cn"; import { Dialog } from "../dialog"; import { MutedText, Text } from "../text"; import { UserAvatar } from "../user-avatar"; import { ProfileTab } from "./ProfileTab"; import { SecurityTab, type SecurityTabProps } from "./SecurityTab"; type Tab = "profile" | "security"; export interface ProfileDialogProps { visible: boolean; onClose: () => void; initialTab?: Tab; /** Wired to `SecurityTab`'s MFA-enrolment callback. */ onEnableMfa: () => void; /** * Optional client-side key-rewrap hook for password changes. Vault * supplies `KeyManager.computeReWrap`; apps without a wrapped key * omit it. */ onComputeReWrap?: SecurityTabProps["onComputeReWrap"]; } /** * Account-management dialog with Profile / Security tabs. The avatar * strip across the top pulls from the entropy-ui `UserAvatar` (which * reads `useAuth().user`). Apps inject their MFA enrolment route via * `onEnableMfa` and (optionally) a key-rewrap hook for password change. */ export function ProfileDialog({ visible, onClose, initialTab, onEnableMfa, onComputeReWrap, }: ProfileDialogProps) { const { user } = useAuth(); const { height: screenHeight } = useWindowDimensions(); const [tab, setTab] = useState(initialTab ?? "profile"); useEffect(() => { if (visible) { setTab(initialTab ?? "profile"); } }, [visible, initialTab]); const handleClose = useCallback(() => { setTab("profile"); onClose(); }, [onClose]); return ( {user?.display_name || user?.username || "User"} {user?.email ?? ""} {user?.role ?? "User"} {(["profile", "security"] as Tab[]).map((t) => { const active = tab === t; return ( setTab(t)} className="mr-1" testID={`profile-tab-${t}`} > {(state) => { // RN-Web extends PressableStateCallbackType with `hovered`; // base RN doesn't, so widen via cast. const hovered = (state as { hovered?: boolean }).hovered === true; return ( {t === "profile" ? "Profile" : "Security"} ); }} ); })} {tab === "profile" && } {tab === "security" && ( )} ); }