diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 2e872a4..97acaa0 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -22,16 +22,19 @@ export const Home: FC = () => { client?.deregisterElement("shopifyRefreshButton"); client?.registerElement("shopifyRefreshButton", { type: "refresh_button" }); - client?.registerElement("shopifyMenu", { - type: "menu", - items: [{ - title: "Change Linked Customer", - payload: { type: "changePage", page: "link_customer" }, - }, { - title: "Settings", - payload: "settings", - }], - }); + + // Redundant in app v1 -- we don't link customers and we don't link to admin settings + // client?.registerElement("shopifyMenu", { + // type: "menu", + // items: [{ + // title: "Change Linked Customer", + // payload: { type: "changePage", page: "link_customer" }, + // }, { + // title: "Settings", + // payload: "settings", + // }], + // }); + }, [client, state]) const onChangePageOrder = (orderId: Order['legacyResourceId']) => { @@ -43,23 +46,36 @@ export const Home: FC = () => { return; } - getEntityCustomerList(client, userId) - .then(async (customers: string[]) => { - const customerId = customers[0]; - - try { - const { customer } = await getCustomer(client, customerId); - const { orders } = customer; + // todo: change the getCustomer() method to accept an email + getCustomer( + client, + state.context?.type === 'ticket' ? state.context?.data.ticket.primaryUser.email : state.context?.data.email + ).then((customer) => { + if (customer) { + // todo: if we have a customer, link it to th app state, e.g. dispatch({ type: "linkedCustomer", customer }) so we can reference it in the various pages + } else { + // todo: if we don't have a customer then we don't show the app home page (show a message saying "Shopify customer could not be found for joe.bloggs@example.com") + } + }); - dispatch({ type: "linkedCustomer", customer }); - dispatch({ type: "linkedOrders", orders }); - } catch (e) { - const error = e as Error; + // getEntityCustomerList(client, userId) + // .then(async (customers: string[]) => { + // const customerId = customers[0]; + // + // try { + // const { customer } = await getCustomer(client, customerId); + // const { orders } = customer; + // + // dispatch({ type: "linkedCustomer", customer }); + // dispatch({ type: "linkedOrders", orders }); + // } catch (e) { + // const error = e as Error; + // + // throw new Error(error.message || "Failed to fetch"); + // } + // }) + // .catch((error: Error) => dispatch({ type: "error", error })); - throw new Error(error.message || "Failed to fetch"); - } - }) - .catch((error: Error) => dispatch({ type: "error", error })); // eslint-disable-next-line react-hooks/exhaustive-deps }, [client, userId]); diff --git a/src/pages/Main.tsx b/src/pages/Main.tsx index 077c80b..eff36de 100644 --- a/src/pages/Main.tsx +++ b/src/pages/Main.tsx @@ -21,10 +21,11 @@ export const Main: FC = () => { console.error(`Shopify: ${state._error}`); } - useTryToLinkCustomer( - useCallback(() => dispatch({ type: "changePage", page: "home" }), [dispatch]), - useCallback(() => dispatch({ type: "changePage", page: "link_customer" }), [dispatch]), - ); + // we don't need this as we simply match based on DP user's email address (and never show the link customer screen + // useTryToLinkCustomer( + // useCallback(() => dispatch({ type: "changePage", page: "home" }), [dispatch]), + // useCallback(() => dispatch({ type: "changePage", page: "link_customer" }), [dispatch]), + // ); useDeskproAppEvents({ onShow: () => { @@ -44,13 +45,13 @@ export const Main: FC = () => { const page = match(state.page) .with("home", () => ) - .with("link_customer", () => ) + // .with("link_customer", () => ) // Link customers page is redundant in v1 .with("view_customer", () => ) .with("edit_customer", () => ) .with("list_orders", () => ) .with("view_order", () => ) .with("edit_order", () => ) - .otherwise(() => ) + .otherwise(() => ) // Always default to home page as we don't need to link customers return ( <>