forked from polka_billy/porridger
Merge pull request 'asynchronous-porridger' (#49) from asynchronous-porridger into main
Reviewed-on: dm1sh/porridger#49
This commit is contained in:
@ -6,7 +6,7 @@ const composePutAnnouncementURL = () => (
|
||||
)
|
||||
|
||||
const processPutAnnouncement = (data: PutAnnouncementResponse): PutAnnouncement => {
|
||||
return data.Answer
|
||||
return data.Success
|
||||
}
|
||||
|
||||
export { composePutAnnouncementURL, processPutAnnouncement }
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { isObject } from '../../utils/types'
|
||||
|
||||
type PutAnnouncementResponse = {
|
||||
Answer: boolean,
|
||||
Success: boolean,
|
||||
}
|
||||
|
||||
const isPutAnnouncementResponse = (obj: unknown): obj is PutAnnouncementResponse => (
|
||||
isObject(obj, {
|
||||
'Answer': 'boolean',
|
||||
'Success': 'boolean',
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -6,11 +6,11 @@ const composeRemoveAnnouncementURL = () => (
|
||||
)
|
||||
|
||||
function processRemoveAnnouncement(data: RemoveAnnouncementResponse): RemoveAnnouncement {
|
||||
if (!data.Answer) {
|
||||
if (!data.Success) {
|
||||
throw new Error('Не удалось закрыть объявление')
|
||||
}
|
||||
|
||||
return data.Answer
|
||||
return data.Success
|
||||
}
|
||||
|
||||
export { composeRemoveAnnouncementURL, processRemoveAnnouncement }
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { isObject } from '../../utils/types'
|
||||
|
||||
type RemoveAnnouncementResponse = {
|
||||
Answer: boolean,
|
||||
Success: boolean,
|
||||
}
|
||||
|
||||
const isRemoveAnnouncementResponse = (obj: unknown): obj is RemoveAnnouncementResponse => (
|
||||
isObject(obj, {
|
||||
'Answer': 'boolean',
|
||||
'Success': 'boolean',
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -14,8 +14,8 @@ function useAddAnnouncement() {
|
||||
processPutAnnouncement
|
||||
)
|
||||
|
||||
function handleAdd(formData: FormData) {
|
||||
void doSend({}, {
|
||||
async function handleAdd(formData: FormData) {
|
||||
await doSend({}, {
|
||||
body: formData,
|
||||
})
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ function useBook() {
|
||||
processBook,
|
||||
)
|
||||
|
||||
const handleBook = useCallback((id: number) => {
|
||||
void doSend({}, {
|
||||
const handleBook = useCallback(async (id: number) => {
|
||||
await doSend({}, {
|
||||
body: JSON.stringify({
|
||||
id,
|
||||
}),
|
||||
|
@ -12,7 +12,7 @@ function useSendButtonCaption(
|
||||
const [title, setTitle] = useState(initial)
|
||||
|
||||
const update = useCallback(<T extends NonNullable<unknown>>(data: T | null | undefined) => {
|
||||
if (data !== undefined) { // not loading
|
||||
if (data !== undefined && data !== null) { // not loading or error
|
||||
setCaption(result)
|
||||
setTitle('Отправить ещё раз')
|
||||
|
||||
|
Reference in New Issue
Block a user