type: fix type for hook and input

This commit is contained in:
DuvCharles 2023-02-10 18:14:39 +01:00 committed by Hadrien Lucas
parent 3abb486452
commit 8a0395050f
3 changed files with 16 additions and 7 deletions

View File

@ -4,21 +4,22 @@ import { useCallback } from 'react'
import useCustomer from '@vercel/commerce/customer/use-customer'
import { setCustomerToken } from '../utils/token/customer-token'
import { setCustomerRoute } from '../utils/token/customer-route'
import { LoginHook } from '@vercel/commerce/types/login'
export default useLogin as UseLogin<typeof handler>
export const handler: MutationHook<any> = {
export const handler: MutationHook<LoginHook> = {
fetchOptions: {
url: '/api/v2/shop/authentication-token',
method: 'POST',
},
fetcher: async ({ input: { email, password }, options, fetch }) => {
fetcher: async ({ input, options, fetch }) => {
const authReturn = await fetch({
url: options.url,
method: options.method,
body: {
email: email,
password: password,
email: input.email,
password: input.password,
},
variables: {
useToken: false,
@ -27,6 +28,8 @@ export const handler: MutationHook<any> = {
setCustomerToken(authReturn.token)
setCustomerRoute(authReturn.customer)
return authReturn
},
useHook:
({ fetch }) =>
@ -43,3 +46,8 @@ export const handler: MutationHook<any> = {
)
},
}
interface LoginInput {
email: string
password: string
}

View File

@ -4,10 +4,11 @@ import useCustomer, {
} from '@vercel/commerce/customer/use-customer'
import { getCustomerRoute } from '../utils/token/customer-route'
import { normalizeCustomer } from '../utils/normalize/normalize-customer'
import { CustomerHook } from '@vercel/commerce/types/customer'
export default useCustomer as UseCustomer<typeof handler>
export const handler: SWRHook<any> = {
export const handler: SWRHook<CustomerHook> = {
fetchOptions: {
url: `/customers/`,
method: 'GET',

View File

@ -1,7 +1,7 @@
import { Customer } from '@vercel/commerce/types/customer'
import { SyliusCustomer } from '../../types/customer'
export const normalizeCustomer = (syliusCustomer: SyliusCustomer): Customer => {
//customer has no type in commerce - SyliusCustomer type is defined in types/customer.ts
export const normalizeCustomer = (syliusCustomer: any): Customer => {
return {
firstName: syliusCustomer.firstName,
lastName: syliusCustomer.lastName,