|
@@ -44,12 +44,7 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
|
|
|
const [coverFile, setCoverFile] = useState<File | null>(null)
|
|
const [coverFile, setCoverFile] = useState<File | null>(null)
|
|
|
const [coverPreview, setCoverPreview] = useState(place?.cover_image || '')
|
|
const [coverPreview, setCoverPreview] = useState(place?.cover_image || '')
|
|
|
const [showMapPicker, setShowMapPicker] = useState(false)
|
|
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(() => {
|
|
useEffect(() => {
|
|
|
api.get<Tag[]>('/tags').then(setTags).catch(() => {})
|
|
api.get<Tag[]>('/tags').then(setTags).catch(() => {})
|
|
@@ -110,10 +105,10 @@ export default function PlaceForm({ type, onSuccess, place }: PlaceFormProps) {
|
|
|
|
|
|
|
|
if (isEdit) {
|
|
if (isEdit) {
|
|
|
await api.patch(`/places/${place.id}`, body)
|
|
await api.patch(`/places/${place.id}`, body)
|
|
|
- showToast('Сохранено')
|
|
|
|
|
|
|
+ if (onSuccess) onSuccess()
|
|
|
} else {
|
|
} else {
|
|
|
await api.post('/places', body)
|
|
await api.post('/places', body)
|
|
|
- showToast(status === 'draft' ? 'Черновик сохранён' : 'Место отправлено на модерацию')
|
|
|
|
|
|
|
+ setSaved(status === 'draft' ? 'draft' : 'submitted')
|
|
|
}
|
|
}
|
|
|
} catch (err: any) {
|
|
} catch (err: any) {
|
|
|
setError(err.message || 'Ошибка при создании')
|
|
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 (
|
|
return (
|
|
|
<form onSubmit={handleSubmit} className="mx-auto max-w-2xl space-y-6 p-6">
|
|
<form onSubmit={handleSubmit} className="mx-auto max-w-2xl space-y-6 p-6">
|
|
|
<h1 className="text-2xl font-bold text-white">
|
|
<h1 className="text-2xl font-bold text-white">
|
|
|
{isEdit ? 'Редактировать' : type === 'studio' ? 'Добавить студию' : 'Добавить место'}
|
|
{isEdit ? 'Редактировать' : type === 'studio' ? 'Добавить студию' : 'Добавить место'}
|
|
|
</h1>
|
|
</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>
|
|
<div>
|
|
|
<label className="mb-1 block text-sm text-white/60">Название *</label>
|
|
<label className="mb-1 block text-sm text-white/60">Название *</label>
|