From ee050c18a82306fe711378da8a6f724321e8f1d6 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 16:28:51 -0400 Subject: [PATCH 1/9] check `abTestSolutionsLaunched` capability to see if we can solution yet --- src/components/WPSolutionsBanner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 17a7215f..ea94e000 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -24,6 +24,7 @@ export function WPSolutionsBanner() { const [ pluginActiveStatusArray, setPluginActiveStatusArray] = useState([]); let currentSolution = []; const hasSolution = NewfoldRuntime.hasCapability("hasSolution"); + const canSolution = NewfoldRuntime.hasCapability( "abTestSolutionsLaunched" ); let premiumPluginStatus = useSWR( "nfd_slug_wonder_cart", @@ -62,7 +63,7 @@ export function WPSolutionsBanner() { } ); }, [] ); - + canSolution && if ( error ) { //Uncomment below line, to debug error in API response //console.log(error.message, "error"); From 0df1961062484d578191056703349ff3e9fbc406 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 16:45:26 -0400 Subject: [PATCH 2/9] bail early if `! canSolution` --- src/components/WPSolutionsBanner.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index ea94e000..373a6ad1 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -63,7 +63,10 @@ export function WPSolutionsBanner() { } ); }, [] ); - canSolution && + + if ( !canSolution ) { + return; + } if ( error ) { //Uncomment below line, to debug error in API response //console.log(error.message, "error"); From 56e9c6fa123aa80a5dd194476bc1ab2f27f8fa70 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 16:55:50 -0400 Subject: [PATCH 3/9] lint/formatting fixes --- src/components/WPSolutionsBanner.js | 520 +++++++++++++++++----------- 1 file changed, 316 insertions(+), 204 deletions(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 373a6ad1..1c368a31 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -1,215 +1,327 @@ -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, + 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 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 canSolution = NewfoldRuntime.hasCapability( "abTestSolutionsLaunched" ); + 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); - } - ); - }, [] ); + useEffect( () => { + apiFetch( { url: `${ entitlementsEndPoint }` } ).then( + ( result ) => { + setIsLoaded( true ); + setApiResponse( result ); + result.solution && setPurchasedSolution( result.solution ); + setAvailableSolutions( result.solutions ); + }, + ( error ) => { + setIsLoaded( true ); + setError( error ); + } + ); + }, [] ); - if ( !canSolution ) { + if ( ! canSolution ) { return; } - if ( error ) { - //Uncomment below line, to debug error in API response - //console.log(error.message, "error"); - return ( -
- - {__("Oops! something went wrong. Please try again later", "wp-module-ecommerce")} -
- ); - } - else if (!isLoaded){ - return ( -
- -
- ); - } - else if (apiResponse) { - if (purchasedSolution === null || !hasSolution) { - return (); - } - else{ - currentSolution = purchasedSolution === "WP_SOLUTION_CREATOR" ? - wpSolutionsPromotedPluginsList[0]['WP_SOLUTION_CREATOR'] : - purchasedSolution === "WP_SOLUTION_SERVICE" ? - wpSolutionsPromotedPluginsList[0]['WP_SOLUTION_SERVICE'] : wpSolutionsPromotedPluginsList[0]['WP_SOLUTION_COMMERCE']; - let solutionsCards = Object.values(currentSolution); - return( - hasSolution && - ( - - -
- { - solutionsCards?.map((details, index) => { - return (
-

- { __(`${details['title']}`,"wp-module-ecommerce") } -

-

- { __(`${details['description']}`,"wp-module-ecommerce") } -

- { - //For type plugin - details.plsSlug !== "" ? + if ( error ) { + //Uncomment below line, to debug error in API response + //console.log(error.message, "error"); + return ( +
+ + + { __( + 'Oops! something went wrong. Please try again later', + 'wp-module-ecommerce' + ) } + +
+ ); + } else if ( ! isLoaded ) { + return ( +
+ +
+ ); + } else if ( apiResponse ) { + if ( purchasedSolution === null || ! hasSolution ) { + return ; + } - 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 - () + currentSolution = + purchasedSolution === 'WP_SOLUTION_CREATOR' + ? wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_CREATOR + : purchasedSolution === 'WP_SOLUTION_SERVICE' + ? wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_SERVICE + : wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_COMMERCE; + const solutionsCards = Object.values( currentSolution ); + return ( + hasSolution && ( + + + +
+ { solutionsCards?.map( ( details, index ) => { + return ( +
+

+ { __( + `${ details.title }`, + 'wp-module-ecommerce' + ) } +

+

+ { __( + `${ details.description }`, + 'wp-module-ecommerce' + ) } +

+ { + //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 + + ) + } +
+ ); + } ) } +
- } - -
) - }) - } -
- - -
-
) - ) - } - - } -} \ No newline at end of file + + + + ) + ); + } +} From 909afe4bbcc63df08a2f5d6402a818c08ad70123 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 16:56:41 -0400 Subject: [PATCH 4/9] rewrite complex ternary chain with a switch and remove commented console.log --- src/components/WPSolutionsBanner.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 1c368a31..4d51ef2a 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -78,8 +78,6 @@ export function WPSolutionsBanner() { return; } if ( error ) { - //Uncomment below line, to debug error in API response - //console.log(error.message, "error"); return (
@@ -102,12 +100,20 @@ export function WPSolutionsBanner() { return ; } - currentSolution = - purchasedSolution === 'WP_SOLUTION_CREATOR' - ? wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_CREATOR - : purchasedSolution === 'WP_SOLUTION_SERVICE' - ? wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_SERVICE - : wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_COMMERCE; + switch ( purchasedSolution ) { + case 'WP_SOLUTION_CREATOR': + currentSolution = + wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_CREATOR; + break; + case 'WP_SOLUTION_SERVICE': + currentSolution = + wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_SERVICE; + break; + case 'WP_SOLUTION_COMMERCE': + default: + currentSolution = + wpSolutionsPromotedPluginsList[ 0 ].WP_SOLUTION_COMMERCE; + } const solutionsCards = Object.values( currentSolution ); return ( hasSolution && ( From 5981b18b83f362fd614cabcc070c4b7707c7d730 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 16:58:29 -0400 Subject: [PATCH 5/9] remove translations for dynamic strings --- src/components/WPSolutionsBanner.js | 35 ++++++----------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 4d51ef2a..2e376516 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -157,16 +157,10 @@ export function WPSolutionsBanner() { ) } >

- { __( - `${ details.title }`, - 'wp-module-ecommerce' - ) } + { details.title }

- { __( - `${ details.description }`, - 'wp-module-ecommerce' - ) } + { details.description }

{ //For type plugin @@ -189,10 +183,7 @@ export function WPSolutionsBanner() { as="a" href={ url } > - { __( - `${ details.cta.text }`, - 'wp-module-ecommerce' - ) } + { details.cta.text } ) : //installed but not active @@ -218,10 +209,7 @@ export function WPSolutionsBanner() { url } > - { __( - `${ details.cta.text }`, - 'wp-module-ecommerce' - ) } + { details.cta.text } ) : //need to install @@ -255,10 +243,7 @@ export function WPSolutionsBanner() { 'installing' } > - { __( - `${ details.cta.text }`, - 'wp-module-ecommerce' - ) } + { details.cta.text } ) : //free @@ -284,10 +269,7 @@ export function WPSolutionsBanner() { 'installing' } > - { __( - `${ details.cta.text }`, - 'wp-module-ecommerce' - ) } + { details.cta.text } ) : null @@ -302,10 +284,7 @@ export function WPSolutionsBanner() { as="a" href={ details.cta.url } > - { __( - `${ details.cta.text }`, - 'wp-module-ecommerce' - ) } + { details.cta.text } ) From 9eaaf8959ec844cb052c7bbbb3a8235d6d516681 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 17:19:34 -0400 Subject: [PATCH 6/9] lint fix - repeated var name --- src/components/WPSolutionsBanner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 2e376516..15654524 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -67,9 +67,9 @@ export function WPSolutionsBanner() { result.solution && setPurchasedSolution( result.solution ); setAvailableSolutions( result.solutions ); }, - ( error ) => { + ( e ) => { setIsLoaded( true ); - setError( error ); + setError( e ); } ); }, [] ); From 51b0b65b81cd2d5b28df7639b242438d5440d572 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 17:26:08 -0400 Subject: [PATCH 7/9] remove unused import --- src/components/WPSolutionsBanner.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/WPSolutionsBanner.js b/src/components/WPSolutionsBanner.js index 15654524..99f310c7 100644 --- a/src/components/WPSolutionsBanner.js +++ b/src/components/WPSolutionsBanner.js @@ -6,7 +6,6 @@ import { __ } from '@wordpress/i18n'; import useSWR from 'swr'; import { myPluginsAndToolsPageLink, - solutionButtonTextObject, wpSolutionsPromotedPluginsList, } from '../constants'; import { ReactComponent as RightArrow } from '../icons/right-arrow.svg'; From 296e479ceba1babc44e0c88c080bb0836547d1d6 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 17:26:55 -0400 Subject: [PATCH 8/9] version bump to 1.4.1 and update build files --- bootstrap.php | 2 +- build/index.asset.php | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) 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..22b8fcde 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", 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/", From d5ccc0f3ecf7b0ef9ebd1e67d6b7bc53a1692bca Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 17:34:39 -0400 Subject: [PATCH 9/9] ran `npm audit fix` to fix 1 vulnerability --- package-lock.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 22b8fcde..006ac35e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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",