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
|
|
|
|
2023-11-15 07:21:14 +00:00
|
|
|
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',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-28 06:47:57 +00:00
|
|
|
export function getItemsByCategory( shopUrl ) {
|
2020-11-04 00:33:04 +00:00
|
|
|
return [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Marketing & Merchandising', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
items: [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Marketing', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-admin',
|
|
|
|
path: 'marketing',
|
|
|
|
} ),
|
|
|
|
icon: megaphone,
|
|
|
|
listItemTag: 'marketing',
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Add products', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wp-admin',
|
|
|
|
path: 'post-new.php?post_type=product',
|
|
|
|
} ),
|
|
|
|
icon: box,
|
|
|
|
listItemTag: 'add-products',
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Personalize my store', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wp-admin',
|
|
|
|
path: 'customize.php',
|
|
|
|
} ),
|
|
|
|
icon: brush,
|
|
|
|
listItemTag: 'personalize-store',
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'View my store', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Settings', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
items: [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Store details', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'general',
|
|
|
|
} ),
|
|
|
|
icon: pencil,
|
|
|
|
listItemTag: 'edit-store-details',
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Payments', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'checkout',
|
|
|
|
} ),
|
|
|
|
icon: payment,
|
|
|
|
listItemTag: 'payment-settings',
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Tax', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'tax',
|
|
|
|
} ),
|
|
|
|
icon: percent,
|
|
|
|
listItemTag: 'tax-settings',
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Shipping', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
link: getLinkTypeAndHref( {
|
|
|
|
type: 'wc-settings',
|
|
|
|
tab: 'shipping',
|
|
|
|
} ),
|
|
|
|
icon: shipping,
|
|
|
|
listItemTag: 'shipping-settings',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* An object defining an extension link.
|
|
|
|
*
|
|
|
|
* @typedef {Object} link
|
2022-03-18 11:45:14 +00:00
|
|
|
* @property {Node} icon Icon to render.
|
|
|
|
* @property {string} href Url.
|
2022-02-11 14:38:38 +00:00
|
|
|
* @property {string} title Link title.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store Management extensions links
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_homescreen_quicklinks
|
|
|
|
* @param {Array.<link>} links Array of links.
|
|
|
|
*/
|
2020-11-04 00:33:04 +00:00
|
|
|
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 = {
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Extensions', 'woocommerce' ),
|
2020-11-04 00:33:04 +00:00
|
|
|
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">
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Store management', 'woocommerce' ) }
|
2020-11-04 00:33:04 +00:00
|
|
|
</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>
|
|
|
|
);
|
|
|
|
};
|