diff --git a/front/src/hooks/api/useAddAnnouncement.ts b/front/src/hooks/api/useAddAnnouncement.ts index ab46a30..c4ea9d9 100644 --- a/front/src/hooks/api/useAddAnnouncement.ts +++ b/front/src/hooks/api/useAddAnnouncement.ts @@ -2,8 +2,8 @@ import { useSendWithButton } from '..' import { composePutAnnouncementURL, processPutAnnouncement } from '../../api/putAnnouncement' import { isPutAnnouncementResponse } from '../../api/putAnnouncement/types' -const useAddAnnouncement = () => ( - useSendWithButton( +function useAddAnnouncement() { + const { doSend, button } = useSendWithButton( 'Опубликовать', 'Опубликовано', true, @@ -13,6 +13,14 @@ const useAddAnnouncement = () => ( isPutAnnouncementResponse, processPutAnnouncement ) -) + + function handleAdd(formData: FormData) { + void doSend({}, { + body: formData + }) + } + + return { handleAdd, addButton: button } +} export default useAddAnnouncement diff --git a/front/src/hooks/api/useBook.ts b/front/src/hooks/api/useBook.ts index 5a1310b..e427e9b 100644 --- a/front/src/hooks/api/useBook.ts +++ b/front/src/hooks/api/useBook.ts @@ -25,7 +25,7 @@ function useBook() { ) const handleBook = useCallback((id: number) => { - void doSend({ + void doSend({}, { body: JSON.stringify({ id }), diff --git a/front/src/hooks/api/useRemoveAnnouncement.ts b/front/src/hooks/api/useRemoveAnnouncement.ts index f24ca00..ca8271f 100644 --- a/front/src/hooks/api/useRemoveAnnouncement.ts +++ b/front/src/hooks/api/useRemoveAnnouncement.ts @@ -16,7 +16,7 @@ const useRemoveAnnouncement = (close: () => void) => { ) const doSendWithClose = useCallback(async (id: number) => { - await doSend({ + await doSend({}, { body: JSON.stringify({ id }) diff --git a/front/src/hooks/useSendWithButton.ts b/front/src/hooks/useSendWithButton.ts index 5115422..300356d 100644 --- a/front/src/hooks/useSendWithButton.ts +++ b/front/src/hooks/useSendWithButton.ts @@ -12,11 +12,10 @@ function useSendWithButton>( const { update, ...button } = useSendButtonCaption(initial, loading, error, result, singular) - const doSendWithButton = useCallback(async (params: Parameters[1]) => { - const data = await doSend({}, params) + const doSendWithButton = useCallback(async (...args: Parameters) => { + const data = await doSend(...args) update(data) - }, [doSend, update]) return { doSend: doSendWithButton, button } diff --git a/front/src/pages/AddPage.tsx b/front/src/pages/AddPage.tsx index ac4c292..eaa8195 100644 --- a/front/src/pages/AddPage.tsx +++ b/front/src/pages/AddPage.tsx @@ -31,7 +31,7 @@ function AddPage() { const address = useOsmAddresses(addressPosition) - const { doSend, button } = useAddAnnouncement() + const { handleAdd, addButton } = useAddAnnouncement() const handleSubmit: FormEventHandler = (event) => { event.preventDefault() @@ -44,7 +44,7 @@ function AddPage() { formData.append('address', address.data || '') // if address.error formData.set('bestBy', new Date((formData.get('bestBy') as number | null) || 0).getTime().toString()) - void doSend(formData) + handleAdd(formData) } return ( @@ -176,7 +176,7 @@ function AddPage() { )} -