import { useQuery } from '@apollo/client' import { PageOptions } from '@graphcommerce/framer-next-pages' import { AddressSingleLine, ApolloCustomerErrorFullPage, SignOutForm, } from '@graphcommerce/magento-customer' import { AccountDashboardDocument, AccountMenu, AccountMenuItem, } from '@graphcommerce/magento-customer-account' import { OrderStateLabelInline } from '@graphcommerce/magento-customer-order' import { CustomerNewsletterToggle } from '@graphcommerce/magento-newsletter' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { AppShellTitle, GetStaticProps, iconBox, iconEmailOutline, iconHome, iconId, iconLock, iconNewspaper, iconPersonAlt, iconShutdown, iconStar, TimeAgo, Title, } from '@graphcommerce/next-ui' import { Container, NoSsr } from '@material-ui/core' import React from 'react' import MinimalPageShell, { MinimalPageShellProps } from '../../components/AppShell/MinimalPageShell' import PageShellHeader from '../../components/AppShell/PageShellHeader' import { DefaultPageDocument } from '../../components/GraphQL/DefaultPage.gql' import apolloClient from '../../lib/apolloClient' type GetPageStaticProps = GetStaticProps function AccountIndexPage() { const { data, loading, error } = useQuery(AccountDashboardDocument, { fetchPolicy: 'cache-and-network', ssr: false, }) const { data: config } = useQuery(StoreConfigDocument) const locale = config?.storeConfig?.locale?.replace('_', '-') const customer = data?.customer const address = customer?.addresses?.filter((a) => a?.default_shipping)?.[0] || customer?.addresses?.[0] const orders = customer?.orders const latestOrder = orders?.items?.[orders?.items?.length - 1] if (loading) return
if (error) return ( ) const latestOrderDate = new Date(latestOrder?.order_date ?? new Date()) return ( <> Account Account {', '} {latestOrder?.items && ( processed, Invoiced: () => invoiced, Shipped: () => shipped, Refunded: () => refunded, Canceled: () => canceled, Returned: () => returned, Partial: () => partially processed, }} /> )} ) : undefined } /> : undefined} /> {customer?.reviews.items.length !== 0 && ( )} } /> ( )} /> ) } const pageOptions: PageOptions = { SharedComponent: MinimalPageShell, } AccountIndexPage.pageOptions = pageOptions export default AccountIndexPage export const getStaticProps: GetPageStaticProps = async ({ locale }) => { const staticClient = apolloClient(locale) const client = apolloClient(locale, true) const conf = client.query({ query: StoreConfigDocument }) const page = staticClient.query({ query: DefaultPageDocument, variables: { url: 'account', rootCategory: (await conf).data.storeConfig?.root_category_uid ?? '', }, }) return { props: { ...(await page).data, apolloState: await conf.then(() => client.cache.extract()), }, revalidate: 60 * 20, } }