forked from polka_billy/porridger
Added announcement adding page
This commit is contained in:
31
front/src/hooks/api/useAddAnnouncement.js
Normal file
31
front/src/hooks/api/useAddAnnouncement.js
Normal file
@ -0,0 +1,31 @@
|
||||
import { useState } from "react"
|
||||
import { API_URL } from "../../config"
|
||||
|
||||
const useAddAnnouncement = () => {
|
||||
const [status, setStatus] = useState("Опубликовать")
|
||||
|
||||
const doAdd = async (formData) => {
|
||||
setStatus(true)
|
||||
try {
|
||||
const res = await fetch(API_URL + "/announcement", {
|
||||
method: 'PUT',
|
||||
body: formData,
|
||||
})
|
||||
|
||||
const data = await res.json()
|
||||
|
||||
if (!data.Answer) {
|
||||
throw new Error("Не удалось опубликовать объявление")
|
||||
}
|
||||
setStatus("Опубликовано")
|
||||
|
||||
} catch (err) {
|
||||
setStatus(err.message ?? err)
|
||||
setTimeout(() => setStatus("Опубликовать"), 10000)
|
||||
}
|
||||
}
|
||||
|
||||
return {doAdd, status}
|
||||
}
|
||||
|
||||
export default useAddAnnouncement
|
12
front/src/hooks/api/useTrashboxes.js
Normal file
12
front/src/hooks/api/useTrashboxes.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { API_URL } from "../../config"
|
||||
import useFetch from "./useFetch"
|
||||
|
||||
const useTrashboxes = (position) => {
|
||||
return useFetch(
|
||||
API_URL + "/trashbox?" + new URLSearchParams({ lat: position.lat, lng: position.lng }),
|
||||
undefined,
|
||||
[]
|
||||
)
|
||||
}
|
||||
|
||||
export default useTrashboxes
|
Reference in New Issue
Block a user