feat: widget partner system with JS embed, isHidden toggle, category/neighborhood filters
This commit is contained in:
@@ -30,14 +30,21 @@ export default function WidgetPartnerForm({
|
||||
|
||||
const isEditing = !!partner
|
||||
|
||||
const [isHidden, setIsHidden] = useState(partner ? Boolean((partner as any).isHidden) : false)
|
||||
const [selectedNeighborhood, setSelectedNeighborhood] = useState(partner?.neighborhoodSlug || '')
|
||||
|
||||
const embedCode = partner
|
||||
? `<iframe
|
||||
src="https://marmarislocal.com/tr/widget${partner.neighborhoodSlug ? `?neighborhood=${partner.neighborhoodSlug}` : ''}"
|
||||
width="100%"
|
||||
height="600"
|
||||
style="border:none; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);"
|
||||
title="Marmaris Local Önerileri"
|
||||
></iframe>`
|
||||
? [
|
||||
'<!-- Marmaris Local Widget -->',
|
||||
'<div',
|
||||
' data-marmaris-widget',
|
||||
` data-neighborhood="${selectedNeighborhood}"`,
|
||||
' data-limit="3"',
|
||||
' data-lang="tr"',
|
||||
isHidden ? ' style="display:none;"' : '',
|
||||
'></div>',
|
||||
'<script src="https://marmarislocal.com/widget.js" async></script>'
|
||||
].filter(Boolean).join('\n')
|
||||
: ''
|
||||
|
||||
const handleCopy = () => {
|
||||
@@ -107,7 +114,7 @@ export default function WidgetPartnerForm({
|
||||
<p className="text-xs text-ink/70 mb-4">
|
||||
Aşağıdaki kodu kopyalayarak partnerin web sitesine yerleştirin. Bu kod, sitenizden backlink almayı sağlar.
|
||||
</p>
|
||||
<pre className="bg-stone-deep/80 text-paper p-4 rounded-xl text-xs overflow-x-auto font-mono whitespace-pre-wrap">
|
||||
<pre className="bg-pine text-white p-4 rounded-xl text-xs overflow-x-auto font-mono whitespace-pre-wrap">
|
||||
{embedCode}
|
||||
</pre>
|
||||
</div>
|
||||
@@ -155,7 +162,8 @@ export default function WidgetPartnerForm({
|
||||
<select
|
||||
id="neighborhoodSlug"
|
||||
name="neighborhoodSlug"
|
||||
defaultValue={partner?.neighborhoodSlug || ''}
|
||||
value={selectedNeighborhood}
|
||||
onChange={(e) => setSelectedNeighborhood(e.target.value)}
|
||||
className="w-full bg-stone/30 border border-pine/10 rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:border-turquoise focus:ring-1 focus:ring-turquoise transition-all"
|
||||
>
|
||||
<option value="">Tüm Marmaris (Karışık)</option>
|
||||
@@ -166,7 +174,7 @@ export default function WidgetPartnerForm({
|
||||
<p className="text-[10px] text-shutter mt-1">Eğer seçilirse widget sadece o bölgedeki mekanları gösterir.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col justify-center pt-6">
|
||||
<div className="flex flex-col justify-center pt-6 space-y-4">
|
||||
<label className="flex items-center gap-3 cursor-pointer group">
|
||||
<div className="relative">
|
||||
<input
|
||||
@@ -184,6 +192,25 @@ export default function WidgetPartnerForm({
|
||||
<span className="text-[10px] text-shutter">Bu widget yayında mı?</span>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center gap-3 cursor-pointer group">
|
||||
<div className="relative">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isHidden"
|
||||
value="true"
|
||||
checked={isHidden}
|
||||
onChange={(e) => setIsHidden(e.target.checked)}
|
||||
className="peer sr-only"
|
||||
/>
|
||||
<div className="w-11 h-6 bg-stone-deep/20 rounded-full peer peer-checked:bg-pine transition-colors duration-300"></div>
|
||||
<div className="absolute top-1 left-1 bg-white w-4 h-4 rounded-full transition-transform duration-300 peer-checked:translate-x-5 shadow-sm"></div>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-sm font-bold text-pine block group-hover:text-pine/80 transition-colors">Gizli Widget</span>
|
||||
<span className="text-[10px] text-shutter">Indexlensin ama görünmesin</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+3
-1
@@ -652,6 +652,7 @@ export async function saveWidgetPartnerAction(formData: FormData) {
|
||||
const url = formData.get('url') as string
|
||||
const neighborhoodSlug = formData.get('neighborhoodSlug') as string | null
|
||||
const isActive = formData.get('isActive') === 'true'
|
||||
const isHidden = formData.get('isHidden') === 'true'
|
||||
|
||||
if (!name || !url) {
|
||||
return { error: 'Lütfen zorunlu alanları doldurun.' }
|
||||
@@ -661,7 +662,8 @@ export async function saveWidgetPartnerAction(formData: FormData) {
|
||||
name,
|
||||
url,
|
||||
neighborhoodSlug: neighborhoodSlug || null,
|
||||
isActive
|
||||
isActive,
|
||||
isHidden
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -4,29 +4,33 @@ import { mockDb } from '@/lib/mockDb'
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url)
|
||||
const neighborhoodSlug = searchParams.get('neighborhood')
|
||||
|
||||
if (!neighborhoodSlug) {
|
||||
return NextResponse.json({ error: 'Neighborhood is required' }, { status: 400 })
|
||||
const categorySlug = searchParams.get('category')
|
||||
|
||||
const filters: Parameters<typeof mockDb.getListings>[0] = {}
|
||||
|
||||
// Neighborhood filtresi (opsiyonel - boşsa tüm Marmaris)
|
||||
if (neighborhoodSlug) {
|
||||
const neighborhood = await mockDb.getNeighborhoodBySlug(neighborhoodSlug)
|
||||
if (neighborhood) {
|
||||
filters.neighborhoodId = neighborhood.id
|
||||
}
|
||||
}
|
||||
|
||||
// Get neighborhood
|
||||
const neighborhood = await mockDb.getNeighborhoodBySlug(neighborhoodSlug)
|
||||
if (!neighborhood) {
|
||||
return NextResponse.json({ listings: [] }, {
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
}
|
||||
})
|
||||
// Category filtresi (opsiyonel)
|
||||
if (categorySlug) {
|
||||
const categories = await mockDb.getCategories()
|
||||
const cat = categories.find(c => c.slug === categorySlug)
|
||||
if (cat) {
|
||||
filters.categoryId = cat.id
|
||||
}
|
||||
}
|
||||
|
||||
// Get listings in that neighborhood
|
||||
const listings = await mockDb.getListings({
|
||||
neighborhoodId: neighborhood.id
|
||||
})
|
||||
const listings = await mockDb.getListings(filters)
|
||||
|
||||
// Format response matching widget needs
|
||||
const formattedListings = listings.map(l => ({
|
||||
// Shuffle for variety, limit to 5
|
||||
const shuffled = listings.sort(() => 0.5 - Math.random()).slice(0, 5)
|
||||
|
||||
const formattedListings = shuffled.map(l => ({
|
||||
id: l.id,
|
||||
name: l.nameTr,
|
||||
nameEn: l.nameEn,
|
||||
@@ -36,8 +40,10 @@ export async function GET(req: NextRequest) {
|
||||
categoryName: l.category?.nameTr || '',
|
||||
neighborhoodName: l.neighborhood?.nameTr || '',
|
||||
rating: l.rating,
|
||||
priceSymbols: '₺'.repeat(l.priceRange),
|
||||
coverImage: l.images && l.images.length > 0 ? l.images[0].url : 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'
|
||||
priceSymbols: '₺'.repeat(l.priceRange || 1),
|
||||
coverImage: l.images && l.images.length > 0
|
||||
? l.images[0].url
|
||||
: 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'
|
||||
}))
|
||||
|
||||
return NextResponse.json({ listings: formattedListings }, {
|
||||
|
||||
Reference in New Issue
Block a user