Added announcement adding page

This commit is contained in:
2023-05-17 10:50:06 +03:00
parent 811cde6f30
commit 929dd8af36
5 changed files with 289 additions and 2 deletions

View 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

View 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