2022-12-22 15:01:01 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Icon } from '@wordpress/icons';
|
|
|
|
import {
|
|
|
|
customerAccountStyle,
|
|
|
|
customerAccountStyleAlt,
|
2024-07-02 07:34:59 +00:00
|
|
|
customerAccountStyleLine,
|
2022-12-22 15:01:01 +00:00
|
|
|
} from '@woocommerce/icons';
|
|
|
|
import { getSetting } from '@woocommerce/settings';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { Attributes, DisplayStyle, IconStyle } from './types';
|
|
|
|
|
2024-07-02 07:34:59 +00:00
|
|
|
const icons = {
|
|
|
|
default: customerAccountStyle,
|
|
|
|
alt: customerAccountStyleAlt,
|
|
|
|
line: customerAccountStyleLine,
|
|
|
|
};
|
|
|
|
|
2022-12-22 15:01:01 +00:00
|
|
|
const AccountIcon = ( {
|
|
|
|
iconStyle,
|
|
|
|
displayStyle,
|
2023-03-03 14:44:34 +00:00
|
|
|
iconClass,
|
2022-12-22 15:01:01 +00:00
|
|
|
}: {
|
|
|
|
iconStyle: IconStyle;
|
|
|
|
displayStyle: DisplayStyle;
|
2023-03-03 14:44:34 +00:00
|
|
|
iconClass: string;
|
2022-12-22 15:01:01 +00:00
|
|
|
} ) => {
|
|
|
|
return displayStyle === DisplayStyle.TEXT_ONLY ? null : (
|
2024-07-02 07:34:59 +00:00
|
|
|
<Icon className={ iconClass } icon={ icons[ iconStyle ] } size={ 18 } />
|
2022-12-22 15:01:01 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Label = ( { displayStyle }: { displayStyle: DisplayStyle } ) => {
|
|
|
|
if ( displayStyle === DisplayStyle.ICON_ONLY ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentUserId = getSetting( 'currentUserId', null );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className="label">
|
|
|
|
{ currentUserId
|
2023-12-12 22:12:36 +00:00
|
|
|
? __( 'My Account', 'woocommerce' )
|
|
|
|
: __( 'Log in', 'woocommerce' ) }
|
2022-12-22 15:01:01 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CustomerAccountBlock = ( {
|
|
|
|
attributes,
|
|
|
|
}: {
|
|
|
|
attributes: Attributes;
|
|
|
|
} ): JSX.Element => {
|
2023-03-03 14:44:34 +00:00
|
|
|
const { displayStyle, iconStyle, iconClass } = attributes;
|
2022-12-22 15:01:01 +00:00
|
|
|
|
2024-04-29 01:35:47 +00:00
|
|
|
const ariaAttributes =
|
|
|
|
displayStyle === DisplayStyle.ICON_ONLY
|
|
|
|
? {
|
|
|
|
'aria-label': __( 'My Account', 'woocommerce' ),
|
|
|
|
}
|
|
|
|
: {};
|
|
|
|
|
2022-12-22 15:01:01 +00:00
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href={ getSetting(
|
|
|
|
'dashboardUrl',
|
|
|
|
getSetting( 'wpLoginUrl', '/wp-login.php' )
|
|
|
|
) }
|
2024-04-29 01:35:47 +00:00
|
|
|
{ ...ariaAttributes }
|
2022-12-22 15:01:01 +00:00
|
|
|
>
|
|
|
|
<AccountIcon
|
|
|
|
iconStyle={ iconStyle }
|
|
|
|
displayStyle={ displayStyle }
|
2023-03-03 14:44:34 +00:00
|
|
|
iconClass={ iconClass }
|
2022-12-22 15:01:01 +00:00
|
|
|
/>
|
|
|
|
<Label displayStyle={ displayStyle } />
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CustomerAccountBlock;
|