forked from polka_billy/porridger
Converted put(api/announcement) to use useSend
Added useSendButtonCaption hook Related to #19
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
import { CSSProperties, FormEventHandler, useEffect, useState } from 'react'
|
||||
import { CSSProperties, FormEventHandler, useState } from 'react'
|
||||
import { Form, Button, Card } from 'react-bootstrap'
|
||||
import { MapContainer, TileLayer } from 'react-leaflet'
|
||||
import { latLng } from 'leaflet'
|
||||
|
||||
import { ClickHandler, LocationMarker, TrashboxMarkers } from '../components'
|
||||
import { useAddAnnouncement, useTrashboxes } from '../hooks/api'
|
||||
import { handleHTTPErrors } from '../utils'
|
||||
import { categories, categoryNames } from '../assets/category'
|
||||
import { stations, lines, lineNames } from '../assets/metro'
|
||||
import { fallbackError, gotError } from '../hooks/useFetch'
|
||||
@ -32,25 +31,7 @@ function AddPage() {
|
||||
|
||||
const address = useOsmAddresses(addressPosition)
|
||||
|
||||
useEffect(() => {
|
||||
if (!gotError(address))
|
||||
void (async () => {
|
||||
try {
|
||||
const res = await fetch(location.protocol + '//nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(address.data))
|
||||
|
||||
handleHTTPErrors(res)
|
||||
|
||||
const fetchData: unknown = await res.json()
|
||||
|
||||
console.log('f', fetchData)
|
||||
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
})()
|
||||
}, [address])
|
||||
|
||||
const { doAdd, status } = useAddAnnouncement()
|
||||
const { doSend, button } = useAddAnnouncement()
|
||||
|
||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (event) => {
|
||||
event.preventDefault()
|
||||
@ -63,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 doAdd(formData)
|
||||
void doSend(formData)
|
||||
}
|
||||
|
||||
return (
|
||||
@ -151,7 +132,7 @@ function AddPage() {
|
||||
</Form.Select>
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className='mb-3' controlId='password'>
|
||||
<Form.Group className='mb-3' controlId='trashbox'>
|
||||
<Form.Label>Пункт сбора мусора</Form.Label>
|
||||
<div className='mb-3'>
|
||||
{trashboxes.loading
|
||||
@ -195,9 +176,7 @@ function AddPage() {
|
||||
)}
|
||||
</Form.Group>
|
||||
|
||||
<Button variant='success' type='submit'>
|
||||
{status}
|
||||
</Button>
|
||||
<Button variant='success' type='submit' {...button} />
|
||||
</Form>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
|
Reference in New Issue
Block a user