Skip to content

Commit

Permalink
Store: Change link target of "Store" menu item for the eCommerce plan (
Browse files Browse the repository at this point in the history
  • Loading branch information
justinshreve authored Nov 15, 2018
1 parent dc245a8 commit 9df0fae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
26 changes: 23 additions & 3 deletions client/my-sites/sidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import SidebarMenu from 'layout/sidebar/menu';
import SidebarRegion from 'layout/sidebar/region';
import StatsSparkline from 'blocks/stats-sparkline';
import JetpackLogo from 'components/jetpack-logo';
import { isFreeTrial, isPersonal, isPremium, isBusiness } from 'lib/products-values';
import { isFreeTrial, isPersonal, isPremium, isBusiness, isEcommerce } from 'lib/products-values';
import { getCurrentUser } from 'state/current-user/selectors';
import { getSelectedSiteId } from 'state/ui/selectors';
import { setNextLayoutFocus, setLayoutFocus } from 'state/ui/layout-focus/actions';
Expand Down Expand Up @@ -125,6 +125,7 @@ export class MySitesSidebar extends Component {
}

const statsLink = getStatsPathForTab( 'day', siteId );
/* eslint-disable wpcalypso/jsx-classname-namespace */
return (
<SidebarItem
tipTarget="menus"
Expand All @@ -143,6 +144,7 @@ export class MySitesSidebar extends Component {
</a>
</SidebarItem>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
}

trackActivityClick = () => {
Expand Down Expand Up @@ -382,7 +384,12 @@ export class MySitesSidebar extends Component {
let planLink = '/plans' + this.props.siteSuffix;

// Show plan details for upgraded sites
if ( isPersonal( site.plan ) || isPremium( site.plan ) || isBusiness( site.plan ) ) {
if (
isPersonal( site.plan ) ||
isPremium( site.plan ) ||
isBusiness( site.plan ) ||
isEcommerce( site.plan )
) {
planLink = '/plans/my-plan' + this.props.siteSuffix;
}

Expand All @@ -400,6 +407,7 @@ export class MySitesSidebar extends Component {
} );
}

/* eslint-disable wpcalypso/jsx-classname-namespace */
return (
<li className={ linkClass } data-tip-target={ tipTarget }>
<a onClick={ this.trackPlanClick } href={ planLink }>
Expand All @@ -411,6 +419,7 @@ export class MySitesSidebar extends Component {
</a>
</li>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
}

trackStoreClick = () => {
Expand All @@ -433,12 +442,19 @@ export class MySitesSidebar extends Component {
if ( ! isEnabled( 'woocommerce/extension-dashboard' ) || ! site ) {
return null;
}

let storeLink = '/store' + siteSuffix;
if ( isEcommerce( site.plan ) ) {
storeLink = site.options.admin_url + 'edit.php?post_type=shop_order&calypsoify=1';
}

return (
<SidebarItem
label={ translate( 'Store' ) }
link={ '/store' + siteSuffix }
link={ storeLink }
onNavigate={ this.trackStoreClick }
icon="cart"
forceInternalLink
>
<div className="sidebar__chevron-right">
<Gridicon icon="chevron-right" />
Expand Down Expand Up @@ -572,6 +588,7 @@ export class MySitesSidebar extends Component {
return null;
}

/* eslint-disable wpcalypso/jsx-classname-namespace*/
return (
<li className="wp-admin">
<a
Expand All @@ -586,6 +603,7 @@ export class MySitesSidebar extends Component {
</a>
</li>
);
/* eslint-enable wpcalypso/jsx-classname-namespace*/
}

// Check for cases where WP Admin links should appear, where we need support for legacy reasons (VIP, older users, testing).
Expand Down Expand Up @@ -626,6 +644,7 @@ export class MySitesSidebar extends Component {
return null;
}

/* eslint-disable wpcalypso/jsx-classname-namespace */
return (
<Button
borderless
Expand All @@ -636,6 +655,7 @@ export class MySitesSidebar extends Component {
<Gridicon icon="add-outline" /> { this.props.translate( 'Add New Site' ) }
</Button>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
}

trackDomainSettingsClick = () => {
Expand Down
26 changes: 26 additions & 0 deletions client/my-sites/sidebar/test/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,39 @@ describe( 'MySitesSidebar', () => {
const Sidebar = new MySitesSidebar( {
canUserUseStore: true,
...defaultProps,
site: {
plan: {
product_slug: 'business-bundle',
},
},
} );
const Store = () => Sidebar.store();

const wrapper = shallow( <Store /> );
expect( wrapper.props().link ).toEqual( '/store/mysite.com' );
} );

test( 'Should return Calypsoified store menu item if user can use store on this site and the site is an ecommerce plan', () => {
const Sidebar = new MySitesSidebar( {
canUserUseStore: true,
...defaultProps,
site: {
options: {
admin_url: 'http://test.com/wp-admin/',
},
plan: {
product_slug: 'ecommerce-bundle',
},
},
} );
const Store = () => Sidebar.store();

const wrapper = shallow( <Store /> );
expect( wrapper.props().link ).toEqual(
'http://test.com/wp-admin/edit.php?post_type=shop_order&calypsoify=1'
);
} );

test( 'Should return null item if user can not use store on this site (nudge-a-palooza disabled)', () => {
config.isEnabled.mockImplementation( feature => feature !== 'upsell/nudge-a-palooza' );
const Sidebar = new MySitesSidebar( {
Expand Down

0 comments on commit 9df0fae

Please sign in to comment.