Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sales channel page to promote Ecomdash plugin adoption #335

Merged
merged 21 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '694f2cb4d10abd7be591');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '13b8ef685af62f69e2dd');
8 changes: 6 additions & 2 deletions src/components/SalesChannel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Modal } from "@newfold/ui-component-library";
import { Button, Modal, Spinner } from "@newfold/ui-component-library";
import { useEffect, useState } from "@wordpress/element";
import { __ } from "@wordpress/i18n";
import useSWR from "swr";
Expand Down Expand Up @@ -42,6 +42,7 @@ export function SalesChannel(props) {
const hasYithExtended = NewfoldRuntime.hasCapability("hasYithExtended");
const hasEcomdash = NewfoldRuntime.hasCapability("hasEcomdash")
const [ecomdashSetupStatus, setEcomdashSetupStatus] = useState("")
const [ecomdashLoading, setEcomdashLoading] = useState(false);


useEffect(() => {
Expand All @@ -51,14 +52,17 @@ export function SalesChannel(props) {
useEffect(() => {
let pluginConnectionStatus = async () => {
try {
setEcomdashLoading(true);
const response = await fetch("/wp-admin/admin.php?page=newfold-ecomdash-settings");
const text = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');
const element = doc.querySelector('#disconnect-instance');
setEcomdashSetupStatus(element === null);
setEcomdashLoading(false);
return element === null
} catch (error) {
setEcomdashLoading(false);
console.error('Error fetching HTML:', error);
}
}
Expand Down Expand Up @@ -113,7 +117,7 @@ export function SalesChannel(props) {
) : null}
id={ecomdashStatus.data.isInstalled ? "manage-ecomdash" : "install-ecomdash"}
>
{ecomdashStatus.data.isInstalled ? (ecomdashSetupStatus ? __("Get Started Now", "wp-module-ecommerce") : __("Go to Ecomdash", "wp-module-ecommerce")) : __("Install Now", "wp-module-ecommerce")}
{ecomdashStatus.data.isInstalled ? (ecomdashLoading ? <><Spinner /> __("Loading...", "wp-module-ecommerce") </> : ecomdashSetupStatus ? __("Get Started Now", "wp-module-ecommerce") : __("Go to Ecomdash", "wp-module-ecommerce")) : __("Install Now", "wp-module-ecommerce")}
</Button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a parenthisis for double ternary operation for better readablity

</div>
<Ecomdash className="nfd-flex-none nfd-self-start" />
Expand Down
Loading