This commit is contained in:
Bel Curcio 2021-06-11 14:13:43 -03:00
parent c74c4b0e07
commit f769a3531b
8 changed files with 66 additions and 20 deletions

View File

@ -33,10 +33,10 @@ const operations = {
export const provider = { config, operations } export const provider = { config, operations }
export type Provider = typeof provider export type Provider = typeof provider
export type LocalAPI<P extends Provider = Provider> = CommerceAPI<P> export type LocalAPI<P extends Provider = Provider> = CommerceAPI<P | any>
export function getCommerceApi<P extends Provider>( export function getCommerceApi<P extends Provider>(
customProvider: P = provider as any customProvider: P = provider as any
): LocalAPI<P> { ): LocalAPI<P> {
return commerceApi(customProvider) return commerceApi(customProvider as any)
} }

View File

@ -1,4 +1,4 @@
export type Page = any export type Page = { url: string }
export type GetAllPagesResult = { pages: Page[] } export type GetAllPagesResult = { pages: Page[] }
import type { LocalConfig } from '../index' import type { LocalConfig } from '../index'

View File

@ -6,7 +6,7 @@ import data from '../../data.json'
export default function getAllProductsOperation({ export default function getAllProductsOperation({
commerce, commerce,
}: OperationContext<Provider>) { }: OperationContext<any>) {
async function getAllProducts<T extends GetAllProductsOperation>({ async function getAllProducts<T extends GetAllProductsOperation>({
query = '', query = '',
variables, variables,

View File

@ -1,9 +1,13 @@
import type { LocalConfig } from '../index' import type { LocalConfig } from '../index'
import { Product } from '@commerce/types/product' import { Product } from '@commerce/types/product'
import { GetProductOperation } from '@commerce/types/product'
import data from '../../data.json' import data from '../../data.json'
import type { OperationContext } from '@commerce/api/operations'
export default function getProductOperation() { export default function getProductOperation({
async function getProduct({ commerce,
}: OperationContext<any>) {
async function getProduct<T extends GetProductOperation>({
query = '', query = '',
variables, variables,
config, config,

View File

@ -1,7 +1,11 @@
import { useCallback } from 'react' import { useCallback } from 'react'
export function emptyHook() { type Options = {
const useEmptyHook = async (options = {}) => { includeProducts?: boolean
}
export function emptyHook(options?: Options) {
const useEmptyHook = async ({ id }: { id: string | number }) => {
return useCallback(async function () { return useCallback(async function () {
return Promise.resolve() return Promise.resolve()
}, []) }, [])

View File

@ -1,13 +1,43 @@
import { useCallback } from 'react' import { HookFetcher } from '@commerce/utils/types'
import type { Product } from '@commerce/types/product'
export function emptyHook() { const defaultOpts = {}
const useEmptyHook = async (options = {}) => {
return useCallback(async function () { export type Wishlist = {
return Promise.resolve() items: [
}, []) {
product_id: number
variant_id: number
id: number
product: Product
} }
]
return useEmptyHook
} }
export default emptyHook export interface UseWishlistOptions {
includeProducts?: boolean
}
export interface UseWishlistInput extends UseWishlistOptions {
customerId?: number
}
export const fetcher: HookFetcher<Wishlist | null, UseWishlistInput> = () => {
return null
}
export function extendHook(
customFetcher: typeof fetcher,
// swrOptions?: SwrOptions<Wishlist | null, UseWishlistInput>
swrOptions?: any
) {
const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => {
return { data: null }
}
useWishlist.extend = extendHook
return useWishlist
}
export default extendHook(fetcher)

View File

@ -8,6 +8,7 @@ import { Text } from '@components/ui'
import { Layout } from '@components/common' import { Layout } from '@components/common'
import getSlug from '@lib/get-slug' import getSlug from '@lib/get-slug'
import { missingLocaleInPages } from '@lib/usage-warns' import { missingLocaleInPages } from '@lib/usage-warns'
import type { Page } from '@commerce/types/page'
export async function getStaticProps({ export async function getStaticProps({
preview, preview,
@ -20,7 +21,9 @@ export async function getStaticProps({
const { categories } = await commerce.getSiteInfo({ config, preview }) const { categories } = await commerce.getSiteInfo({ config, preview })
const path = params?.pages.join('/') const path = params?.pages.join('/')
const slug = locale ? `${locale}/${path}` : path const slug = locale ? `${locale}/${path}` : path
const pageItem = pages.find((p) => (p.url ? getSlug(p.url) === slug : false)) const pageItem = pages.find((p: Page) =>
p.url ? getSlug(p.url) === slug : false
)
const data = const data =
pageItem && pageItem &&
(await commerce.getPage({ (await commerce.getPage({
@ -43,7 +46,7 @@ export async function getStaticProps({
export async function getStaticPaths({ locales }: GetStaticPathsContext) { export async function getStaticPaths({ locales }: GetStaticPathsContext) {
const config = { locales } const config = { locales }
const { pages } = await commerce.getAllPages({ config }) const { pages }: { pages: Page[] } = await commerce.getAllPages({ config })
const [invalidPaths, log] = missingLocaleInPages() const [invalidPaths, log] = missingLocaleInPages()
const paths = pages const paths = pages
.map((page) => page.url) .map((page) => page.url)

View File

@ -27,5 +27,10 @@
} }
}, },
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"], "include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
"exclude": ["node_modules", "framework/swell", "framework/vendure"] "exclude": [
"node_modules",
"framework/swell",
"framework/vendure",
"framework/local"
]
} }