diff --git a/.changeset/cold-readers-design.md b/.changeset/cold-readers-design.md new file mode 100644 index 0000000000..4bb277c194 --- /dev/null +++ b/.changeset/cold-readers-design.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/magento-cart-checkout': patch +--- + +Prevent rendering "You have not placed an order" before the router resolves. diff --git a/examples/magento-graphcms/pages/checkout/success.tsx b/examples/magento-graphcms/pages/checkout/success.tsx index 6409dff05e..ec5d167d4d 100644 --- a/examples/magento-graphcms/pages/checkout/success.tsx +++ b/examples/magento-graphcms/pages/checkout/success.tsx @@ -19,7 +19,7 @@ import { } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' -import { Button, Box, Container, Typography } from '@mui/material' +import { Button, Box, Container, Typography, CircularProgress } from '@mui/material' import { useRouter } from 'next/router' import { LayoutDocument, @@ -28,26 +28,24 @@ import { LayoutMinimalProps, } from '../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../lib/graphql/graphqlSsrClient' +import { WaitForQueries } from '@graphcommerce/ecommerce-ui' type Props = Record type GetPageStaticProps = GetStaticProps function OrderSuccessPage() { - const hasCartId = !!useRouter().query.cart_id - - const orderNumber = useRouter().query.order_number + const router = useRouter() + const { cart_id, order_number } = router.query ?? {} + const hasCartId = !!cart_id return ( <> - - {hasCartId && ( - - - - )} - - + + } title={} />} + > {!hasCartId && ( } @@ -61,19 +59,26 @@ function OrderSuccessPage() { )} + {hasCartId && ( - <> + + + + + + )} + + {hasCartId && ( + - {orderNumber && #{orderNumber}} + {order_number && #{order_number}} - - @@ -81,9 +86,9 @@ function OrderSuccessPage() { - + )} - + ) } diff --git a/examples/magento-open-source/pages/checkout/success.tsx b/examples/magento-open-source/pages/checkout/success.tsx index 936a4754e7..b73e1eeaaf 100644 --- a/examples/magento-open-source/pages/checkout/success.tsx +++ b/examples/magento-open-source/pages/checkout/success.tsx @@ -1,4 +1,5 @@ -import type { PageOptions } from '@graphcommerce/framer-next-pages' +import { WaitForQueries } from '@graphcommerce/ecommerce-ui' +import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst } from '@graphcommerce/graphql' import { CartItemSummary, @@ -19,7 +20,7 @@ import { } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' -import { Box, Button, Container, Typography } from '@mui/material' +import { Box, Button, CircularProgress, Container, Typography } from '@mui/material' import { useRouter } from 'next/router' import type { LayoutMinimalProps, LayoutNavigationProps } from '../../components' import { LayoutDocument, LayoutMinimal } from '../../components' @@ -29,21 +30,18 @@ type Props = Record type GetPageStaticProps = GetStaticProps function OrderSuccessPage() { - const hasCartId = !!useRouter().query.cart_id - - const orderNumber = useRouter().query.order_number + const router = useRouter() + const { cart_id, order_number } = router.query ?? {} + const hasCartId = !!cart_id return ( <> - - {hasCartId && ( - - - - )} - - + + } title={} />} + > {!hasCartId && ( } @@ -57,12 +55,21 @@ function OrderSuccessPage() { )} + + {hasCartId && ( + + + + + + )} + {hasCartId && ( - <> + - {orderNumber && #{orderNumber}} + {order_number && #{order_number}} @@ -77,9 +84,9 @@ function OrderSuccessPage() { - + )} - + ) }