2020-11-04 00:33:04 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2021-01-07 23:57:09 +00:00
|
|
|
import { Card, CardBody, CardHeader } from '@wordpress/components';
|
2020-11-04 00:33:04 +00:00
|
|
|
import {
|
|
|
|
megaphone,
|
|
|
|
box,
|
|
|
|
brush,
|
|
|
|
home,
|
|
|
|
shipping,
|
|
|
|
percent,
|
|
|
|
payment,
|
|
|
|
pencil,
|
|
|
|
} from '@wordpress/icons';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2021-01-07 23:57:09 +00:00
|
|
|
import { Text } from '@woocommerce/experimental';
|
2020-11-04 00:33:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
import { QuickLinkCategory } from './quick-link-category';
|
|
|
|
import { QuickLink } from './quick-link';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2020-11-04 00:33:04 +00:00
|
|
|
|
2021-01-28 06:47:57 +00:00
|
|
|
export function getItemsByCategory( shopUrl ) {
|
2020-11-04 00:33:04 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: __( 'Marketing & Merchandising', 'woocommerce-admin' ),
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
title: __( 'Marketing', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-admin',
|
|
|
|
path: 'marketing',
|
|
|
|
} ),
|
|
|
|
icon: megaphone,
|
|
|
|
listItemTag: 'marketing',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Add products', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wp-admin',
|
|
|
|
path: 'post-new.php?post_type=product',
|
|
|
|
} ),
|
|
|
|
icon: box,
|
|
|
|
listItemTag: 'add-products',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Personalize my store', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wp-admin',
|
|
|
|
path: 'customize.php',
|
|
|
|
} ),
|
|
|
|
icon: brush,
|
|
|
|
listItemTag: 'personalize-store',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'View my store', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'external',
|
2021-01-28 06:47:57 +00:00
|
|
|
href: shopUrl,
|
2020-11-04 00:33:04 +00:00
|
|
|
} ),
|
|
|
|
icon: home,
|
|
|
|
listItemTag: 'view-store',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Settings', 'woocommerce-admin' ),
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
title: __( 'Store details', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'general',
|
|
|
|
} ),
|
|
|
|
icon: pencil,
|
|
|
|
listItemTag: 'edit-store-details',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Payments', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'checkout',
|
|
|
|
} ),
|
|
|
|
icon: payment,
|
|
|
|
listItemTag: 'payment-settings',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Tax', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'tax',
|
|
|
|
} ),
|
|
|
|
icon: percent,
|
|
|
|
listItemTag: 'tax-settings',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Shipping', 'woocommerce-admin' ),
|
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'shipping',
|
|
|
|
} ),
|
|
|
|
icon: shipping,
|
|
|
|
listItemTag: 'shipping-settings',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getLinkTypeAndHref( { path, tab = null, type, href = null } ) {
|
|
|
|
return (
|
|
|
|
{
|
|
|
|
'wc-admin': {
|
|
|
|
href: `admin.php?page=wc-admin&path=%2F${ path }`,
|
|
|
|
linkType: 'wc-admin',
|
|
|
|
},
|
|
|
|
'wp-admin': {
|
|
|
|
href: path,
|
|
|
|
linkType: 'wp-admin',
|
|
|
|
},
|
|
|
|
'wc-settings': {
|
|
|
|
href: `admin.php?page=wc-settings&tab=${ tab }`,
|
|
|
|
linkType: 'wp-admin',
|
|
|
|
},
|
|
|
|
}[ type ] || {
|
|
|
|
href,
|
|
|
|
linkType: 'external',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const generateExtensionLinks = ( links ) => {
|
|
|
|
return links.reduce( ( acc, { icon, href, title } ) => {
|
|
|
|
const url = new URL( href, window.location.href );
|
|
|
|
|
|
|
|
// We do not support extension links that take users away from the host.
|
|
|
|
if ( url.origin === window.location.origin ) {
|
|
|
|
acc.push( {
|
|
|
|
icon,
|
|
|
|
link: {
|
|
|
|
href,
|
|
|
|
linkType: 'wp-admin',
|
|
|
|
},
|
|
|
|
title,
|
|
|
|
listItemTag: 'quick-links-extension-link',
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, [] );
|
|
|
|
};
|
|
|
|
|
|
|
|
export const StoreManagementLinks = () => {
|
2022-01-06 12:53:30 +00:00
|
|
|
const shopUrl = getAdminSetting( 'shopUrl' );
|
2020-11-04 00:33:04 +00:00
|
|
|
|
|
|
|
const extensionQuickLinks = generateExtensionLinks(
|
|
|
|
applyFilters( 'woocommerce_admin_homescreen_quicklinks', [] )
|
|
|
|
);
|
|
|
|
|
2021-01-28 06:47:57 +00:00
|
|
|
const itemCategories = getItemsByCategory( shopUrl );
|
2020-11-04 00:33:04 +00:00
|
|
|
|
|
|
|
const extensionCategory = {
|
|
|
|
title: __( 'Extensions', 'woocommerce-admin' ),
|
|
|
|
items: extensionQuickLinks,
|
|
|
|
};
|
|
|
|
|
|
|
|
const categories = extensionQuickLinks.length
|
|
|
|
? [ ...itemCategories, extensionCategory ]
|
|
|
|
: itemCategories;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card size="medium">
|
|
|
|
<CardHeader size="medium">
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text variant="title.small" size="20" lineHeight="28px">
|
2020-11-04 00:33:04 +00:00
|
|
|
{ __( 'Store management', 'woocommerce-admin' ) }
|
|
|
|
</Text>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody
|
|
|
|
size="custom"
|
|
|
|
className="woocommerce-store-management-links__card-body"
|
|
|
|
>
|
|
|
|
{ categories.map( ( category ) => {
|
|
|
|
return (
|
|
|
|
<QuickLinkCategory
|
|
|
|
key={ category.title }
|
|
|
|
title={ category.title }
|
|
|
|
>
|
|
|
|
{ category.items.map(
|
|
|
|
( {
|
|
|
|
icon,
|
|
|
|
listItemTag,
|
|
|
|
title,
|
|
|
|
link: { href, linkType },
|
|
|
|
} ) => (
|
|
|
|
<QuickLink
|
|
|
|
icon={ icon }
|
|
|
|
key={ `${ title }_${ listItemTag }_${ href }` }
|
|
|
|
title={ title }
|
|
|
|
linkType={ linkType }
|
|
|
|
href={ href }
|
|
|
|
onClick={ () => {
|
|
|
|
recordEvent(
|
|
|
|
'home_quick_links_click',
|
|
|
|
{
|
|
|
|
task_name: listItemTag,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
) }
|
|
|
|
</QuickLinkCategory>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|