Path: blob/master/cloud/ai-service-apps/nextjs-carbon-react-ui/src/components/AppHeader/ProfilePanel.js
6408 views
import React, { useState } from "react";1import { HeaderGlobalAction, HeaderPanel } from "@carbon/react";2import { useAppContext } from "@/contexts/app-context";3import { useOutsideClick } from "../../hooks/useOutsideClick";4import { getUserInitials, mapUserColor } from "../../utils/user-util";5import ThemeToggle from "../ThemeToggle/ThemeToggle";67const profilePanelContentId = "profile-panel-content";89const ProfilePanel = () => {10const [isExpanded, setIsExpanded] = useState(false);11const { userData } = useAppContext();12const { givenName, familyName } = userData;1314const userName = userData?.name;15const refHeaderProfileAction = useOutsideClick(16() => setIsExpanded(false),17[profilePanelContentId]18);19const userInitials = getUserInitials({ givenName, familyName });20const userColor = mapUserColor(userName);2122return (23<>24{userName && (25<>26<HeaderGlobalAction27aria-label="User profile"28className="profile-panel__action"29onClick={() => {30setIsExpanded((currentValue) => !currentValue);31}}32ref={refHeaderProfileAction}33>34<div className="profile-panel__actionUserAvatar" style={{ backgroundColor: userColor }}>35{userInitials}36</div>37</HeaderGlobalAction>38<HeaderPanel className="profile-panel__content" expanded={isExpanded}>39<div id={profilePanelContentId} className="profile-panel__contentWrapper">40<div className="profile-panel__appSection">41<div className="profile-panel__version">Version {process.env.version}</div>42<div className="profile-panel__themeSection">43<ThemeToggle isExpanded={isExpanded} />44</div>45</div>46<div className="profile-panel__userSection">47<div className="profile-panel__userAvatar" style={{ backgroundColor: userColor }}>48{userInitials}49</div>50<div className="profile-panel__info">51<div className="profile-panel__userName">{userName}</div>52</div>53</div>54</div>55</HeaderPanel>56</>57)}58</>59);60};6162export default ProfilePanel;636465