forked from crowetic/commerce
* changes * Adding shopify commit * Changed to query page by id * Fixed page query, Changed use-search GraphQl query * Update use-search.tsx * remove unused util * Changed cookie expiration * Update tsconfig.json Co-authored-by: okbel <curciobel@gmail.com>
38 lines
776 B
TypeScript
38 lines
776 B
TypeScript
import { getConfig, ShopifyConfig } from '../api'
|
|
import getPageQuery from '../utils/queries/get-page-query'
|
|
import { Page } from './get-all-pages'
|
|
|
|
type Variables = {
|
|
id: string
|
|
}
|
|
|
|
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
|
|
|
const getPage = async (options: {
|
|
variables: Variables
|
|
config: ShopifyConfig
|
|
preview?: boolean
|
|
}): Promise<GetPageResult> => {
|
|
let { config, variables } = options ?? {}
|
|
|
|
config = getConfig(config)
|
|
const { locale } = config
|
|
|
|
const { data } = await config.fetch(getPageQuery, {
|
|
variables,
|
|
})
|
|
const page = data.node
|
|
|
|
return {
|
|
page: page
|
|
? {
|
|
...page,
|
|
name: page.title,
|
|
url: `/${locale}/${page.handle}`,
|
|
}
|
|
: null,
|
|
}
|
|
}
|
|
|
|
export default getPage
|