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

push nofication fix #200

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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', 'wp-api-fetch', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '48ad4ec1646d7a93d94d');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'wp-api-fetch', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'fa04bc00a67c691890f2');
69 changes: 36 additions & 33 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { NewfoldRuntime } from './sdk/NewfoldRuntime';
import apiFetch from '@wordpress/api-fetch';
import { Spinner } from '@newfold/ui-component-library';
import { __ } from '@wordpress/i18n';
import useSWR, { SWRConfig } from 'swr';
import { Products } from './components/ProductsAndServices';
import { Store } from './components/Store';
import { StoreDetails } from './components/StoreDetails';
import { WonderCart } from './components/WonderCart';
import { PluginsSdk } from './sdk/plugins';
import { AllPayments } from './components/AllPayments';
import domReady from '@wordpress/dom-ready';
import { AnalyticsSdk } from './sdk/analytics';
import { NewfoldRuntime } from "./sdk/NewfoldRuntime";
import apiFetch from "@wordpress/api-fetch";
import { Spinner } from "@newfold/ui-component-library";
import { __ } from "@wordpress/i18n";
import useSWR, { SWRConfig } from "swr";
import { Products } from "./components/ProductsAndServices";
import { Store } from "./components/Store";
import { StoreDetails } from "./components/StoreDetails";
import { WonderCart } from "./components/WonderCart";
import { PluginsSdk } from "./sdk/plugins";
import { AllPayments } from "./components/AllPayments";
import domReady from "@wordpress/dom-ready";
import { AnalyticsSdk } from "./sdk/analytics";

const fetcher = (path) => apiFetch({ url: NewfoldRuntime.createApiUrl(path) });

Expand All @@ -19,43 +19,44 @@ domReady(() => {
});

const pages = [
{ key: '/store', Page: Store },
{ key: '/store/products', Page: Products },
{ key: '/store/details', Page: StoreDetails },
{ key: '/store/sales_discounts', Page: WonderCart },
{ key: '/store/payments', Page: AllPayments },
{ key: "/store", Page: Store },
{ key: "/store/products", Page: Products },
{ key: "/store/details", Page: StoreDetails },
{ key: "/store/sales_discounts", Page: WonderCart },
{ key: "/store/payments", Page: AllPayments },
];

function parseWCStatus(data) {
const status = data?.details?.woocommerce?.status;
const isActive = status === 'active';
const needsInstall = status === 'need_to_install';
const isInstalling = data?.queue?.includes('woocommerce');
const isActive = status === "active";
const needsInstall = status === "need_to_install";
const isInstalling = data?.queue?.includes("woocommerce");
return { isActive, needsInstall, isInstalling };
}

/** @type {import("..").NewfoldEcommerce} */
export function NewfoldECommerce(props) {
let { data: woo, mutate } = useSWR(
'woo-status',
() => PluginsSdk.queries.status('woocommerce').then(parseWCStatus),
"woo-status",
() => PluginsSdk.queries.status("woocommerce").then(parseWCStatus),
{ revalidateOnReconnect: false, refreshInterval: 30 * 1000 }
);
let { Page } =
pages.find((page) => page.key === props.state.location) ?? pages[0];
let { notify } = props.wpModules;

useEffect(() => {
sessionStorage.getItem('reload') === 'true' &&
notify.push('woo-install-status', {
sessionStorage.getItem("reload") === "true" &&
sessionStorage.getItem("woo") === "true" &&
notify.push("woo-install-status", {
title: __(
'WooCommerce has been installed successfully',
'wp-module-ecommerce'
"WooCommerce has been installed successfully",
"wp-module-ecommerce"
),
variant: 'success',
variant: "success",
autoDismiss: 5000,
});
sessionStorage.setItem('reload', 'false');
sessionStorage.setItem("reload", "false");
}, []);

if (woo === undefined) {
Expand All @@ -67,9 +68,11 @@ export function NewfoldECommerce(props) {
}
if (!woo.isActive) {
Page = Store;
sessionStorage.setItem('reload', 'true');
sessionStorage.setItem("reload", "true");
sessionStorage.setItem("woo", "false");
} else {
if (sessionStorage.getItem('reload') === 'true') {
sessionStorage.setItem("woo", "true");
if (sessionStorage.getItem("reload") === "true") {
window.location.reload();
}
}
Expand All @@ -86,5 +89,5 @@ export function NewfoldECommerce(props) {
);
}

export * from './components/FreePlugins';
export * from './components/OnboardingScreen';
export * from "./components/FreePlugins";
export * from "./components/OnboardingScreen";
Loading