Update application features and add scripts (core changes)
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { signOut } from 'next-auth/react'
|
||||
import { Menu, LogOut, Settings, User } from 'lucide-react'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { ADMIN_NAVIGATION } from './AdminSidebar'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuGroup,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
|
||||
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet'
|
||||
|
||||
interface AdminHeaderProps {
|
||||
userEmail?: string | null
|
||||
userName?: string | null
|
||||
}
|
||||
|
||||
export function AdminHeader({ userEmail, userName }: AdminHeaderProps) {
|
||||
const pathname = usePathname()
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const initials = userName
|
||||
? userName.slice(0, 2).toUpperCase()
|
||||
: userEmail?.slice(0, 2).toUpperCase() || 'AD'
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-40 flex h-16 w-full items-center justify-between border-b border-gray-200 dark:border-gray-800 bg-white/80 dark:bg-gray-950/80 px-4 backdrop-blur md:px-6">
|
||||
|
||||
{/* Mobile Menu */}
|
||||
<div className="flex items-center md:hidden">
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
<SheetTrigger render={<Button variant="ghost" size="icon" className="-ml-2 mr-2" />}>
|
||||
<Menu className="h-5 w-5" />
|
||||
<span className="sr-only">Menüyü aç</span>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="left" className="w-72">
|
||||
<SheetHeader className="border-b pb-4 mb-4">
|
||||
<SheetTitle className="text-left text-xl bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-indigo-600">
|
||||
Sitar Admin
|
||||
</SheetTitle>
|
||||
</SheetHeader>
|
||||
<nav className="flex flex-col space-y-1">
|
||||
{ADMIN_NAVIGATION.map((item) => {
|
||||
const isActive = pathname === item.href || (item.href !== '/admin' && pathname.startsWith(item.href))
|
||||
return (
|
||||
<Link
|
||||
key={item.name}
|
||||
href={item.href}
|
||||
onClick={() => setOpen(false)}
|
||||
className={`
|
||||
flex items-center px-3 py-2.5 text-sm font-medium rounded-lg transition-colors
|
||||
${isActive
|
||||
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-400'
|
||||
: 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800'}
|
||||
`}
|
||||
>
|
||||
<item.icon className={`mr-3 h-5 w-5 ${isActive ? 'text-blue-700 dark:text-blue-400' : 'text-gray-400'}`} />
|
||||
{item.name}
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
<span className="text-lg font-bold text-gray-900 dark:text-white sm:hidden">Admin</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-1 items-center justify-end space-x-4">
|
||||
{/* User Dropdown */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger render={<Button variant="ghost" className="relative h-9 w-9 rounded-full" />}>
|
||||
<Avatar className="h-9 w-9 border border-gray-200 dark:border-gray-800">
|
||||
<AvatarFallback className="bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-200">
|
||||
{initials}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56" align="end">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel className="font-normal">
|
||||
<div className="flex flex-col space-y-1">
|
||||
<p className="text-sm font-medium leading-none text-gray-900 dark:text-white">
|
||||
{userName || 'Admin'}
|
||||
</p>
|
||||
<p className="text-xs leading-none text-gray-500 dark:text-gray-400">
|
||||
{userEmail}
|
||||
</p>
|
||||
</div>
|
||||
</DropdownMenuLabel>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem render={<Link href="/admin/settings" />}>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
<span>Ayarlar</span>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem render={<Link href="/" target="_blank" />}>
|
||||
<User className="mr-2 h-4 w-4" />
|
||||
<span>Siteye Git</span>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600 dark:text-red-400 cursor-pointer focus:bg-red-50 dark:focus:bg-red-950/30 focus:text-red-600"
|
||||
onClick={() => signOut({ callbackUrl: '/' })}
|
||||
>
|
||||
<LogOut className="mr-2 h-4 w-4" />
|
||||
<span>Çıkış Yap</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import { LayoutDashboard, Users, Settings, BedDouble } from 'lucide-react'
|
||||
|
||||
export const ADMIN_NAVIGATION = [
|
||||
{ name: 'Dashboard', href: '/admin', icon: LayoutDashboard },
|
||||
{ name: 'Odalar', href: '/admin/rooms', icon: BedDouble },
|
||||
{ name: 'Kullanıcılar', href: '/admin/users', icon: Users },
|
||||
{ name: 'Ayarlar', href: '/admin/settings', icon: Settings },
|
||||
]
|
||||
|
||||
export function AdminSidebar() {
|
||||
const pathname = usePathname()
|
||||
|
||||
return (
|
||||
<div className="hidden border-r border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-950 md:flex md:flex-col md:w-64 flex-shrink-0">
|
||||
<div className="flex h-16 items-center border-b border-gray-200 dark:border-gray-800 px-6">
|
||||
<h1 className="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-indigo-600 dark:from-blue-400 dark:to-indigo-400">
|
||||
Sitar Admin
|
||||
</h1>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto px-4 py-6">
|
||||
<nav className="flex flex-col space-y-1">
|
||||
{ADMIN_NAVIGATION.map((item) => {
|
||||
const isActive = pathname === item.href || (item.href !== '/admin' && pathname.startsWith(item.href))
|
||||
return (
|
||||
<Link
|
||||
key={item.name}
|
||||
href={item.href}
|
||||
className={`
|
||||
group flex items-center px-3 py-2.5 text-sm font-medium rounded-lg transition-all duration-200
|
||||
${isActive
|
||||
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-400'
|
||||
: 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-gray-900 dark:hover:text-white'}
|
||||
`}
|
||||
>
|
||||
<item.icon
|
||||
className={`mr-3 h-5 w-5 flex-shrink-0 transition-colors duration-200 ${isActive ? 'text-blue-700 dark:text-blue-400' : 'text-gray-400 group-hover:text-gray-600 dark:group-hover:text-gray-300'}`}
|
||||
/>
|
||||
{item.name}
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useRef } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { uploadImageAction } from '@/lib/actions/upload'
|
||||
import { ImagePlus, X, UploadCloud, Loader2, CheckCircle2, AlertCircle } from 'lucide-react'
|
||||
|
||||
interface ImageUploadModalProps {
|
||||
onUploadComplete: (urls: string[]) => void
|
||||
multiple?: boolean
|
||||
triggerText?: string
|
||||
folderName?: string
|
||||
}
|
||||
|
||||
export function ImageUploadModal({
|
||||
onUploadComplete,
|
||||
multiple = false,
|
||||
triggerText = "Resim Yükle",
|
||||
folderName = "starapart"
|
||||
}: ImageUploadModalProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([])
|
||||
const [previews, setPreviews] = useState<string[]>([])
|
||||
const [isUploading, setIsUploading] = useState(false)
|
||||
const [progress, setProgress] = useState(0) // 0 to total files
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const resetState = () => {
|
||||
setSelectedFiles([])
|
||||
previews.forEach(p => URL.revokeObjectURL(p))
|
||||
setPreviews([])
|
||||
setIsUploading(false)
|
||||
setProgress(0)
|
||||
setError(null)
|
||||
}
|
||||
|
||||
const handleOpenChange = (newOpen: boolean) => {
|
||||
if (isUploading) return // Prevent closing while uploading
|
||||
setOpen(newOpen)
|
||||
if (!newOpen) {
|
||||
resetState()
|
||||
}
|
||||
}
|
||||
|
||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (!e.target.files?.length) return
|
||||
|
||||
const files = Array.from(e.target.files)
|
||||
const newFiles = multiple ? [...selectedFiles, ...files] : [files[0]]
|
||||
|
||||
setSelectedFiles(newFiles)
|
||||
|
||||
// Create preview URLs
|
||||
const newPreviews = newFiles.map(file => URL.createObjectURL(file))
|
||||
if (!multiple) {
|
||||
previews.forEach(p => URL.revokeObjectURL(p)) // cleanup old previews
|
||||
setPreviews(newPreviews)
|
||||
} else {
|
||||
setPreviews([...previews, ...newPreviews])
|
||||
}
|
||||
|
||||
setError(null)
|
||||
|
||||
// Reset file input so same file can be selected again if removed
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const removeFile = (index: number) => {
|
||||
const newFiles = [...selectedFiles]
|
||||
newFiles.splice(index, 1)
|
||||
|
||||
const newPreviews = [...previews]
|
||||
URL.revokeObjectURL(newPreviews[index])
|
||||
newPreviews.splice(index, 1)
|
||||
|
||||
setSelectedFiles(newFiles)
|
||||
setPreviews(newPreviews)
|
||||
}
|
||||
|
||||
const handleUpload = async () => {
|
||||
if (!selectedFiles.length) return
|
||||
|
||||
setIsUploading(true)
|
||||
setError(null)
|
||||
setProgress(0)
|
||||
|
||||
const uploadedUrls: string[] = []
|
||||
|
||||
try {
|
||||
// Upload one by one to prevent timeout and body size limits
|
||||
for (let i = 0; i < selectedFiles.length; i++) {
|
||||
const file = selectedFiles[i]
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
fd.append('folder', folderName)
|
||||
|
||||
const res = await uploadImageAction(fd)
|
||||
if (res.success && res.url) {
|
||||
uploadedUrls.push(res.url)
|
||||
} else {
|
||||
throw new Error(res.error || `${file.name} yüklenemedi.`)
|
||||
}
|
||||
|
||||
setProgress(i + 1)
|
||||
}
|
||||
|
||||
onUploadComplete(uploadedUrls)
|
||||
setOpen(false)
|
||||
resetState()
|
||||
} catch (err: any) {
|
||||
setError(err.message || "Yükleme sırasında bir hata oluştu.")
|
||||
setIsUploading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||
<DialogTrigger render={
|
||||
<Button type="button" variant="outline" className="w-full h-24 border-dashed flex flex-col items-center justify-center gap-2">
|
||||
<ImagePlus className="h-6 w-6 text-gray-500" />
|
||||
<span className="text-gray-500">{triggerText}</span>
|
||||
</Button>
|
||||
} />
|
||||
|
||||
<DialogContent className="sm:max-w-[600px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Resim Yükle</DialogTitle>
|
||||
<DialogDescription>
|
||||
{multiple ? "Birden fazla resim seçip yükleyebilirsiniz." : "Odanın ana görselini seçin."}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="py-4 space-y-4">
|
||||
{!isUploading && (
|
||||
<div className="flex justify-center">
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple={multiple}
|
||||
className="hidden"
|
||||
ref={fileInputRef}
|
||||
onChange={handleFileChange}
|
||||
/>
|
||||
<Button type="button" variant="secondary" onClick={() => fileInputRef.current?.click()}>
|
||||
Bilgisayardan Seç
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-50 text-red-600 p-3 rounded-md text-sm flex items-start gap-2">
|
||||
<AlertCircle className="h-5 w-5 shrink-0" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{previews.length > 0 && (
|
||||
<div className="bg-gray-50 dark:bg-gray-900 p-4 rounded-lg border">
|
||||
<h4 className="text-sm font-medium mb-3">Seçilen Resimler ({selectedFiles.length})</h4>
|
||||
<div className="grid grid-cols-3 sm:grid-cols-4 gap-4 max-h-[300px] overflow-y-auto p-1">
|
||||
{previews.map((preview, idx) => (
|
||||
<div key={idx} className="relative group aspect-square rounded-md border bg-white overflow-hidden">
|
||||
<img src={preview} alt="preview" className="w-full h-full object-cover" />
|
||||
{!isUploading && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeFile(idx)}
|
||||
className="absolute top-1 right-1 bg-red-500 text-white rounded-full p-1 shadow-sm opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
{isUploading && idx < progress && (
|
||||
<div className="absolute inset-0 bg-white/70 flex items-center justify-center">
|
||||
<CheckCircle2 className="h-8 w-8 text-green-500" />
|
||||
</div>
|
||||
)}
|
||||
{isUploading && idx === progress && (
|
||||
<div className="absolute inset-0 bg-white/50 flex items-center justify-center">
|
||||
<Loader2 className="h-8 w-8 text-blue-500 animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isUploading && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between text-sm font-medium text-gray-500">
|
||||
<span>Yükleniyor...</span>
|
||||
<span>{progress} / {selectedFiles.length}</span>
|
||||
</div>
|
||||
<div className="h-2 w-full bg-gray-100 rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-blue-600 transition-all duration-300 ease-in-out"
|
||||
style={{ width: `${(progress / selectedFiles.length) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenChange(false)}
|
||||
disabled={isUploading}
|
||||
>
|
||||
İptal
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleUpload}
|
||||
disabled={isUploading || selectedFiles.length === 0}
|
||||
className="min-w-[120px]"
|
||||
>
|
||||
{isUploading ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
Yükleniyor...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<UploadCloud className="mr-2 h-4 w-4" />
|
||||
Yüklemeyi Başlat
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { createRoom, updateRoom, RoomInput } from '@/lib/actions/room'
|
||||
import { uploadImageAction } from '@/lib/actions/upload'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { ImageUploadModal } from '@/components/admin/ImageUploadModal'
|
||||
|
||||
interface RoomFormProps {
|
||||
initialData?: RoomInput & { id: string }
|
||||
}
|
||||
|
||||
export function RoomForm({ initialData }: RoomFormProps) {
|
||||
const router = useRouter()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const [formData, setFormData] = useState<RoomInput>(initialData || {
|
||||
slug: '',
|
||||
type: 'STUDIO_1_0',
|
||||
nameTr: '',
|
||||
nameEn: '',
|
||||
nameDe: '',
|
||||
descriptionTr: '',
|
||||
descriptionEn: '',
|
||||
descriptionDe: '',
|
||||
capacity: 2,
|
||||
price: null,
|
||||
imageUrl: '',
|
||||
images: [],
|
||||
amenities: [],
|
||||
available: true,
|
||||
featured: false,
|
||||
})
|
||||
|
||||
// Helper for comma-separated arrays
|
||||
const handleArrayChange = (field: 'images' | 'amenities', value: string) => {
|
||||
const arrayValue = value.split(',').map(s => s.trim()).filter(Boolean)
|
||||
setFormData(prev => ({ ...prev, [field]: arrayValue }))
|
||||
}
|
||||
|
||||
const handleMainImageComplete = (urls: string[]) => {
|
||||
if (urls.length > 0) {
|
||||
setFormData(prev => ({ ...prev, imageUrl: urls[0] }))
|
||||
}
|
||||
}
|
||||
|
||||
const handleGalleryComplete = (urls: string[]) => {
|
||||
if (urls.length > 0) {
|
||||
setFormData(prev => ({ ...prev, images: [...prev.images, ...urls] }))
|
||||
}
|
||||
}
|
||||
|
||||
const removeGalleryImage = (index: number) => {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
images: prev.images.filter((_, i) => i !== index)
|
||||
}))
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
let result
|
||||
if (initialData?.id) {
|
||||
result = await updateRoom(initialData.id, formData)
|
||||
} else {
|
||||
result = await createRoom(formData)
|
||||
}
|
||||
|
||||
if (result?.success) {
|
||||
router.push('/admin/rooms')
|
||||
router.refresh()
|
||||
} else {
|
||||
setError(result?.error || 'Bir hata oluştu.')
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Bir hata oluştu.')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-6 max-w-4xl bg-white dark:bg-gray-950 p-6 rounded-lg border border-gray-200 dark:border-gray-800">
|
||||
{error && (
|
||||
<div className="bg-red-50 text-red-600 p-3 rounded-md text-sm">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Oda Tipi</label>
|
||||
<select
|
||||
value={formData.type}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, type: e.target.value as any }))}
|
||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
<option value="STUDIO_1_0">Stüdyo (1+0)</option>
|
||||
<option value="SUITE_1_1">Süit (1+1)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Slug (URL)</label>
|
||||
<Input
|
||||
required
|
||||
value={formData.slug}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, slug: e.target.value }))}
|
||||
placeholder="ornek-oda-1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Ad (TR)</label>
|
||||
<Input required value={formData.nameTr} onChange={(e) => setFormData(prev => ({ ...prev, nameTr: e.target.value }))} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Ad (EN)</label>
|
||||
<Input required value={formData.nameEn} onChange={(e) => setFormData(prev => ({ ...prev, nameEn: e.target.value }))} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Ad (DE)</label>
|
||||
<Input required value={formData.nameDe} onChange={(e) => setFormData(prev => ({ ...prev, nameDe: e.target.value }))} />
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Kapasite</label>
|
||||
<Input type="number" required value={formData.capacity} onChange={(e) => setFormData(prev => ({ ...prev, capacity: parseInt(e.target.value) || 0 }))} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Fiyat (Opsiyonel)</label>
|
||||
<Input type="number" value={formData.price || ''} onChange={(e) => setFormData(prev => ({ ...prev, price: e.target.value ? parseInt(e.target.value) : null }))} />
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-medium">Açıklama (TR)</label>
|
||||
<textarea
|
||||
required
|
||||
className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
value={formData.descriptionTr}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, descriptionTr: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-medium">Açıklama (EN)</label>
|
||||
<textarea
|
||||
required
|
||||
className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
value={formData.descriptionEn}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, descriptionEn: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-medium">Açıklama (DE)</label>
|
||||
<textarea
|
||||
required
|
||||
className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
value={formData.descriptionDe}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, descriptionDe: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-medium">Ana Resim</label>
|
||||
<ImageUploadModal
|
||||
onUploadComplete={handleMainImageComplete}
|
||||
multiple={false}
|
||||
triggerText="Ana Resmi Yükle"
|
||||
folderName={`starapart/${formData.type}`}
|
||||
/>
|
||||
{formData.imageUrl && (
|
||||
<div className="mt-2">
|
||||
<img src={formData.imageUrl} alt="Ana Resim" className="h-32 object-cover rounded-md border" />
|
||||
<Input className="mt-2" value={formData.imageUrl} onChange={(e) => setFormData(prev => ({ ...prev, imageUrl: e.target.value }))} placeholder="Veya doğrudan URL girin..." />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-medium">Galeri (Diğer Resimler)</label>
|
||||
<ImageUploadModal
|
||||
onUploadComplete={handleGalleryComplete}
|
||||
multiple={true}
|
||||
triggerText="Galeri İçin Çoklu Resim Yükle"
|
||||
folderName={`starapart/${formData.type}`}
|
||||
/>
|
||||
{formData.images.length > 0 && (
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mt-4">
|
||||
{formData.images.map((url, idx) => (
|
||||
<div key={idx} className="relative group">
|
||||
<img src={url} alt={`Gallery ${idx}`} className="h-24 w-full object-cover rounded-md border" />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeGalleryImage(idx)}
|
||||
className="absolute top-1 right-1 bg-red-500 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<Input
|
||||
className="mt-2"
|
||||
value={formData.images.join(', ')}
|
||||
onChange={(e) => handleArrayChange('images', e.target.value)}
|
||||
placeholder="Veya virgülle ayırarak URL'leri girin..."
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-medium">Özellikler (Amenities - Virgülle ayırın)</label>
|
||||
<Input value={formData.amenities.join(', ')} onChange={(e) => handleArrayChange('amenities', e.target.value)} placeholder="Wifi, TV, Klima..." />
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="available"
|
||||
checked={formData.available}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, available: e.target.checked }))}
|
||||
className="h-4 w-4 rounded border-gray-300"
|
||||
/>
|
||||
<label htmlFor="available" className="text-sm font-medium cursor-pointer">Müsait mi?</label>
|
||||
</div>
|
||||
<div className="space-y-2 flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="featured"
|
||||
checked={formData.featured}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, featured: e.target.checked }))}
|
||||
className="h-4 w-4 rounded border-gray-300"
|
||||
/>
|
||||
<label htmlFor="featured" className="text-sm font-medium cursor-pointer">Öne Çıkan (Anasayfada göster)</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-4 pt-4 border-t border-gray-200 dark:border-gray-800">
|
||||
<Button type="button" variant="outline" onClick={() => router.push('/admin/rooms')} disabled={loading}>İptal</Button>
|
||||
<Button type="submit" disabled={loading}>
|
||||
{loading ? 'Kaydediliyor...' : 'Kaydet'}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user