Added redirect to home on successfull ann addition

This commit is contained in:
Dmitriy Shishkov 2023-07-29 18:49:02 +03:00
parent cf81e3d817
commit 8b6010f453
Signed by: dm1sh
GPG Key ID: 027994B0AA357688

View File

@ -1,9 +1,10 @@
import { CSSProperties, FormEventHandler, useState } from 'react' import { CSSProperties, FormEventHandler, useEffect, useState } from 'react'
import { Form, Button, Card } from 'react-bootstrap' import { Form, Button } from 'react-bootstrap'
import { MapContainer, TileLayer } from 'react-leaflet' import { MapContainer, TileLayer } from 'react-leaflet'
import { latLng } from 'leaflet' import { latLng } from 'leaflet'
import { useNavigate } from 'react-router-dom'
import { BackHeader, ClickHandler, LocationMarker, TrashboxMarkers } from '../components' import { ClickHandler, LocationMarker, TrashboxMarkers } from '../components'
import { useAddAnnouncement, useTrashboxes } from '../hooks/api' import { useAddAnnouncement, useTrashboxes } from '../hooks/api'
import { categories, categoryNames } from '../assets/category' import { categories, categoryNames } from '../assets/category'
import { stations, lines, lineNames } from '../assets/metro' import { stations, lines, lineNames } from '../assets/metro'
@ -28,6 +29,8 @@ function AddPage() {
const { handleAdd, addButton } = useAddAnnouncement() const { handleAdd, addButton } = useAddAnnouncement()
const navigate = useNavigate()
const handleSubmit: FormEventHandler<HTMLFormElement> = (event) => { const handleSubmit: FormEventHandler<HTMLFormElement> = (event) => {
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -42,6 +45,12 @@ function AddPage() {
handleAdd(formData) handleAdd(formData)
} }
useEffect(() => {
if (addButton.children === 'Опубликовано') {
navigate('/')
}
}, [addButton.children, navigate])
return ( return (
<CardLayout text='Опубликовать объявление'> <CardLayout text='Опубликовать объявление'>
<Form onSubmit={handleSubmit}> <Form onSubmit={handleSubmit}>