Skip to content

Commit

Permalink
Merge pull request #29 from newfold-labs/add/free-plugin-installation
Browse files Browse the repository at this point in the history
Add free plugin installation
  • Loading branch information
arunshenoy99 authored Oct 17, 2024
2 parents 8951a26 + 50cfa0b commit d66d19b
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Installer/components/Modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {

const Modal = ( {
action,
pluginDownloadUrl,
pluginName,
pluginDownloadUrl,
pluginName,
pluginProvider,
pluginSlug,
redirectUrl,
Expand Down Expand Up @@ -48,7 +48,7 @@ const Modal = ( {
useEffect( () => {
switch ( action ) {
case 'installFreePlugin':
// TODO: Install free plugin from pluginDownloadUrl
installFreePlugin();
break;

case 'installPremiumPlugin':
Expand Down Expand Up @@ -104,6 +104,29 @@ const Modal = ( {
}
};

const installFreePlugin = async () => {
try {
setPluginStatus( 'installing' );
await apiFetch( {
url: installerAPI,
method: 'POST',
headers: {
'X-NFD-INSTALLER': pluginInstallHash,
},
data: {
activate: true,
queue: false,
priority: 0,
plugin: pluginDownloadUrl,
},
} );
setPluginStatus( 'completed' );
window.location.href = redirectUrl;
} catch ( e ) {
setPluginStatus( 'failed' );
}
};

const helpLink = `${ window.NewfoldRuntime.adminUrl }admin.php?page=${ window.NewfoldRuntime.plugin.brand }#/help`;

const errorMessage = createInterpolateElement(
Expand Down

0 comments on commit d66d19b

Please sign in to comment.