|
|
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'
|
|
|
import { useRouter } from 'next/navigation'
|
|
|
import { api } from '@/lib/api'
|
|
|
import type { Tag, Feature } from '@/types'
|
|
|
+import MapPicker from './MapPicker'
|
|
|
|
|
|
/** Пропсы компонента формы создания места/студии */
|
|
|
interface PlaceFormProps {
|
|
|
@@ -39,6 +40,7 @@ export default function PlaceForm({ type, onSuccess }: PlaceFormProps) {
|
|
|
const [minHours, setMinHours] = useState('1')
|
|
|
const [coverFile, setCoverFile] = useState<File | null>(null)
|
|
|
const [coverPreview, setCoverPreview] = useState('')
|
|
|
+ const [showMapPicker, setShowMapPicker] = useState(false)
|
|
|
|
|
|
useEffect(() => {
|
|
|
api.get<Tag[]>('/tags').then(setTags).catch(() => {})
|
|
|
@@ -54,6 +56,13 @@ export default function PlaceForm({ type, onSuccess }: PlaceFormProps) {
|
|
|
}
|
|
|
}, [coverPreview])
|
|
|
|
|
|
+ const handleMapPick = (pickLat: number, pickLng: number, pickAddress?: string) => {
|
|
|
+ setLat(pickLat.toFixed(6))
|
|
|
+ setLng(pickLng.toFixed(6))
|
|
|
+ if (pickAddress) setAddress(pickAddress)
|
|
|
+ setShowMapPicker(false)
|
|
|
+ }
|
|
|
+
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
|
e.preventDefault()
|
|
|
setLoading(true)
|
|
|
@@ -153,7 +162,16 @@ export default function PlaceForm({ type, onSuccess }: PlaceFormProps) {
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
|
- <div className="grid grid-cols-2 gap-4">
|
|
|
+ <div className="grid grid-cols-3 gap-4">
|
|
|
+ <div className="flex items-end">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => setShowMapPicker(true)}
|
|
|
+ className="w-full rounded-lg border border-white/10 bg-white/5 px-2 py-3 text-sm text-white/80 hover:bg-white/10 transition text-center leading-tight"
|
|
|
+ >
|
|
|
+ Указать<br />на карте
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
<div>
|
|
|
<label className="mb-1 block text-sm text-white/60">Широта</label>
|
|
|
<input
|
|
|
@@ -161,7 +179,7 @@ export default function PlaceForm({ type, onSuccess }: PlaceFormProps) {
|
|
|
step="any"
|
|
|
value={lat}
|
|
|
onChange={(e) => setLat(e.target.value)}
|
|
|
- className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-3 text-white outline-none focus:border-green-500"
|
|
|
+ className="w-full rounded-lg border border-white/10 bg-white/5 px-3 py-3 text-white outline-none focus:border-green-500"
|
|
|
/>
|
|
|
</div>
|
|
|
<div>
|
|
|
@@ -171,7 +189,7 @@ export default function PlaceForm({ type, onSuccess }: PlaceFormProps) {
|
|
|
step="any"
|
|
|
value={lng}
|
|
|
onChange={(e) => setLng(e.target.value)}
|
|
|
- className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-3 text-white outline-none focus:border-green-500"
|
|
|
+ className="w-full rounded-lg border border-white/10 bg-white/5 px-3 py-3 text-white outline-none focus:border-green-500"
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -279,6 +297,8 @@ export default function PlaceForm({ type, onSuccess }: PlaceFormProps) {
|
|
|
>
|
|
|
{loading ? 'Сохранение...' : `Создать ${type === 'studio' ? 'студию' : 'место'}`}
|
|
|
</button>
|
|
|
+
|
|
|
+ {showMapPicker && <MapPicker onSelect={handleMapPick} onClose={() => setShowMapPicker(false)} />}
|
|
|
</form>
|
|
|
)
|
|
|
}
|