/**
* External dependencies
*/
import { useState } from '@wordpress/element';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { Icon, commentAuthorAvatar, external, linkOff } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import './header-account.scss';
import { getAdminSetting } from '../../../utils/admin-settings';
import HeaderAccountModal from './header-account-modal';
import { MARKETPLACE_HOST } from '../constants';
export default function HeaderAccount(): JSX.Element {
const [ isModalOpen, setIsModalOpen ] = useState( false );
const openModal = () => setIsModalOpen( true );
const wccomSettings = getAdminSetting( 'wccomHelper', {} );
const isConnected = wccomSettings?.isConnected ?? false;
const connectionURL = wccomSettings?.connectURL ?? '';
const userEmail = wccomSettings?.userEmail;
const avatarURL = wccomSettings?.userAvatar ?? commentAuthorAvatar;
// This is a hack to prevent TypeScript errors. The MenuItem component passes these as an href prop to the underlying button
// component. That component is either an anchor with href if provided or a button that won't accept an href if no href is provided.
// Due to early erroring of TypeScript, it only takes the button version into account which doesn't accept href.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const accountURL: any = MARKETPLACE_HOST + '/my-dashboard/';
const accountOrConnect = isConnected ? accountURL : connectionURL;
const avatar = () => {
if ( ! isConnected ) {
return commentAuthorAvatar;
}
return (
);
};
const connectionStatusText = isConnected
? __( 'Connected', 'woocommerce' )
: __( 'Not Connected', 'woocommerce' );
const connectionDetails = () => {
if ( isConnected ) {
return (
<>