Skip to content

Commit

Permalink
Merge pull request #49 from newfold-labs/bugfix/paypal
Browse files Browse the repository at this point in the history
Bugfix - PayPal Onboarding Flow
  • Loading branch information
ashrithapradeep authored Dec 14, 2022
2 parents 0ac18fa + adcdad5 commit fea6088
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
3 changes: 0 additions & 3 deletions includes/Partials/CaptiveFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public static function render_paypal() {
echo PHP_EOL;
echo '<div id="nfd-ecommerce" class="nfd-ecommerce-captive-flow">';
echo do_action( 'nfd-ecommerce-captive-flow-paypal' );
if (get_option('nfd-ecommerce-captive-flow-paypal', 'false') == 'true') {
echo '<script id="captive-flow-completion"> window.parent && window.parent.postMessage({ type: "captive-flow-completion" }, window.location.origin);</script>';
}
echo '</div>';
echo PHP_EOL;
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/GeneralSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { DashboardContent } from "./DashboardContent";

export function GeneralSettings(props) {
let { plugins } = props;
let cards = useCardManager(GeneralSettingsConfig(plugins));
let cards = useCardManager(GeneralSettingsConfig(plugins), {
refreshInterval: 8 * 1000,
});
const isLoading = !(cards ?? []).every(
(cardConfig) => cardConfig.isLoading == false
);
Expand Down
7 changes: 6 additions & 1 deletion src/components/MinimalCard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "@wordpress/element";
import { useEffect, useState } from "@wordpress/element";
import { ReactComponent as CompletedTask } from "../icons/task-completed-solid.svg";
import ModalCard from "./ModalCard";

Expand All @@ -7,6 +7,11 @@ export function MinimalCard(props) {
let modal = props.modal();
let { image: Icon } = props.assets(props.state);
const taskCompleted = props.state.taskCompleted;
useEffect(() => {
if (taskCompleted && showModal) {
setShowModal(false);
}
}, [taskCompleted, showModal]);
let { title, actionName } = props.text(taskCompleted);
const buttonClickHandler = () => {
const data = {
Expand Down
19 changes: 0 additions & 19 deletions src/components/ModalCard.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
import { Modal } from "@wordpress/components";
import { useEffect } from "@wordpress/element";

const ModalCard = (props) => {
const closeModal = () => props.setShowModal(false);

useEffect(() => {
let captiveFlowCompletion = async (e) => {
if (
e.origin === window.location.origin &&
e?.data?.type === "captive-flow-completion"
) {
for (let refreshDependency of props.modal?.onClose ?? []) {
await props.onRefresh(refreshDependency);
}
closeModal();
}
};
let iframeEvent = window.addEventListener("message", captiveFlowCompletion);
return () => {
window.removeEventListener("message", iframeEvent);
};
}, []);

return (
<Modal
overlayClassName="nfd-ecommerce-modal-overlay"
Expand Down
11 changes: 6 additions & 5 deletions src/components/useCardManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ function createDependencyTree(config) {
.map((_) => _.dataDependencies)
.flat()
.reduce(
(tree, { endpoint, refresh}) => ({
(tree, { endpoint, refresh }) => ({
...tree,
[endpoint]: tree[endpoint] ? [...tree[endpoint], refresh] : [refresh],
}),
{}
);
}

function useLoadDependencies(tree) {
function useLoadDependencies(tree, { refreshInterval }) {
let endpoints = Object.keys(tree);
let { data, mutate } = useSWR(
endpoints,
Expand All @@ -29,7 +29,8 @@ function useLoadDependencies(tree) {
}
}
return realisedTree;
}
},
{ refreshInterval }
);

async function onRefresh(dependency) {
Expand Down Expand Up @@ -57,9 +58,9 @@ function extractDependencies(realisedTree, cardConfig) {
);
}

export const useCardManager = (config) => {
export const useCardManager = (config, fetchOptions = {}) => {
const tree = createDependencyTree(config);
let { realisedTree, onRefresh } = useLoadDependencies(tree);
let { realisedTree, onRefresh } = useLoadDependencies(tree, fetchOptions);
return config
.map((cardConfig) => {
let { state: stateDefinition } = cardConfig;
Expand Down

0 comments on commit fea6088

Please sign in to comment.