import { useQuery } from '@apollo/client' import { PageOptions } from '@graphcommerce/framer-next-pages' import { AccountAddresses, ApolloCustomerErrorFullPage } from '@graphcommerce/magento-customer' import { AccountDashboardAddressesDocument } from '@graphcommerce/magento-customer-account' import { CountryRegionsDocument, PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { AppShellTitle, GetStaticProps, iconAddresses, SheetShellHeader, 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 Props = Record type GetPageStaticProps = GetStaticProps function AccountAddressesPage() { const { data, loading, error } = useQuery(AccountDashboardAddressesDocument, { fetchPolicy: 'network-only', ssr: false, }) const customer = data?.customer if (loading) return
if (error) return ( ) return ( <> Addresses {((customer?.addresses && customer.addresses.length > 1) || !customer?.addresses) && ( Addresses )} ) } const pageOptions: PageOptions = { overlayGroup: 'account', SharedComponent: SheetShell, sharedKey: () => 'account/addresses', } AccountAddressesPage.pageOptions = pageOptions export default AccountAddressesPage export const getStaticProps: GetPageStaticProps = async ({ locale }) => { const client = apolloClient(locale) const staticClient = apolloClient(locale) const conf = client.query({ query: StoreConfigDocument }) const countryRegions = staticClient.query({ query: CountryRegionsDocument, }) return { props: { ...(await countryRegions).data, apolloState: await conf.then(() => client.cache.extract()), variant: 'bottom', size: 'max', backFallbackHref: '/account', backFallbackTitle: 'Account', }, } }