Explorar el Código

add toast notifications for place save actions

- Place submitted for moderation → 'Место отправлено на модерацию'
- Draft saved → 'Черновик сохранён'
- Both auto-dismiss after 3 seconds
neyrogovnarik hace 1 mes
padre
commit
5603f76e7e
Se han modificado 1 ficheros con 10 adiciones y 4 borrados
  1. 10 4
      frontend/src/components/PlaceForm.tsx

+ 10 - 4
frontend/src/components/PlaceForm.tsx

@@ -1,7 +1,6 @@
 'use client'
 
 import { useState, useEffect } from 'react'
-import { useRouter } from 'next/navigation'
 import dynamic from 'next/dynamic'
 import { api } from '@/lib/api'
 import type { Tag, Feature } from '@/types'
@@ -26,7 +25,6 @@ interface PlaceFormProps {
  * @param type - Тип объекта: 'place' — место, 'studio' — студия
  */
 export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
-  const router = useRouter()
   const isEdit = !!place
   const [tags, setTags] = useState<Tag[]>([])
   const [features, setFeatures] = useState<Feature[]>([])
@@ -46,6 +44,12 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
   const [coverFile, setCoverFile] = useState<File | null>(null)
   const [coverPreview, setCoverPreview] = useState(place?.cover_image || '')
   const [showMapPicker, setShowMapPicker] = useState(false)
+  const [toast, setToast] = useState('')
+
+  const showToast = (msg: string) => {
+    setToast(msg)
+    setTimeout(() => setToast(''), 3000)
+  }
 
   useEffect(() => {
     api.get<Tag[]>('/tags').then(setTags).catch(() => {})
@@ -106,10 +110,11 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
 
       if (isEdit) {
         await api.patch(`/places/${place.id}`, body)
+        showToast('Сохранено')
       } else {
         await api.post('/places', body)
+        showToast(status === 'draft' ? 'Черновик сохранён' : 'Место отправлено на модерацию')
       }
-      if (onSuccess) { onSuccess() } else { router.push('/') }
     } catch (err: any) {
       setError(err.message || 'Ошибка при создании')
     } finally {
@@ -138,7 +143,8 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
         {isEdit ? 'Редактировать' : type === 'studio' ? 'Добавить студию' : 'Добавить место'}
       </h1>
 
-      {error && <p className="rounded-lg bg-red-500/10 p-3 text-sm text-red-400">{error}</p>}
+      {toast && <p className="rounded-lg bg-green-500/15 px-4 py-3 text-sm text-green-400 text-center font-medium">{toast}</p>}
+      {!toast && error && <p className="rounded-lg bg-red-500/10 p-3 text-sm text-red-400">{error}</p>}
 
       <div>
         <label className="mb-1 block text-sm text-white/60">Название *</label>