import { useQuery } from '@apollo/client' import { PageOptions, usePageRouter } from '@graphcommerce/framer-next-pages' import { ApolloCustomerErrorFullPage } from '@graphcommerce/magento-customer' import { AccountDashboardOrdersDocument, AccountOrders, } from '@graphcommerce/magento-customer-account' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { AppShellTitle, FullPageMessage, GetStaticProps, iconBox, SheetShellHeader, SvgImage, Title, } from '@graphcommerce/next-ui' import { Container, NoSsr } from '@material-ui/core' import React from 'react' import SheetShell, { SheetShellProps } from '../../../components/AppShell/SheetShell' import apolloClient from '../../../lib/apolloClient' type GetPageStaticProps = GetStaticProps function AccountOrdersPage() { const { query } = usePageRouter() const { data, loading, error } = useQuery(AccountDashboardOrdersDocument, { fetchPolicy: 'cache-and-network', ssr: false, variables: { pageSize: 5, currentPage: Number(query?.page ?? 1), }, }) const customer = data?.customer if (loading) return
if (error) return ( ) return ( <> Orders {customer?.orders && customer.orders.items.length > 1 && ( <> Orders )} {customer?.orders && customer.orders.items.length < 1 && ( <> } /> )} ) } const pageOptions: PageOptions = { overlayGroup: 'account', SharedComponent: SheetShell, } AccountOrdersPage.pageOptions = pageOptions export default AccountOrdersPage export const getStaticProps: GetPageStaticProps = async ({ locale }) => { const client = apolloClient(locale, true) const conf = client.query({ query: StoreConfigDocument }) return { props: { apolloState: await conf.then(() => client.cache.extract()), variant: 'bottom', size: 'max', backFallbackHref: '/account', backFallbackTitle: 'Account', }, } }