Loan Laux 3112c7fc80
WIP pages implementation & fix add to cart variant ID bug
Signed-off-by: Loan Laux <loan@outgrow.io>
2021-05-17 15:28:04 +04:00

55 lines
1.0 KiB
TypeScript

import { getConfig, ReactionCommerceConfig } from '../api'
import { NavigationTreeItem } from '../schema'
import { getAllPagesQuery } from '../utils/queries'
type Variables = {
first?: number
}
type ReturnType = {
pages: Page[]
}
export type Page = {
id: string
name: string
url: string
sort_order?: number
body: string
}
const getAllPages = async (options?: {
variables?: Variables
config: ReactionCommerceConfig
preview?: boolean
}): Promise<ReturnType> => {
let { config, variables } = options ?? {}
config = getConfig(config)
const { locale } = config
console.log('locale', locale)
const { data } = await config.fetch(getAllPagesQuery, {
variables: {
...variables,
shopId: config.shopId,
},
})
const pages = data.shop?.defaultNavigationTree?.items?.map(
({
navigationItem: {
_id: id,
data: { contentForLanguage: name, url },
},
}: NavigationTreeItem) => ({
id,
url,
name,
body: '',
})
)
return { pages }
}
export default getAllPages