Explorar el Código

replace toast with success screen after place save

Form is replaced by success message (draft saved / submitted for moderation)
with a link to add another.
neyrogovnarik hace 1 mes
padre
commit
21a2f369aa
Se han modificado 1 ficheros con 17 adiciones y 10 borrados
  1. 17 10
      frontend/src/components/PlaceForm.tsx

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

@@ -44,12 +44,7 @@ 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)
-  }
+  const [saved, setSaved] = useState<'draft' | 'submitted' | null>(null)
 
   useEffect(() => {
     api.get<Tag[]>('/tags').then(setTags).catch(() => {})
@@ -110,10 +105,10 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
 
       if (isEdit) {
         await api.patch(`/places/${place.id}`, body)
-        showToast('Сохранено')
+        if (onSuccess) onSuccess()
       } else {
         await api.post('/places', body)
-        showToast(status === 'draft' ? 'Черновик сохранён' : 'Место отправлено на модерацию')
+        setSaved(status === 'draft' ? 'draft' : 'submitted')
       }
     } catch (err: any) {
       setError(err.message || 'Ошибка при создании')
@@ -137,14 +132,26 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
     )
   }
 
+  if (saved) {
+    return (
+      <div className="mx-auto max-w-2xl space-y-4 p-6 text-center">
+        <p className="text-lg font-medium text-green-400">
+          {saved === 'draft' ? 'Черновик сохранён' : 'Место отправлено на модерацию'}
+        </p>
+        <a href={type === 'studio' ? '/studios/add' : '/places/add'}
+          className="inline-block rounded-lg bg-green-600 px-6 py-2 text-white hover:bg-green-500 transition"
+        >Добавить ещё</a>
+      </div>
+    )
+  }
+
   return (
     <form onSubmit={handleSubmit} className="mx-auto max-w-2xl space-y-6 p-6">
       <h1 className="text-2xl font-bold text-white">
         {isEdit ? 'Редактировать' : type === 'studio' ? 'Добавить студию' : 'Добавить место'}
       </h1>
 
-      {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>}
+      {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>