Skip to content

Commit

Permalink
push nofication fix
Browse files Browse the repository at this point in the history
  • Loading branch information
manikantakailasa committed Jan 9, 2024
1 parent 66fe3fa commit 8f64fd2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
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";

0 comments on commit 8f64fd2

Please sign in to comment.