web sitesi yönetimi
This commit is contained in:
@@ -1,50 +1,11 @@
|
||||
"use client"
|
||||
import { getSiteContents } from "@/lib/data"
|
||||
import { ContactForm } from "@/components/contact/contact-form"
|
||||
import { Mail, MapPin, Phone, Instagram, Youtube } from "lucide-react"
|
||||
import { FaTiktok } from "react-icons/fa"
|
||||
import Link from "next/link"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Mail, MapPin, Phone, Loader2, CheckCircle } from "lucide-react"
|
||||
import { contactFormSchema, ContactFormValues } from "@/lib/schemas"
|
||||
import { submitContactForm } from "@/lib/actions/contact"
|
||||
import { toast } from "sonner"
|
||||
|
||||
export default function ContactPage() {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const [isSuccess, setIsSuccess] = useState(false)
|
||||
|
||||
const form = useForm<ContactFormValues>({
|
||||
resolver: zodResolver(contactFormSchema),
|
||||
defaultValues: {
|
||||
name: "",
|
||||
surname: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
subject: "",
|
||||
message: "",
|
||||
},
|
||||
})
|
||||
|
||||
async function onSubmit(data: ContactFormValues) {
|
||||
setIsSubmitting(true)
|
||||
try {
|
||||
const response = await submitContactForm(data)
|
||||
if (response.success) {
|
||||
setIsSuccess(true)
|
||||
form.reset()
|
||||
toast.success("Mesajınız başarıyla gönderildi.")
|
||||
} else {
|
||||
toast.error("Hata: " + response.error)
|
||||
}
|
||||
} catch {
|
||||
toast.error("Bir hata oluştu.")
|
||||
} finally {
|
||||
setIsSubmitting(false)
|
||||
}
|
||||
}
|
||||
export default async function ContactPage() {
|
||||
const siteSettings = await getSiteContents()
|
||||
|
||||
return (
|
||||
<div className="container py-12 md:py-24">
|
||||
@@ -63,9 +24,8 @@ export default function ContactPage() {
|
||||
<MapPin className="w-6 h-6 text-primary mt-1" />
|
||||
<div>
|
||||
<p className="font-medium">Merkez Ofis & Showroom</p>
|
||||
<p className="text-slate-600 dark:text-slate-400">
|
||||
Organize Sanayi Bölgesi, 12. Cadde No: 45<br />
|
||||
Başakşehir, İstanbul
|
||||
<p className="text-slate-600 dark:text-slate-400 whitespace-pre-wrap">
|
||||
{siteSettings.contact_address || "Organize Sanayi Bölgesi, 12. Cadde No: 45\nBaşakşehir, İstanbul"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -73,110 +33,55 @@ export default function ContactPage() {
|
||||
<Phone className="w-6 h-6 text-primary" />
|
||||
<div>
|
||||
<p className="font-medium">Telefon</p>
|
||||
<p className="text-slate-600 dark:text-slate-400">+90 (212) 555 00 00</p>
|
||||
<p className="text-slate-600 dark:text-slate-400">
|
||||
{siteSettings.contact_phone || "+90 (212) 555 00 00"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center space-x-4">
|
||||
<Mail className="w-6 h-6 text-primary" />
|
||||
<div>
|
||||
<p className="font-medium">E-posta</p>
|
||||
<p className="text-slate-600 dark:text-slate-400">info@parakasa.com</p>
|
||||
<p className="text-slate-600 dark:text-slate-400">
|
||||
{siteSettings.contact_email || "info@parakasa.com"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-4 border-t">
|
||||
<h3 className="text-lg font-semibold mb-3">Sosyal Medya</h3>
|
||||
<div className="flex gap-4">
|
||||
{siteSettings.social_instagram && (
|
||||
<Link href={siteSettings.social_instagram} target="_blank" className="p-2 bg-slate-100 dark:bg-slate-800 rounded-full hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors text-slate-700 dark:text-slate-300">
|
||||
<Instagram className="h-5 w-5" />
|
||||
</Link>
|
||||
)}
|
||||
{siteSettings.social_youtube && (
|
||||
<Link href={siteSettings.social_youtube} target="_blank" className="p-2 bg-slate-100 dark:bg-slate-800 rounded-full hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors text-slate-700 dark:text-slate-300">
|
||||
<Youtube className="h-5 w-5" />
|
||||
</Link>
|
||||
)}
|
||||
{siteSettings.social_tiktok && (
|
||||
<Link href={siteSettings.social_tiktok} target="_blank" className="p-2 bg-slate-100 dark:bg-slate-800 rounded-full hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors text-slate-700 dark:text-slate-300">
|
||||
<FaTiktok className="h-5 w-5" />
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="aspect-video bg-slate-100 rounded-lg overflow-hidden relative">
|
||||
<div className="absolute inset-0 flex items-center justify-center text-muted-foreground">
|
||||
Harita (Google Maps Embed)
|
||||
{siteSettings.contact_map_embed ? (
|
||||
<div
|
||||
className="aspect-video bg-slate-100 rounded-lg overflow-hidden relative"
|
||||
dangerouslySetInnerHTML={{ __html: siteSettings.contact_map_embed }}
|
||||
/>
|
||||
) : (
|
||||
<div className="aspect-video bg-slate-100 rounded-lg overflow-hidden relative flex items-center justify-center text-muted-foreground">
|
||||
Harita henüz eklenmemiş.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardContent className="p-6 sm:p-8">
|
||||
{isSuccess ? (
|
||||
<div className="flex flex-col items-center justify-center h-full min-h-[400px] text-center space-y-4">
|
||||
<CheckCircle className="w-16 h-16 text-green-500" />
|
||||
<h3 className="text-2xl font-bold">Mesajınız Alındı!</h3>
|
||||
<p className="text-muted-foreground">
|
||||
En kısa sürede size dönüş yapacağız.
|
||||
</p>
|
||||
<Button onClick={() => setIsSuccess(false)} variant="outline">
|
||||
Yeni Mesaj Gönder
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="name" className="text-sm font-medium">Adınız</label>
|
||||
<Input id="name" {...form.register("name")} placeholder="Adınız" />
|
||||
{form.formState.errors.name && <p className="text-xs text-red-500">{form.formState.errors.name.message}</p>}
|
||||
</div>
|
||||
<div className="space-y-2 w-[210px]">
|
||||
<label htmlFor="surname" className="text-sm font-medium">Soyadınız</label>
|
||||
<Input id="surname" {...form.register("surname")} placeholder="Soyadınız" />
|
||||
{form.formState.errors.surname && <p className="text-xs text-red-500">{form.formState.errors.surname.message}</p>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="email" className="text-sm font-medium">E-posta</label>
|
||||
<Input id="email" type="email" {...form.register("email")} placeholder="ornek@sirket.com" />
|
||||
{form.formState.errors.email && <p className="text-xs text-red-500">{form.formState.errors.email.message}</p>}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="phone" className="text-sm font-medium">Telefon</label>
|
||||
<div className="relative w-[210px]">
|
||||
<div className="absolute left-3 top-2 text-muted-foreground text-sm flex items-center gap-2 font-medium z-10 select-none pointer-events-none">
|
||||
<span>🇹🇷</span>
|
||||
<span>+90</span>
|
||||
<div className="w-px h-4 bg-border" />
|
||||
</div>
|
||||
<Input
|
||||
id="phone"
|
||||
type="tel"
|
||||
className="pl-20 font-mono"
|
||||
placeholder="(5XX) XXX XX XX"
|
||||
maxLength={15}
|
||||
{...form.register("phone", {
|
||||
onChange: (e) => {
|
||||
let value = e.target.value.replace(/\D/g, ''); // Remove non-digits
|
||||
if (value.startsWith('90')) value = value.slice(2); // Remove leading 90 if user types it
|
||||
|
||||
// Format: (5XX) XXX XX XX
|
||||
let formattedValue = '';
|
||||
if (value.length > 0) formattedValue += '(' + value.substring(0, 3);
|
||||
if (value.length > 3) formattedValue += ') ' + value.substring(3, 6);
|
||||
if (value.length > 6) formattedValue += ' ' + value.substring(6, 8);
|
||||
if (value.length > 8) formattedValue += ' ' + value.substring(8, 10);
|
||||
|
||||
e.target.value = formattedValue;
|
||||
return e;
|
||||
}
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
{form.formState.errors.phone && <p className="text-xs text-red-500">{form.formState.errors.phone.message}</p>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="subject" className="text-sm font-medium">Konu</label>
|
||||
<Input id="subject" {...form.register("subject")} placeholder="Konu" />
|
||||
{form.formState.errors.subject && <p className="text-xs text-red-500">{form.formState.errors.subject.message}</p>}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="message" className="text-sm font-medium">Mesajınız</label>
|
||||
<Textarea id="message" {...form.register("message")} placeholder="Size nasıl yardımcı olabiliriz?" className="min-h-[120px]" />
|
||||
{form.formState.errors.message && <p className="text-xs text-red-500">{form.formState.errors.message.message}</p>}
|
||||
</div>
|
||||
<Button size="lg" className="w-full" disabled={isSubmitting}>
|
||||
{isSubmitting && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Mesaj Gönder
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<ContactForm />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user