import { Button } from '@wordpress/components';
import { useEffect, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, check, warning } from '@wordpress/icons';
import { installPlugin, activatePlugin } from '@shared/api/wp';
import { useActivityStore } from '@shared/state/activity';
export const RecommendationCard = ({ recommendation }) => {
if (recommendation.pluginSlug) {
return ;
}
return ;
};
const LinkCard = ({ recommendation }) => {
const { by, slug, description, image, title, linkType } = recommendation;
const { incrementActivity } = useActivityStore();
if (!recommendation?.[linkType]) return null;
return (
incrementActivity(`recommendations-${slug}`)}
target="_blank"
rel="noopener noreferrer"
className="cursor-pointer rounded border border-gray-200 bg-transparent p-4 text-left text-base no-underline hover:border-design-main hover:bg-gray-50 rtl:text-right">
{title}
{by &&
{by}
}
{description}
);
};
const InstallCard = ({ recommendation }) => {
const { by, slug, description, image, title, pluginSlug } = recommendation;
const { incrementActivity } = useActivityStore();
return (
incrementActivity(`recommendations-install-${slug}`)}
className="rounded border border-gray-200 bg-transparent p-4 text-left text-base rtl:text-right">
{title}
{by &&
{by}
}
{description}
);
};
const InstallButton = ({ pluginSlug }) => {
const [installing, setInstalling] = useState(false);
const [status, setStatus] = useState('');
useEffect(() => {
const { installedPlugins, activePlugins } = window.extSharedData;
const hasPlugin = (p) => p?.includes(pluginSlug);
const installed = Object.values(installedPlugins).some(hasPlugin);
const active = Object.values(activePlugins).some(hasPlugin);
if (installed) setStatus('inactive');
if (active) setStatus('active');
}, [pluginSlug, setStatus]);
const handleClick = async () => {
setInstalling(true);
try {
await installPlugin(pluginSlug);
} catch (_) {
// Fail silently if the plugin is already installed
}
try {
await activatePlugin(pluginSlug);
setStatus('active');
} catch (_) {
setStatus('error');
setTimeout(() => {
setStatus(status);
}, 1500);
}
setInstalling(false);
};
if (status === 'error') {
return (
<>
{__('Error', 'extendify-local')}
>
);
}
if (status === 'active') {
return (
<>
{__('Active', 'extendify-local')}
>
);
}
if (status === 'inactive') {
return (
{installing
? __('Activating...', 'extendify-local')
: __('Activate', 'extendify-local')}
);
}
return (
{installing
? __('Installing...', 'extendify-local')
: __('Install Now', 'extendify-local')}
);
};
Get Pro Addon to unlock more features
The features below are available in Nextend Social Login Pro Addon. Get it today and tweak the awesome settings.
If you already have a license, you can Authorize your Pro Addon. Otherwise you can purchase it using the button below.
Buy Pro Addon
Authorize Pro Addon
{"id":24,"count":44,"description":"","link":"https:\/\/dispenseroo.store\/product-category\/rso-oil\/","name":"RSO OIL","slug":"rso-oil","taxonomy":"product_cat","parent":0,"meta":[],"_links":{"self":[{"href":"https:\/\/dispenseroo.store\/wp-json\/wp\/v2\/product_cat\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dispenseroo.store\/wp-json\/wp\/v2\/product_cat"}],"about":[{"href":"https:\/\/dispenseroo.store\/wp-json\/wp\/v2\/taxonomies\/product_cat"}],"wp:post_type":[{"href":"https:\/\/dispenseroo.store\/wp-json\/wp\/v2\/product?product_cat=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}