diff --git a/bootstrap.php b/bootstrap.php index 5fd69a4f..c6c0a03b 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,7 +5,7 @@ use function NewfoldLabs\WP\ModuleLoader\register; -define( 'NFD_ECOMMERCE_MODULE_VERSION', '1.4.0' ); +define( 'NFD_ECOMMERCE_MODULE_VERSION', '1.4.1' ); if ( function_exists( 'is_admin' ) && is_admin() ) { $old_woocommerce_module_version = get_option( 'nfd_ecommerce_module_version' ); diff --git a/build/index.asset.php b/build/index.asset.php index eb55938c..16709f05 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('lodash', 'moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '06f7324e4a155909e837'); + array('lodash', 'moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '6b1b5fd9818934caf55a'); diff --git a/package-lock.json b/package-lock.json index 44c24aad..006ac35e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@newfold-labs/wp-module-ecommerce", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@newfold-labs/wp-module-ecommerce", - "version": "1.4.0", + "version": "1.4.1", "license": "GPL-2.0-or-later", "dependencies": { "@faizaanceg/pandora": "^1.1.1", @@ -11817,7 +11817,9 @@ } }, "node_modules/http-proxy-middleware": { - "version": "2.0.6", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-2.0.7.tgz", + "integrity": "sha512-fgVY8AV7qU7z/MmXJ/rxwbrtQH4jBQ9m7kp3llF0liB7glmFeVZFBepQb32T3y8n8k2+AEYuMPCpinYW+/CuRA==", "dev": true, "license": "MIT", "dependencies": { @@ -29386,7 +29388,9 @@ } }, "http-proxy-middleware": { - "version": "2.0.6", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-2.0.7.tgz", + "integrity": "sha512-fgVY8AV7qU7z/MmXJ/rxwbrtQH4jBQ9m7kp3llF0liB7glmFeVZFBepQb32T3y8n8k2+AEYuMPCpinYW+/CuRA==", "dev": true, "requires": { "@types/http-proxy": "^1.17.8", diff --git a/package.json b/package.json index 0a067704..38ebbc75 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@newfold-labs/wp-module-ecommerce", "description": "Brand Agnostic eCommerce Experience", "license": "GPL-2.0-or-later", - "version": "1.4.0", + "version": "1.4.1", "main": "build/index.js", "files": [ "build/", diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 17a7215f..99f310c7 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -1,211 +1,311 @@ -import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; -import { Button, Spinner } from "@newfold/ui-component-library"; +import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'; +import { Button, Spinner } from '@newfold/ui-component-library'; import apiFetch from '@wordpress/api-fetch'; -import { useEffect, useState } from "@wordpress/element"; -import { __ } from "@wordpress/i18n"; -import useSWR from "swr"; -import { myPluginsAndToolsPageLink, solutionButtonTextObject, wpSolutionsPromotedPluginsList } from "../constants"; -import { ReactComponent as RightArrow } from "../icons/right-arrow.svg"; -import { NewfoldRuntime } from "../sdk/NewfoldRuntime"; -import { PluginsSdk } from "../sdk/plugins"; -import { NoExistingPlan } from "./NoExistingPlan"; -import { Section } from "./Section"; +import { useEffect, useState } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import useSWR from 'swr'; +import { + myPluginsAndToolsPageLink, + wpSolutionsPromotedPluginsList, +} from '../constants'; +import { ReactComponent as RightArrow } from '../icons/right-arrow.svg'; +import { NewfoldRuntime } from '../sdk/NewfoldRuntime'; +import { PluginsSdk } from '../sdk/plugins'; +import { NoExistingPlan } from './NoExistingPlan'; +import { Section } from './Section'; import classNames from 'classnames'; - export function WPSolutionsBanner() { - - const entitlementsEndPoint = NewfoldRuntime.createApiUrl("/newfold-solutions/v1/entitlements"); - const [ error, setError ] = useState(null); - const [ apiResponse, setApiResponse ] = useState(null); - const [ isLoaded, setIsLoaded ] = useState( false ); - const [ purchasedSolution, setPurchasedSolution] = useState(null) - const [ availableSolutions, setAvailableSolutions] = useState([]); - const [ pluginActiveStatusArray, setPluginActiveStatusArray] = useState([]); - let currentSolution = []; - const hasSolution = NewfoldRuntime.hasCapability("hasSolution"); + const entitlementsEndPoint = NewfoldRuntime.createApiUrl( + '/newfold-solutions/v1/entitlements' + ); + const [ error, setError ] = useState( null ); + const [ apiResponse, setApiResponse ] = useState( null ); + const [ isLoaded, setIsLoaded ] = useState( false ); + const [ purchasedSolution, setPurchasedSolution ] = useState( null ); + const [ availableSolutions, setAvailableSolutions ] = useState( [] ); + const [ pluginActiveStatusArray, setPluginActiveStatusArray ] = useState( + [] + ); + let currentSolution = []; + const hasSolution = NewfoldRuntime.hasCapability( 'hasSolution' ); + const canSolution = NewfoldRuntime.hasCapability( + 'abTestSolutionsLaunched' + ); + + const premiumPluginStatus = useSWR( + 'nfd_slug_wonder_cart', + () => + PluginsSdk.queries + .status( + 'nfd_slug_wonder_cart', + 'sensei-lms', + 'wp-seo', + 'yith-woocommerce-affiliates', + 'yith-woocommerce-booking', + 'yith-woocommerce-points-and-rewards', + 'yith-woocommerce-wishlist', + 'yith-woocommerce-advanced-reviews', + 'yith-woocommerce-dynamic-pricing-and-discounts' + ) + .then( ( res ) => { + setPluginActiveStatusArray( res?.details ); + } ), + { refreshInterval: 30 * 1000 } + ); - let premiumPluginStatus = useSWR( - "nfd_slug_wonder_cart", - () => - PluginsSdk.queries - .status("nfd_slug_wonder_cart", - "sensei-lms", - "wp-seo", - "yith-woocommerce-affiliates", - "yith-woocommerce-booking", - "yith-woocommerce-points-and-rewards", - "yith-woocommerce-wishlist", - "yith-woocommerce-advanced-reviews", - "yith-woocommerce-dynamic-pricing-and-discounts") - .then(res => { - setPluginActiveStatusArray(res?.details) - }), - { refreshInterval: 30 * 1000 } - ); - - const routeChange = () =>{ - location.href = myPluginsAndToolsPageLink; - } + const routeChange = () => { + location.href = myPluginsAndToolsPageLink; + }; - useEffect( () => { - apiFetch( { url: `${ entitlementsEndPoint }` } ).then( - ( result ) => { - setIsLoaded(true); - setApiResponse(result) - result['solution'] && setPurchasedSolution(result['solution']) - setAvailableSolutions(result['solutions']) - }, - ( error ) => { - setIsLoaded(true); - setError(error); - } - ); - }, [] ); - - if ( error ) { - //Uncomment below line, to debug error in API response - //console.log(error.message, "error"); - return ( -
- { __(`${details['description']}`,"wp-module-ecommerce") } -
- { - //For type plugin - details.plsSlug !== "" ? + useEffect( () => { + apiFetch( { url: `${ entitlementsEndPoint }` } ).then( + ( result ) => { + setIsLoaded( true ); + setApiResponse( result ); + result.solution && setPurchasedSolution( result.solution ); + setAvailableSolutions( result.solutions ); + }, + ( e ) => { + setIsLoaded( true ); + setError( e ); + } + ); + }, [] ); - Object.entries(pluginActiveStatusArray).map(([slug, { status, url }]) => ( - details.plsSlug === slug ? - ( - //installed & active - status === "active" ? - ( - - ) - : - //installed but not active - status === "need_to_activate" ? - ( - - ) - : - //need to install - status === "need_to_install" ? - //premium - details.plsProviderName && details.plsSlug && !details.download ? - ( - - ) - : - //free - details.download ? - ( - - ) : null - : - null - ) - : null - )) - : - //For type not plugin - () + if ( ! canSolution ) { + return; + } + if ( error ) { + return ( ++ { details.description } +
+ { + //For type plugin + details.plsSlug !== '' ? ( + Object.entries( + pluginActiveStatusArray + ).map( + ( [ + slug, + { status, url }, + ] ) => + details.plsSlug === + slug ? ( + //installed & active + status === + 'active' ? ( + + ) : //installed but not active + status === + 'need_to_activate' ? ( + + ) : //need to install + status === + 'need_to_install' ? ( + //premium + details.plsProviderName && + details.plsSlug && + ! details.download ? ( + + ) : //free + details.download ? ( + + ) : null + ) : null + ) : null + ) + ) : ( + //For type not plugin + + ) + } +