From 8b6010f453107f0d48fc98ec823f10869b986224 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 29 Jul 2023 18:49:02 +0300 Subject: [PATCH] Added redirect to home on successfull ann addition --- front/src/pages/AddPage.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/front/src/pages/AddPage.tsx b/front/src/pages/AddPage.tsx index b653b91..28159c2 100644 --- a/front/src/pages/AddPage.tsx +++ b/front/src/pages/AddPage.tsx @@ -1,9 +1,10 @@ -import { CSSProperties, FormEventHandler, useState } from 'react' -import { Form, Button, Card } from 'react-bootstrap' +import { CSSProperties, FormEventHandler, useEffect, useState } from 'react' +import { Form, Button } from 'react-bootstrap' import { MapContainer, TileLayer } from 'react-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 { categories, categoryNames } from '../assets/category' import { stations, lines, lineNames } from '../assets/metro' @@ -28,6 +29,8 @@ function AddPage() { const { handleAdd, addButton } = useAddAnnouncement() + const navigate = useNavigate() + const handleSubmit: FormEventHandler = (event) => { event.preventDefault() event.stopPropagation() @@ -42,6 +45,12 @@ function AddPage() { handleAdd(formData) } + useEffect(() => { + if (addButton.children === 'Опубликовано') { + navigate('/') + } + }, [addButton.children, navigate]) + return (