Skip to content

Commit

Permalink
Bind activation and installation to the update button
Browse files Browse the repository at this point in the history
  • Loading branch information
harriswong committed Jun 11, 2024
1 parent 5e00d4c commit ff8dd0b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 56 deletions.
4 changes: 2 additions & 2 deletions classes/class-wc-connect-service-settings-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ public function get_package_lookup() {

return $lookup;
}

public function is_eligible_for_migration() {
return false;
return true;
}

private function translate_unit( $value ) {
Expand Down
51 changes: 0 additions & 51 deletions client/apps/shipping-label/view-wrapper-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import classNames from 'classnames';
import Gridicon from 'gridicons';
import { sumBy, differenceBy, filter, maxBy } from 'lodash';
import { Button } from '@wordpress/components';
import {getNonce} from 'api/request'; // client/api/request.js

/**
* Internal dependencies
Expand Down Expand Up @@ -97,15 +96,6 @@ export class ShippingLabelViewWrapper extends Component {
>
{ translate( 'Create shipping label' ) }
</Button>
<Button
className={ className }
isPrimary
isBusy= { ! loaded }
disabled= { ! loaded }
onClick={ this.handleActivateLabelButtonClick }
>
{ translate( 'Activate plugin' ) }
</Button>
<Suspense fallback={<div />}>
<LabelPurchaseModal orderId={ orderId } siteId={ siteId } />
</Suspense>
Expand Down Expand Up @@ -174,47 +164,6 @@ export class ShippingLabelViewWrapper extends Component {
);
};

handleActivateLabelButtonClick = () => {
const plugins = 'hello-dolly'; //this needs to be a CSV string.
const installPluginAPICall = () =>
fetch( '/wp-json/wc-admin/plugins/install', {
method: 'POST',
headers: {
"Content-Type": "application/json",
'X-WP-Nonce': getNonce()
},
body: JSON.stringify({
plugins
})
} );

const activatePluginAPICall = () =>
fetch( '/wp-json/wc-admin/plugins/activate', {
method: 'POST',
headers: {
"Content-Type": "application/json",
'X-WP-Nonce': getNonce()
},
body: JSON.stringify({
plugins
})
} );


const installAndActivatePlugins = async() => {
try {
//TODO: status update
await installPluginAPICall();
await activatePluginAPICall();
} catch (e) {
//TODO: error handling.
// console.log('Failed to install or activate.', e);
}
};

installAndActivatePlugins();
};

handleCreateLabelButtonClick = () => {
const {
orderId,
Expand Down
43 changes: 40 additions & 3 deletions client/components/migration/feature-announcement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useState } from '@wordpress/element';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { localize } from 'i18n-calypso';
import { getNonce } from 'api/request'; // client/api/request.js

/**
* Internal dependencies
Expand All @@ -30,9 +31,45 @@ const FeatureAnnouncement = ({ translate, isEligable }) => {
};

const update = () => {
// Todo: implement update
setIsUpdating(true);
setTimeout(() => setIsUpdating(false), 2000);
const plugins = 'hello-dolly'; //this needs to be a CSV string.
const installPluginAPICall = () =>
fetch( '/wp-json/wc-admin/plugins/install', {
method: 'POST',
headers: {
"Content-Type": "application/json",
'X-WP-Nonce': getNonce()
},
body: JSON.stringify({
plugins
})
} );

const activatePluginAPICall = () =>
fetch( '/wp-json/wc-admin/plugins/activate', {
method: 'POST',
headers: {
"Content-Type": "application/json",
'X-WP-Nonce': getNonce()
},
body: JSON.stringify({
plugins
})
} );


const installAndActivatePlugins = async() => {
try {
setIsUpdating(true);
await installPluginAPICall();
await activatePluginAPICall();
setIsUpdating(false);
} catch (e) {
//TODO: error handling.
// console.log('Failed to install or activate.', e);
}
};

installAndActivatePlugins();
};

return <>{isOpen && (<Modal
Expand Down

0 comments on commit ff8dd0b

Please sign in to comment.