GunaTrika d785f3c0ef New epcc client
- Extended motlin sdk and corrected pcm ur
 - Using new client for below sections
   - Get all products
   - Get product
   - Get all products path
   - Login & Signup
   - Customers
 - Changing product normalizer for pcm products
2021-09-17 15:14:38 +05:30

36 lines
941 B
TypeScript

import { SWRHook } from '@commerce/utils/types'
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
import getCustomerCookie from '../utils/get-customer-creds'
import epClient from '../utils/ep-client'
export default useCustomer as UseCustomer<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher() {
const creds = getCustomerCookie();
// if user is not logged-in return null
if(!creds) {
return null;
}
console.log('moltin sdk', epClient);
const {data:customer} = await epClient.Customers.Get(creds.customer_id, creds.token);
return {
...customer,
firstName: customer.name.split(" ")[0],
lastName: customer.name.split(" ")[1]
}
},
useHook: ({ useData }) => (input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,
...input?.swrOptions,
},
})
},
}