Skip to content

Commit

Permalink
Changed giftcard and booking redirections (#48)
Browse files Browse the repository at this point in the history
* Modified address details sent while country with no state is selected

* Update StoreAddress.js

* Update StoreAddress.js

* Showing Gift and Booking Cards only when the corresponding plugins are Active

* Update StoreAddress.scss

* Update StoreAddress.scss

* Closing the Payment popup on sucessfull linking with paypal account

* Changed create giftcard and booking urls

* Add JS to trigger postMessage from server-side once onboarding is successful

* Made captiveFlowCompletion function asynchronous

* Revert "Changed create giftcard and booking urls"

This reverts commit 47c1de1.

* Changed create giftcard and booking urls

* Handled error

Co-authored-by: Ashritha <[email protected]>
Co-authored-by: aulisius <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2022
1 parent 257aa12 commit 0ac18fa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
60 changes: 41 additions & 19 deletions src/configs/ManageProducts.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MultipleActionsCard } from "../components/MultipleActionsCard";
import { StandardCard } from "../components/StandardCard";
import { ReactComponent as AddProducts } from "../icons/add-products.svg";
import { ReactComponent as GiftCard } from "../icons/gift.svg";
import { ReactComponent as Booking } from "../icons/booking.svg";
import { ReactComponent as GiftCard } from "../icons/gift.svg";
import { ReactComponent as ImportProducts } from "../icons/import-products.svg";
import { createProduct } from "../services";
import {
wcBookings,
wcGiftCardsSelector,
Expand Down Expand Up @@ -95,8 +96,14 @@ const ManageProducts = (plugins) => [
isDisabled: () => plugins.status?.woocommerce !== "Active",
},
actions: {
buttonClick: (state, setShowModal) => {
window.location.href = getUrl("post-new.php?post_type=gift_card");
buttonClick: async (state, setShowModal) => {
let product = await createProduct({
type: "gift-card",
status: "draft",
});
window.location.href = product
? `post.php?post=${product.id}&action=edit`
: "post-new.php?post_type=product";
},
},
dataDependencies: [
Expand Down Expand Up @@ -126,14 +133,21 @@ const ManageProducts = (plugins) => [
isDisabled: () => plugins.status?.woocommerce !== "Active",
},
actions: {
onSelectAction: (state, action, opts) => {
let url =
action === "create_gift_card"
? "post-new.php?post_type=gift_card"
: action === "view_gift_card"
? "admin.php?page=yith_woocommerce_gift_cards_panel"
: "admin.php?page=yith_woocommerce_gift_cards_panel&tab=general";
window.location.href = url;
onSelectAction: async (state, action, opts) => {
if (action === "create_gift_card") {
let product = await createProduct({
type: "gift-card",
status: "draft",
});
window.location.href = product
? `post.php?post=${product.id}&action=edit`
: "post-new.php?post_type=product";
} else if (action === "view_gift_card") {
window.location.href = "edit.php?post_type=product";
} else {
window.location.href =
"admin.php?page=yith_woocommerce_gift_cards_panel";
}
},
},
dataDependencies: [
Expand All @@ -146,30 +160,38 @@ const ManageProducts = (plugins) => [
},
{
Card: StandardCard,
shouldRender: () =>
plugins?.status.nfd_slug_yith_woocommerce_booking === "Active",
title: "nfd_slug_yith_woocommerce_booking",
shouldRender: () => plugins?.status.yith_wcbk_panel === "Active",
title: "booking",
assets: (state) => ({ Icon: BookingIcon }),
text: (state) => ({
title: state.hasUsedPlugin ? "Manage Bookings" : "Setup Bookings",
actionName: state.hasUsedPlugin ? "Manage" : "Create now",
}),
state: {
hasUsedPlugin: (data) =>
data.nfd_slug_yith_woocommerce_booking.length > 0,
hasUsedPlugin: (data) => data.yith_wcbk_panel.length > 0,
showCompletedIcon: (data) => false,
isDisabled: () => plugins.status?.woocommerce !== "Active",
},
actions: {
buttonClick: (state, setShowModal) => {
window.location.href = "admin.php?page=yith_wcbk_panel";
buttonClick: async (state, setShowModal) => {
if (state.hasUsedPlugin) {
window.location.href = "admin.php?page=yith_wcbk_panel";
} else {
let product = await createProduct({
type: "booking",
status: "draft",
});
window.location.href = product
? `post.php?post=${product.id}&action=edit`
: "post-new.php?post_type=product";
}
},
},
dataDependencies: [
{
endpoint: "/wc/v3/products",
selector: wcBookings,
refresh: "nfd_slug_yith_woocommerce_booking",
refresh: "yith_wcbk_panel",
},
],
},
Expand Down
9 changes: 9 additions & 0 deletions src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const Endpoints = {
PAGE_STATUS: '/newfold-ecommerce/v1/user/page-status',
PLUGIN_STATUS: '/newfold-ecommerce/v1/plugins/status',
PLUGIN_INSTALL: '/newfold-onboarding/v1/plugins/install',
WC_PRODUCTS: '/wc/v3/products',
};
export async function fetchWPSettings() {
return apiFetch({ path: Endpoints.WP_SETTINGS });
Expand Down Expand Up @@ -42,3 +43,11 @@ export async function queuePluginInstall(plugin, token, priority = 10) {
data: { plugin, activate: true, queue: true, priority },
}).catch((error) => 'failed');
}

export async function createProduct(data) {
return apiFetch({
path: Endpoints.WC_PRODUCTS,
method: 'POST',
data
}).catch((error) => null);
}

0 comments on commit 0ac18fa

Please sign in to comment.