porridger/front/src/hooks/api/useDispose.ts
dm1sh b93ab9794d
Added announcement disposal:
Added ann details button
Added modal shown on its click
Moved trashbox selection there
Added trashboxes mock while testing in restricted area
2023-08-01 18:23:56 +03:00

36 lines
970 B
TypeScript

import { useCallback } from 'react'
import { useSendWithButton } from '..'
import { composeDisposeBody, composeDisposeURL, processDispose } from '../../api/dispose'
import { DisposeParams, isDisposeResponse } from '../../api/dispose/types'
const 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