forked from crowetic/commerce
Added useLogout hook
This commit is contained in:
parent
79d0c0a0cb
commit
f81c507157
35
lib/bigcommerce/use-logout.tsx
Normal file
35
lib/bigcommerce/use-logout.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { HookFetcher } from '@lib/commerce/utils/types'
|
||||
import useCommerceLogout from '@lib/commerce/use-logout'
|
||||
|
||||
const defaultOpts = {
|
||||
url: '/api/bigcommerce/customers/logout',
|
||||
method: 'GET',
|
||||
}
|
||||
|
||||
export const fetcher: HookFetcher<null> = (options, _, fetch) => {
|
||||
return fetch({
|
||||
...defaultOpts,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export function extendHook(customFetcher: typeof fetcher) {
|
||||
const useLogout = () => {
|
||||
const fn = useCommerceLogout<null>(defaultOpts, customFetcher)
|
||||
|
||||
return useCallback(
|
||||
async function login() {
|
||||
const data = await fn(null)
|
||||
return data
|
||||
},
|
||||
[fn]
|
||||
)
|
||||
}
|
||||
|
||||
useLogout.extend = extendHook
|
||||
|
||||
return useLogout
|
||||
}
|
||||
|
||||
export default extendHook(fetcher)
|
5
lib/commerce/use-logout.tsx
Normal file
5
lib/commerce/use-logout.tsx
Normal file
@ -0,0 +1,5 @@
|
||||
import useAction from './utils/use-action'
|
||||
|
||||
const useLogout = useAction
|
||||
|
||||
export default useLogout
|
@ -9,7 +9,7 @@ export type FetcherOptions = {
|
||||
body?: any
|
||||
}
|
||||
|
||||
export type HookFetcher<T, Input> = (
|
||||
export type HookFetcher<T, Input = null> = (
|
||||
options: HookFetcherOptions | null,
|
||||
input: Input,
|
||||
fetch: Fetcher<T>
|
||||
@ -22,5 +22,3 @@ export type HookFetcherOptions = {
|
||||
}
|
||||
|
||||
export type HookInput = [string, string | number | undefined][]
|
||||
|
||||
export type HookDeps = string | number | undefined[]
|
||||
|
@ -2,7 +2,7 @@ import { useCallback } from 'react'
|
||||
import type { HookFetcher, HookFetcherOptions } from './types'
|
||||
import { useCommerce } from '..'
|
||||
|
||||
export default function useAction<T, Input>(
|
||||
export default function useAction<T, Input = null>(
|
||||
options: HookFetcherOptions,
|
||||
fetcher: HookFetcher<T, Input>
|
||||
) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user