-
Notifications
You must be signed in to change notification settings - Fork 77
Bump @shopify/app-bridge-react from 3.7.10 to 4.1.3 #255
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,73 @@ | ||
import { useState } from "react"; | ||
import { Card, TextContainer, Text } from "@shopify/polaris"; | ||
import { Toast } from "@shopify/app-bridge-react"; | ||
import { useAppBridge } from "@shopify/app-bridge-react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useAppQuery, useAuthenticatedFetch } from "../hooks"; | ||
import { useQuery } from "react-query"; | ||
|
||
export function ProductsCard() { | ||
const emptyToastProps = { content: null }; | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [toastProps, setToastProps] = useState(emptyToastProps); | ||
const fetch = useAuthenticatedFetch(); | ||
const shopify = useAppBridge(); | ||
const { t } = useTranslation(); | ||
const [isPopulating, setIsPopulating] = useState(false); | ||
const productsCount = 5; | ||
|
||
const { | ||
data, | ||
refetch: refetchProductCount, | ||
isLoading: isLoadingCount, | ||
isRefetching: isRefetchingCount, | ||
} = useAppQuery({ | ||
url: "/api/products/count", | ||
reactQueryOptions: { | ||
onSuccess: () => { | ||
setIsLoading(false); | ||
}, | ||
} = useQuery({ | ||
queryKey: ["productCount"], | ||
queryFn: async () => { | ||
const response = await fetch("/api/products/count"); | ||
return await response.json(); | ||
}, | ||
refetchOnWindowFocus: false, | ||
}); | ||
|
||
const toastMarkup = toastProps.content && !isRefetchingCount && ( | ||
<Toast {...toastProps} onDismiss={() => setToastProps(emptyToastProps)} /> | ||
); | ||
const setPopulating = (flag) => { | ||
shopify.loading(flag); | ||
setIsPopulating(flag); | ||
}; | ||
|
||
const handlePopulate = async () => { | ||
setIsLoading(true); | ||
const response = await fetch("/api/products", {method: "POST"}); | ||
setPopulating(true); | ||
const response = await fetch("/api/products", { method: "POST" }); | ||
|
||
if (response.ok) { | ||
await refetchProductCount(); | ||
setToastProps({ | ||
content: t("ProductsCard.productsCreatedToast", { | ||
count: productsCount, | ||
}), | ||
}); | ||
|
||
shopify.toast.show( | ||
t("ProductsCard.productsCreatedToast", { count: productsCount }) | ||
); | ||
} else { | ||
setIsLoading(false); | ||
setToastProps({ | ||
content: t("ProductsCard.errorCreatingProductsToast"), | ||
error: true, | ||
shopify.toast.show(t("ProductsCard.errorCreatingProductsToast"), { | ||
isError: true, | ||
}); | ||
} | ||
|
||
setPopulating(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{toastMarkup} | ||
<Card | ||
title={t("ProductsCard.title")} | ||
sectioned | ||
primaryFooterAction={{ | ||
content: t("ProductsCard.populateProductsButton", { | ||
count: productsCount, | ||
}), | ||
onAction: handlePopulate, | ||
loading: isLoading, | ||
}} | ||
> | ||
<TextContainer spacing="loose"> | ||
<p>{t("ProductsCard.description")}</p> | ||
<Text as="h4" variant="headingMd"> | ||
{t("ProductsCard.totalProductsHeading")} | ||
<Text variant="bodyMd" as="p" fontWeight="semibold"> | ||
{isLoadingCount ? "-" : data.count} | ||
</Text> | ||
<Card | ||
title={t("ProductsCard.title")} | ||
sectioned | ||
primaryFooterAction={{ | ||
content: t("ProductsCard.populateProductsButton", { | ||
count: productsCount, | ||
}), | ||
onAction: handlePopulate, | ||
loading: isPopulating, | ||
}} | ||
> | ||
<TextContainer spacing="loose"> | ||
<p>{t("ProductsCard.description")}</p> | ||
<Text as="h4" variant="headingMd"> | ||
{t("ProductsCard.totalProductsHeading")} | ||
<Text variant="bodyMd" as="p" fontWeight="semibold"> | ||
{isLoadingCount ? "-" : data?.count} | ||
</Text> | ||
</TextContainer> | ||
</Card> | ||
</> | ||
</Text> | ||
</TextContainer> | ||
</Card> | ||
); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import { useCallback } from "react"; | ||
import { AppProvider } from "@shopify/polaris"; | ||
import { useNavigate } from "@shopify/app-bridge-react"; | ||
import "@shopify/polaris/build/esm/styles.css"; | ||
import { getPolarisTranslations } from "../../utils/i18nUtils"; | ||
|
||
function AppBridgeLink({ url, children, external, ...rest }) { | ||
const navigate = useNavigate(); | ||
const handleClick = useCallback(() => { | ||
navigate(url); | ||
}, [url]); | ||
const handleClick = useCallback(() => window.open(url), [url]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering we are fixing the template in this PR, can we wait til the back stack fix is out. I would like to bring => The back stack PRs should be merged this week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can wait. Will we need to change anything here though? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we do. There are two options. I think option 1 is the best for most cases.
const handleClick = useCallback(async () => {
await shopify.saveBar.leaveConfirmation();
navigate(url);
}, [url]);
|
||
|
||
const IS_EXTERNAL_LINK_REGEX = /^(?:[a-z][a-z\d+.-]*:|\/\/)/; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { AppBridgeProvider } from "./AppBridgeProvider"; | ||
export { QueryProvider } from "./QueryProvider"; | ||
export { PolarisProvider } from "./PolarisProvider"; |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add home page if the app root is not
/
<a href="/app" rel="home">Home</a>