import { useQuery } from '@apollo/client' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ApolloCustomerErrorFullPage, EditAddressForm } from '@graphcommerce/magento-customer' import { AccountDashboardAddressesDocument } from '@graphcommerce/magento-customer-account' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { AppShellTitle, GetStaticProps, iconAddresses, IconHeader, SectionContainer, SheetShellHeader, Title, } from '@graphcommerce/next-ui' import { Box, Container, NoSsr } from '@material-ui/core' import { Skeleton } from '@material-ui/lab' import { useRouter } from 'next/router' import React from 'react' import SheetShell, { SheetShellProps } from '../../../components/AppShell/SheetShell' import apolloClient from '../../../lib/apolloClient' type Props = Record type GetPageStaticProps = GetStaticProps function EditAddressPage(props: Props) { const router = useRouter() const { addressId } = router.query const { data, loading, error } = useQuery(AccountDashboardAddressesDocument, { fetchPolicy: 'network-only', ssr: false, }) const numAddressId = Number(addressId) const addresses = data?.customer?.addresses const address = addresses?.find((a) => a?.id === numAddressId) if (loading) return
if (error) return ( ) return ( <> Addresses Addresses {!address && !loading && ( )} {loading && (
)} {address && !loading && }
) } const pageOptions: PageOptions = { overlayGroup: 'account', SharedComponent: SheetShell, sharedKey: () => 'account/addresses', } EditAddressPage.pageOptions = pageOptions export default EditAddressPage export const getStaticProps: GetPageStaticProps = async ({ locale }) => { const client = apolloClient(locale) const staticClient = apolloClient(locale) const conf = client.query({ query: StoreConfigDocument }) return { props: { apolloState: await conf.then(() => client.cache.extract()), variant: 'bottom', size: 'max', backFallbackHref: '/account/addresses', backFallbackTitle: 'Addresses', }, } }