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 }
|
||||
}
|
||||
|
||||
+29
-3
@@ -6,6 +6,8 @@ export interface Category {
|
||||
nameTr: string
|
||||
nameEn: string
|
||||
nameRu: string
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
}
|
||||
|
||||
export interface Neighborhood {
|
||||
@@ -196,9 +198,9 @@ const globalForMockDb = globalThis as unknown as {
|
||||
|
||||
if (!globalForMockDb.initialized || globalForMockDb.__version !== MOCK_DB_VERSION) {
|
||||
globalForMockDb.categories = [
|
||||
{ id: 'cat-1', slug: 'restoran', nameTr: 'Restoran', nameEn: 'Restaurant', nameRu: 'Ресторан' },
|
||||
{ id: 'cat-2', slug: 'apart', nameTr: 'Apart', nameEn: 'Apart Hotel', nameRu: 'Апарт-отель' },
|
||||
{ id: 'cat-3', slug: 'isletme', nameTr: 'İşletme & Hizmet', nameEn: 'Business & Service', nameRu: 'Бизнес и Услуги' }
|
||||
{ id: 'cat-1', slug: 'restoran', nameTr: 'Restoran', nameEn: 'Restaurant', nameRu: 'Ресторан', createdAt: new Date(), updatedAt: new Date() },
|
||||
{ id: 'cat-2', slug: 'apart', nameTr: 'Apart', nameEn: 'Apart Hotel', nameRu: 'Апарт-отель', createdAt: new Date(), updatedAt: new Date() },
|
||||
{ id: 'cat-3', slug: 'isletme', nameTr: 'İşletme & Hizmet', nameEn: 'Business & Service', nameRu: 'Бизнес и Услуги', createdAt: new Date(), updatedAt: new Date() }
|
||||
]
|
||||
|
||||
globalForMockDb.neighborhoods = [
|
||||
@@ -974,6 +976,18 @@ export const mockDb = {
|
||||
return db.businessSubmission.findMany({ orderBy: { createdAt: 'desc' } })
|
||||
},
|
||||
|
||||
async deleteSubmission(id: string) {
|
||||
if (this.isMock()) {
|
||||
const idx = globalForMockDb.submissions.findIndex(s => s.id === id)
|
||||
if (idx !== -1) {
|
||||
globalForMockDb.submissions.splice(idx, 1)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
await db.businessSubmission.delete({ where: { id } })
|
||||
},
|
||||
|
||||
async createSubmission(data: Omit<BusinessSubmission, 'id' | 'status' | 'createdAt' | 'updatedAt'>) {
|
||||
if (this.isMock()) {
|
||||
const newSub: BusinessSubmission = {
|
||||
@@ -1020,6 +1034,18 @@ export const mockDb = {
|
||||
return db.contactMessage.findMany({ orderBy: { createdAt: 'desc' } })
|
||||
},
|
||||
|
||||
async deleteMessage(id: string) {
|
||||
if (this.isMock()) {
|
||||
const idx = globalForMockDb.messages.findIndex(m => m.id === id)
|
||||
if (idx !== -1) {
|
||||
globalForMockDb.messages.splice(idx, 1)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
await db.contactMessage.delete({ where: { id } })
|
||||
},
|
||||
|
||||
async createMessage(data: Omit<ContactMessage, 'id' | 'isRead' | 'createdAt' | 'updatedAt'>) {
|
||||
if (this.isMock()) {
|
||||
const newMsg: ContactMessage = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineConfig } from '@prisma/config'
|
||||
|
||||
export default defineConfig({
|
||||
// @ts-ignore
|
||||
seed: 'tsx prisma/seed.ts'
|
||||
})
|
||||
|
||||
+4
-6
@@ -47,7 +47,7 @@ async function main() {
|
||||
console.log('Mekanlar ekleniyor...')
|
||||
const listings = await mockDb.getListings() // Default is 100 limit, mockDb returns all for seed if not paginated
|
||||
// Let's ensure we get all
|
||||
const allListings = await mockDb.getListings({ limit: 1000 })
|
||||
const allListings = await mockDb.getListings()
|
||||
for (const listing of allListings) {
|
||||
await prisma.listing.upsert({
|
||||
where: { id: listing.id },
|
||||
@@ -82,10 +82,8 @@ async function main() {
|
||||
hasWidgetInstalled: listing.hasWidgetInstalled,
|
||||
widgetSiteUrl: listing.widgetSiteUrl,
|
||||
images: {
|
||||
create: listing.images?.map(img => ({
|
||||
id: img.id,
|
||||
url: img.url,
|
||||
createdAt: img.createdAt
|
||||
create: listing.images?.map((img: any) => ({
|
||||
url: typeof img === 'string' ? img : img.url
|
||||
})) || []
|
||||
}
|
||||
},
|
||||
@@ -135,7 +133,7 @@ async function main() {
|
||||
descriptionRu: col.descriptionRu,
|
||||
coverImage: col.coverImage,
|
||||
listings: {
|
||||
connect: col.listingIds?.map(id => ({ id })) || []
|
||||
connect: (col as any).listingIds?.map((id: string) => ({ id })) || []
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user