-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from Codeinwp/fix/install-plugins-buttons
Disable install buttons if users can not install them [#4071]
- Loading branch information
Showing
6 changed files
with
148 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-components', 'wp-element'), 'version' => 'b9d5790c82f421f0773c'); | ||
<?php return array('dependencies' => array('wp-components', 'wp-element'), 'version' => 'abd2fd2f3b61120a53af'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,99 @@ | ||
import {useState} from '@wordpress/element'; | ||
import {Button} from '@wordpress/components'; | ||
import {Button, Tooltip} from '@wordpress/components'; | ||
|
||
import {activatePlugin, installPluginOrTheme} from "../../common/utils"; | ||
import {installPluginOrTheme} from "../../common/utils"; | ||
|
||
export default function ProductCard({product, slug}) { | ||
const {icon, name, description, status, premiumUrl, activationLink} = product; | ||
const {strings} = window.tiSDKAboutData; | ||
const { | ||
installNow, | ||
installed, | ||
notInstalled, | ||
active, | ||
activate, | ||
learnMore | ||
} = strings; | ||
const {icon, name, description, status, premiumUrl, activationLink} = product; | ||
const {strings, canInstallPlugins} = window.tiSDKAboutData; | ||
const { | ||
installNow, | ||
installed, | ||
notInstalled, | ||
active, | ||
activate, | ||
learnMore | ||
} = strings; | ||
|
||
const isPremium = !!premiumUrl; | ||
const [productStatus, setProductStatus] = useState(status); | ||
const [loading, setLoading] = useState(false); | ||
const isPremium = !!premiumUrl; | ||
const [productStatus, setProductStatus] = useState(status); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const runInstall = async () => { | ||
setLoading(true); | ||
await installPluginOrTheme(slug, slug === 'neve').then((res) => { | ||
if (res.success) { | ||
setProductStatus('installed'); | ||
} | ||
}); | ||
setLoading(false); | ||
} | ||
const runInstall = async () => { | ||
if ( ! canInstallPlugins ) { | ||
return; | ||
} | ||
setLoading(true); | ||
await installPluginOrTheme(slug, slug === 'neve').then((res) => { | ||
if (res.success) { | ||
setProductStatus('installed'); | ||
} | ||
}); | ||
setLoading(false); | ||
} | ||
|
||
const runActivate = async () => { | ||
setLoading(true); | ||
window.location.href = activationLink; | ||
} | ||
const runActivate = async () => { | ||
if ( ! canInstallPlugins ) { | ||
return; | ||
} | ||
setLoading(true); | ||
window.location.href = activationLink; | ||
} | ||
|
||
return (<div className="product-card"> | ||
<div className="header"> | ||
{icon && <img src={icon} alt={name}/>} | ||
<h2>{name}</h2> | ||
</div> | ||
<div className="body"> | ||
<p dangerouslySetInnerHTML={{__html: description}}/> | ||
</div> | ||
<div className="footer"> | ||
<p>Status: | ||
{" "} | ||
<span className={productStatus}> | ||
const buttonContent = ( () => { | ||
if ( productStatus === 'not-installed' && isPremium ) { | ||
return ( | ||
<Button isLink icon={'external'} href={premiumUrl} target="_blank"> | ||
{learnMore} | ||
</Button> | ||
); | ||
} | ||
|
||
if ( productStatus === 'not-installed' && !isPremium ) { | ||
return ( | ||
<Button isPrimary onClick={runInstall} disabled={loading || ! canInstallPlugins}> | ||
{installNow} | ||
</Button> | ||
); | ||
} | ||
|
||
if ( productStatus === 'installed' ) { | ||
return ( | ||
<Button isSecondary onClick={runActivate} disabled={loading || ! canInstallPlugins}> | ||
{activate} | ||
</Button> | ||
) | ||
} | ||
|
||
return null; | ||
}); | ||
|
||
const wrappedButtonContent = ! canInstallPlugins ? ( | ||
<Tooltip text={`Ask your admin to enable ${name} on your site`} position="top center">{buttonContent()}</Tooltip> | ||
) : ( | ||
buttonContent() | ||
); | ||
|
||
return (<div className="product-card"> | ||
<div className="header"> | ||
{icon && <img src={icon} alt={name}/>} | ||
<h2>{name}</h2> | ||
</div> | ||
<div className="body"> | ||
<p dangerouslySetInnerHTML={{__html: description}}/> | ||
</div> | ||
<div className="footer"> | ||
<p>Status: | ||
{" "} | ||
<span className={productStatus}> | ||
{productStatus === 'installed' && installed} | ||
{productStatus === 'not-installed' && notInstalled} | ||
{productStatus === 'active' && active} | ||
{productStatus === 'not-installed' && notInstalled} | ||
{productStatus === 'active' && active} | ||
</span> | ||
</p> | ||
{productStatus !== 'active' && !loading && ( | ||
<> | ||
{productStatus === 'not-installed' && isPremium && | ||
<Button isLink icon={'external'} href={premiumUrl} target="_blank">{learnMore}</Button>} | ||
{productStatus === 'not-installed' && !isPremium && | ||
<Button isPrimary onClick={runInstall}>{installNow}</Button>} | ||
{productStatus === 'installed' && <Button isSecondary onClick={runActivate}>{activate}</Button>} | ||
</> | ||
)} | ||
</p> | ||
{productStatus !== 'active' && !loading && wrappedButtonContent } | ||
|
||
{loading && <span className="dashicons dashicons-update spin"/>} | ||
</div> | ||
</div>) | ||
} | ||
{loading && <span className="dashicons dashicons-update spin"/>} | ||
</div> | ||
</div>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters