fix: resolve ts errors for build and cleanup widget partners action
This commit is contained in:
@@ -1,110 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { saveWidgetPartnerAction } from '@/app/actions'
|
||||
|
||||
export default function WidgetPartnerForm({ initialData }: { initialData?: any }) {
|
||||
const router = useRouter()
|
||||
const [isPending, setIsPending] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
||||
e.preventDefault()
|
||||
setIsPending(true)
|
||||
setError(null)
|
||||
|
||||
const formData = new FormData(e.currentTarget)
|
||||
if (initialData?.id) formData.append('id', initialData.id)
|
||||
|
||||
try {
|
||||
const res = await saveWidgetPartnerAction(formData)
|
||||
if (res?.error) {
|
||||
setError(res.error)
|
||||
} else {
|
||||
router.push('/tr/admin/widget-partners')
|
||||
router.refresh()
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Bir hata oluştu')
|
||||
} finally {
|
||||
setIsPending(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="bg-paper p-8 rounded-3xl border border-pine/10 shadow-sm space-y-6">
|
||||
{error && (
|
||||
<div className="bg-red-50 text-red-500 p-4 rounded-xl text-sm">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-mono uppercase tracking-wider text-shutter mb-2">Partner Adı *</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
defaultValue={initialData?.name}
|
||||
required
|
||||
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-turquoise/20 outline-none transition"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-mono uppercase tracking-wider text-shutter mb-2">Logo URL *</label>
|
||||
<input
|
||||
type="text"
|
||||
name="logoUrl"
|
||||
defaultValue={initialData?.logoUrl}
|
||||
required
|
||||
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-turquoise/20 outline-none transition"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-mono uppercase tracking-wider text-shutter mb-2">Web Sitesi *</label>
|
||||
<input
|
||||
type="text"
|
||||
name="websiteUrl"
|
||||
defaultValue={initialData?.websiteUrl}
|
||||
required
|
||||
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-turquoise/20 outline-none transition"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-mono uppercase tracking-wider text-shutter mb-2">Widget Tipi *</label>
|
||||
<select
|
||||
name="widgetType"
|
||||
defaultValue={initialData?.widgetType || 'listing'}
|
||||
required
|
||||
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-turquoise/20 outline-none transition"
|
||||
>
|
||||
<option value="listing">Listing</option>
|
||||
<option value="collection">Collection</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="pt-6 border-t border-pine/10 flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => router.back()}
|
||||
className="px-6 py-3 rounded-xl border border-pine/10 text-pine font-bold text-sm hover:bg-stone transition"
|
||||
>
|
||||
İptal
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isPending}
|
||||
className="px-6 py-3 rounded-xl bg-turquoise text-white font-bold text-sm hover:bg-turquoise/90 transition flex items-center gap-2"
|
||||
>
|
||||
{isPending && <Loader2 className="w-4 h-4 animate-spin" />}
|
||||
Kaydet
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { getTranslations } from 'next-intl/server'
|
||||
import { mockDb } from '@/lib/mockDb'
|
||||
import { notFound } from 'next/navigation'
|
||||
import WidgetPartnerForm from './WidgetPartnerForm'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
interface Props {
|
||||
params: Promise<{ id: string; locale: string }>
|
||||
}
|
||||
|
||||
export default async function EditWidgetPartnerPage({ params }: Props) {
|
||||
const { id } = await params
|
||||
const isNew = id === 'new'
|
||||
|
||||
let partner = null
|
||||
if (!isNew) {
|
||||
partner = (await mockDb.getWidgetPartners()).find(p => p.id === id)
|
||||
if (!partner) notFound()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl mx-auto py-10 space-y-6">
|
||||
<div className="flex flex-col gap-1 mb-8">
|
||||
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">
|
||||
{isNew ? 'yeni partner ekle' : 'partneri düzenle'}
|
||||
</h2>
|
||||
<p className="text-ink/65 text-xs font-medium">
|
||||
Widget partneri bilgilerini buradan {isNew ? 'ekleyebilirsiniz' : 'düzenleyebilirsiniz'}.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<WidgetPartnerForm initialData={partner} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+3
-21
@@ -96,6 +96,7 @@ export async function approveSubmissionAction(id: string) {
|
||||
rating: 5.0,
|
||||
isLocalApproved: false,
|
||||
isFeatured: false,
|
||||
hasWidgetInstalled: false,
|
||||
images: submission.imageUrl ? [submission.imageUrl] : []
|
||||
})
|
||||
|
||||
@@ -237,7 +238,8 @@ export async function createOrUpdateListingAction(formData: FormData) {
|
||||
latitude,
|
||||
longitude,
|
||||
openingHours,
|
||||
images
|
||||
images,
|
||||
hasWidgetInstalled: false
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -643,23 +645,3 @@ export async function searchListingsAction(query: string) {
|
||||
}))
|
||||
}
|
||||
|
||||
export async function saveWidgetPartnerAction(formData: FormData) {
|
||||
const id = formData.get('id') as string | null
|
||||
const name = formData.get('name') as string
|
||||
const logoUrl = formData.get('logoUrl') as string
|
||||
const websiteUrl = formData.get('websiteUrl') as string
|
||||
const widgetType = formData.get('widgetType') as string
|
||||
|
||||
if (!name || !logoUrl || !websiteUrl) {
|
||||
return { error: 'Lütfen zorunlu alanları doldurun.' }
|
||||
}
|
||||
|
||||
if (id) {
|
||||
await mockDb.updateWidgetPartner(id, { name, logoUrl, websiteUrl, widgetType })
|
||||
} else {
|
||||
await mockDb.createWidgetPartner({ name, logoUrl, websiteUrl, widgetType })
|
||||
}
|
||||
|
||||
revalidatePath('/admin/widget-partners')
|
||||
return { success: true, error: undefined }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user