Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move out store setup from extension/woocommerce to my-sites section #49879

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions client/my-sites/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
getSiteOption,
canCurrentUserUseCalypsoStore,
canCurrentUserUseWooCommerceCoreStore,
getSiteWoocommerceUrl,
} from 'calypso/state/sites/selectors';
import getSiteChecklist from 'calypso/state/selectors/get-site-checklist';
import getSiteTaskList from 'calypso/state/selectors/get-site-task-list';
Expand Down Expand Up @@ -765,7 +766,13 @@ export class MySitesSidebar extends Component {
}

woocommerce() {
const { site, canUserUseWooCommerceCoreStore, siteSuffix, isSiteWpcomStore } = this.props;
const {
site,
canUserUseWooCommerceCoreStore,
siteSuffix,
isSiteWpcomStore,
woocommerceUrl,
} = this.props;

if ( ! site ) {
return null;
Expand All @@ -785,7 +792,7 @@ export class MySitesSidebar extends Component {
return null;
}

let storeLink = site.options.admin_url + 'admin.php?page=wc-admin&from-calypso';
let storeLink = woocommerceUrl;
if ( ! isSiteWpcomStore ) {
// Navigate to Store UI for installation.
storeLink = '/store' + siteSuffix + '?redirect_after_install';
Expand Down Expand Up @@ -1216,6 +1223,7 @@ function mapStateToProps( state ) {
sitePlanSlug: getSitePlanSlug( state, siteId ),
onboardingUrl: getOnboardingUrl( state ),
isSiteWpcomStore: getSiteOption( state, siteId, 'is_wpcom_store' ), // 'is_automated_transfer' && 'woocommerce_is_active'
woocommerceUrl: getSiteWoocommerceUrl( state, siteId ),
};
}

Expand Down
1 change: 1 addition & 0 deletions client/my-sites/sidebar/test/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe( 'MySitesSidebar', () => {
},
},
isSiteWpcomStore: true,
woocommerceUrl: 'http://test.com/wp-admin/admin.php?page=wc-admin&from-calypso',
} );
const WooCommerce = () => Sidebar.woocommerce();

Expand Down
47 changes: 47 additions & 0 deletions client/my-sites/woocommerce/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* External dependencies
*/
import React from 'react';
import page from 'page';

/**
* Internal Dependencies
*/
import main from './main';
import { getSiteFragment } from 'calypso/lib/route';
import {
getSelectedSiteWithFallback,
getSiteOption,
getSiteWoocommerceUrl,
} from 'calypso/state/sites/selectors';
import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer';

export function checkPrerequisites( context, next ) {
const state = context.store.getState();
const site = getSelectedSiteWithFallback( state );
const siteId = site ? site.ID : null;

// Only allow AT sites to access.
if ( ! isAtomicSite( state, siteId ) ) {
return page.redirect( `/home/${ site.slug }` );
}

// WooCommerce plugin is already installed, redirect to Woo.
if ( getSiteOption( state, siteId, 'is_wpcom_store' ) ) {
const redirectUrl = getSiteWoocommerceUrl( state, siteId );
window.location.href = redirectUrl;
return;
}

next();
}

export function setup( context, next ) {
// Invalid site, redirect to select site.
if ( ! getSiteFragment( context.path ) ) {
return page.redirect( '/woocommerce-installation' );
}

context.primary = React.createElement( main );
next();
}
Loading