Merge pull request #8 from trikatechnologies/CKAD-75-store-categories-categoryPages

Ckad 75 store categories category pages
This commit is contained in:
Gunasekaran R 2021-12-24 15:45:25 +05:30 committed by GitHub
commit 627289b1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34340 additions and 5839 deletions

View File

@ -31,4 +31,4 @@ const fetchGraphqlApi: (getConfig: () => ElasticpathConfig) => GraphQLFetcher =
return { data: json.data, res } return { data: json.data, res }
} }
export default fetchGraphqlApi export default fetchGraphqlApi

View File

@ -1,17 +1,53 @@
import { SWRHook } from '@commerce/utils/types' import { SWRHook } from '@commerce/utils/types'
import useSearch, { UseSearch } from '@commerce/product/use-search' import useSearch, { UseSearch } from '@commerce/product/use-search'
import type { SearchProductsHook } from '../types/product'
import epClient from '../utils/ep-client'
import normalizeProducts from '../utils/normalize'
export default useSearch as UseSearch<typeof handler> export default useSearch as UseSearch<typeof handler>
export const handler: SWRHook<any> = { export type SearchProductsInput = {
search?: string
sort?: string
}
export const handler: SWRHook<SearchProductsHook> = {
fetchOptions: { fetchOptions: {
query: '', url: 'Products',
method: 'All',
}, },
async fetcher({ input, options, fetch }) {}, async fetcher({ input: { search, sort }, options, fetch }) {
useHook: () => () => { // Use a dummy base as we only care about the relative path
return { let url = new URL(options.url!, 'http://api.moltin.com')
data: {
products: [], if (search) url.searchParams.set('search', search)
}, if (sort) url.searchParams.set('sort', sort)
if(sort){
let productsRes = await epClient.PCM.Sort(sort).All();
let products = await normalizeProducts(productsRes.data);
return {
products: products,
}
}
else{
let productsRes = await epClient.PCM.All()
let products = await normalizeProducts(productsRes.data);
return {
products: products
}
} }
}, },
} useHook: ({ useData }) => (input = {}) => {
return useData({
input: [
['search', input.search],
['sort', input.sort],
],
swrOptions: {
revalidateOnFocus: false,
...input.swrOptions,
},
})
},
}

View File

@ -16,7 +16,9 @@ import { handler as useSignup } from './auth/use-signup'
import { handler as useCheckout } from './checkout/use-checkout' import { handler as useCheckout } from './checkout/use-checkout'
import { handler as useCards } from './customer/card/use-cards' import { handler as useCards } from './customer/card/use-cards'
import { handler as useAddCardItem } from './customer/card/use-add-item'
import { handler as useAddresses } from './customer/address/use-addresses' import { handler as useAddresses } from './customer/address/use-addresses'
import { handler as useAddAddressItem } from './customer/address/use-add-item'
import {fetcher} from './fetcher' import {fetcher} from './fetcher'
@ -36,10 +38,12 @@ export const elasticpathProvider = {
customer: { customer: {
useCustomer, useCustomer,
card: { card: {
useCards useCards,
useAddItem: useAddCardItem,
}, },
address: { address: {
useAddresses useAddresses,
useAddItem: useAddAddressItem,
} }
}, },
products: { useSearch }, products: { useSearch },

View File

@ -0,0 +1 @@
export * from '@commerce/types/product'

View File

@ -31,4 +31,4 @@ const fetchGraphqlApi: (getConfig: () => LocalConfig) => GraphQLFetcher =
return { data: json.data, res } return { data: json.data, res }
} }
export default fetchGraphqlApi export default fetchGraphqlApi

28456
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

11656
yarn.lock

File diff suppressed because it is too large Load Diff