porridger/front/src/hooks/api/useDispose.ts
2023-08-08 19:26:38 +03:00

36 lines
967 B
TypeScript

import { useCallback } from 'react'
import { useSendWithButton } from '..'
import { composeDisposeBody, composeDisposeURL, processDispose } from '../../api/dispose'
import { DisposeParams, isDisposeResponse } from '../../api/dispose/types'
function useDispose(resolve: () => void) {
const { doSend, button } = useSendWithButton(
'Выбор сделан',
'Зачтено',
true,
composeDisposeURL(),
'POST',
true,
isDisposeResponse,
processDispose,
)
const doSendWithClose = useCallback(async (...args: DisposeParams) => {
const res = await doSend({}, {
body: composeDisposeBody(...args),
headers: {
'Content-Type': 'application/json',
},
})
if (res) {
resolve()
}
}, [doSend, resolve])
return { handleDispose: doSendWithClose, disposeButton: button }
}
export default useDispose