mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 06:56:59 +00:00
type: fix type for hook and input
This commit is contained in:
parent
3abb486452
commit
8a0395050f
@ -4,21 +4,22 @@ import { useCallback } from 'react'
|
|||||||
import useCustomer from '@vercel/commerce/customer/use-customer'
|
import useCustomer from '@vercel/commerce/customer/use-customer'
|
||||||
import { setCustomerToken } from '../utils/token/customer-token'
|
import { setCustomerToken } from '../utils/token/customer-token'
|
||||||
import { setCustomerRoute } from '../utils/token/customer-route'
|
import { setCustomerRoute } from '../utils/token/customer-route'
|
||||||
|
import { LoginHook } from '@vercel/commerce/types/login'
|
||||||
|
|
||||||
export default useLogin as UseLogin<typeof handler>
|
export default useLogin as UseLogin<typeof handler>
|
||||||
|
|
||||||
export const handler: MutationHook<any> = {
|
export const handler: MutationHook<LoginHook> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
url: '/api/v2/shop/authentication-token',
|
url: '/api/v2/shop/authentication-token',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
},
|
},
|
||||||
fetcher: async ({ input: { email, password }, options, fetch }) => {
|
fetcher: async ({ input, options, fetch }) => {
|
||||||
const authReturn = await fetch({
|
const authReturn = await fetch({
|
||||||
url: options.url,
|
url: options.url,
|
||||||
method: options.method,
|
method: options.method,
|
||||||
body: {
|
body: {
|
||||||
email: email,
|
email: input.email,
|
||||||
password: password,
|
password: input.password,
|
||||||
},
|
},
|
||||||
variables: {
|
variables: {
|
||||||
useToken: false,
|
useToken: false,
|
||||||
@ -27,6 +28,8 @@ export const handler: MutationHook<any> = {
|
|||||||
|
|
||||||
setCustomerToken(authReturn.token)
|
setCustomerToken(authReturn.token)
|
||||||
setCustomerRoute(authReturn.customer)
|
setCustomerRoute(authReturn.customer)
|
||||||
|
|
||||||
|
return authReturn
|
||||||
},
|
},
|
||||||
useHook:
|
useHook:
|
||||||
({ fetch }) =>
|
({ fetch }) =>
|
||||||
@ -43,3 +46,8 @@ export const handler: MutationHook<any> = {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LoginInput {
|
||||||
|
email: string
|
||||||
|
password: string
|
||||||
|
}
|
||||||
|
@ -4,10 +4,11 @@ import useCustomer, {
|
|||||||
} from '@vercel/commerce/customer/use-customer'
|
} from '@vercel/commerce/customer/use-customer'
|
||||||
import { getCustomerRoute } from '../utils/token/customer-route'
|
import { getCustomerRoute } from '../utils/token/customer-route'
|
||||||
import { normalizeCustomer } from '../utils/normalize/normalize-customer'
|
import { normalizeCustomer } from '../utils/normalize/normalize-customer'
|
||||||
|
import { CustomerHook } from '@vercel/commerce/types/customer'
|
||||||
|
|
||||||
export default useCustomer as UseCustomer<typeof handler>
|
export default useCustomer as UseCustomer<typeof handler>
|
||||||
|
|
||||||
export const handler: SWRHook<any> = {
|
export const handler: SWRHook<CustomerHook> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
url: `/customers/`,
|
url: `/customers/`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Customer } from '@vercel/commerce/types/customer'
|
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 {
|
return {
|
||||||
firstName: syliusCustomer.firstName,
|
firstName: syliusCustomer.firstName,
|
||||||
lastName: syliusCustomer.lastName,
|
lastName: syliusCustomer.lastName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user