feat(surum-notlari): geri bildirim kutusu ve arayüz iyileştirmeleri balonu
Dev CTA bandı yerine başlık + metin alanı + buton; mesaj sunucu aksiyonuyla destek kutusuna e-posta olarak gider (IP başına 10 dk'da 3). Başlığın başı sabit, devamı bir kez daktilo gibi yazılır. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
"use client";
|
||||
|
||||
// Sürüm notları sayfasının altındaki geri bildirim kutusu: başlık, metin
|
||||
// alanı, buton. Mesaj geriBildirimGonder sunucu aksiyonuyla destek kutusuna
|
||||
// e-posta olarak gider.
|
||||
|
||||
import { useState } from "react";
|
||||
import { ArrowRight } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { TypingAnimation } from "@/components/ui/typing-animation";
|
||||
import { geriBildirimGonder } from "@/features/geri-bildirim/geri-bildirim-actions";
|
||||
|
||||
const BASLIK = "Bir hata mı gördün?";
|
||||
const DEVAM = "Yalın üretim metodunu benimsiyor ve fikirlerine önem veriyoruz.";
|
||||
|
||||
export function GeriBildirimFormu({ className = "" }: { className?: string }) {
|
||||
const [mesaj, setMesaj] = useState("");
|
||||
const [pending, setPending] = useState(false);
|
||||
|
||||
async function gonder(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setPending(true);
|
||||
try {
|
||||
const sonuc = await geriBildirimGonder(mesaj);
|
||||
if (sonuc.ok) {
|
||||
toast.success("Geri bildirimin ulaştı, teşekkürler.");
|
||||
setMesaj("");
|
||||
} else {
|
||||
toast.error(sonuc.error);
|
||||
}
|
||||
} catch {
|
||||
toast.error("Beklenmeyen bir hata oluştu, tekrar dener misin?");
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Dış kart yok: başlık sayfadaki sürüm başlıklarıyla aynı ölçekte durur,
|
||||
// altında tek yüzey var — metin alanı kenarlıksız, buton aynı yüzeyin
|
||||
// içinde (sohbet kutusuyla aynı kalıp, DESIGN.md §4.6).
|
||||
return (
|
||||
<section aria-labelledby="geri-bildirim-baslik" className={className}>
|
||||
<form onSubmit={gonder}>
|
||||
{/* Başlığın başı sabit; devamı bir kez daktilo gibi yazılır ve kalır
|
||||
(döngü yok). Görünmez tam metin aynı hücrede yer tutar ki yazı
|
||||
ilerlerken kutu aşağı kaymasın. Ekran okuyucu tam metni okur. */}
|
||||
<h2
|
||||
id="geri-bildirim-baslik"
|
||||
className="grid font-heading text-2xl font-bold text-balance text-slate-900 sm:text-3xl"
|
||||
>
|
||||
<span className="sr-only">
|
||||
{BASLIK} {DEVAM}
|
||||
</span>
|
||||
<span aria-hidden className="invisible col-start-1 row-start-1">
|
||||
{BASLIK} {DEVAM}
|
||||
</span>
|
||||
<span aria-hidden className="col-start-1 row-start-1">
|
||||
{BASLIK}{" "}
|
||||
<TypingAnimation
|
||||
typeSpeed={40}
|
||||
delay={400}
|
||||
className="inline leading-[inherit] tracking-normal text-slate-500"
|
||||
>
|
||||
{DEVAM}
|
||||
</TypingAnimation>
|
||||
</span>
|
||||
</h2>
|
||||
<div className="mt-5 rounded-2xl border border-slate-200 bg-card p-2 transition-colors duration-150 focus-within:border-primary focus-within:ring-3 focus-within:ring-ring/50">
|
||||
<Textarea
|
||||
id="geri-bildirim-mesaj"
|
||||
aria-labelledby="geri-bildirim-baslik"
|
||||
value={mesaj}
|
||||
onChange={(e) => setMesaj(e.target.value)}
|
||||
maxLength={2000}
|
||||
placeholder="Çekinme, aklına geleni yaz…"
|
||||
disabled={pending}
|
||||
className="min-h-28 resize-none border-0 bg-transparent px-3 py-2 focus-visible:ring-0 disabled:bg-transparent"
|
||||
/>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
type="submit"
|
||||
size="lg"
|
||||
disabled={pending || mesaj.trim().length < 10}
|
||||
className="cursor-pointer bg-orange-500 text-white transition-colors duration-200 hover:bg-orange-600 active:scale-[0.97]"
|
||||
>
|
||||
{pending ? "Gönderiliyor…" : "Gönder"}
|
||||
<ArrowRight className="size-4" aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
82
src/features/geri-bildirim/geri-bildirim-actions.ts
Normal file
82
src/features/geri-bildirim/geri-bildirim-actions.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
"use server";
|
||||
|
||||
import { headers } from "next/headers";
|
||||
import { getSession } from "@/lib/session";
|
||||
import { geriBildirimEpostasi } from "@/lib/eposta";
|
||||
import { epostaGonder } from "@/lib/eposta-gonder";
|
||||
import { SURUM } from "@/lib/surum";
|
||||
|
||||
const DESTEK_ADRESI = "destek@kolaytercih.com";
|
||||
const MIN_UZUNLUK = 10;
|
||||
const MAX_UZUNLUK = 2000;
|
||||
|
||||
// Uç oturumsuz da çalışır; kötüye kullanım yalnız kendi destek kutumuzu ve
|
||||
// Resend kotasını doldurur. Tek süreçte bellek içi sayaç bunu sınırlamaya
|
||||
// yeter: IP başına 10 dakikada 3 mesaj.
|
||||
const PENCERE_MS = 10 * 60 * 1000;
|
||||
const PENCERE_LIMIT = 3;
|
||||
const sonGonderimler = new Map<string, number[]>();
|
||||
|
||||
function sinirAsildi(ip: string): boolean {
|
||||
const simdi = Date.now();
|
||||
const taze = (sonGonderimler.get(ip) ?? []).filter(
|
||||
(t) => simdi - t < PENCERE_MS,
|
||||
);
|
||||
if (taze.length >= PENCERE_LIMIT) {
|
||||
sonGonderimler.set(ip, taze);
|
||||
return true;
|
||||
}
|
||||
taze.push(simdi);
|
||||
sonGonderimler.set(ip, taze);
|
||||
// Harita sınırsız büyümesin: eskimiş kayıtları ara sıra süpür.
|
||||
if (sonGonderimler.size > 1000) {
|
||||
for (const [anahtar, zamanlar] of sonGonderimler) {
|
||||
if (zamanlar.every((t) => simdi - t >= PENCERE_MS)) {
|
||||
sonGonderimler.delete(anahtar);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function geriBildirimGonder(
|
||||
hamMesaj: string,
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
const mesaj = typeof hamMesaj === "string" ? hamMesaj.trim() : "";
|
||||
if (mesaj.length < MIN_UZUNLUK) {
|
||||
return { ok: false, error: "Biraz daha ayrıntı yazar mısın?" };
|
||||
}
|
||||
if (mesaj.length > MAX_UZUNLUK) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `Mesaj en fazla ${MAX_UZUNLUK} karakter olabilir.`,
|
||||
};
|
||||
}
|
||||
|
||||
const [session, h] = await Promise.all([getSession(), headers()]);
|
||||
const ip = h.get("x-forwarded-for")?.split(",")[0]?.trim() ?? "bilinmiyor";
|
||||
if (sinirAsildi(ip)) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "Kısa sürede çok mesaj gönderdin. Birkaç dakika sonra tekrar dene.",
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await epostaGonder(
|
||||
DESTEK_ADRESI,
|
||||
geriBildirimEpostasi({
|
||||
mesaj,
|
||||
gonderen: session?.user.email ?? null,
|
||||
surum: SURUM,
|
||||
}),
|
||||
);
|
||||
return { ok: true };
|
||||
} catch (hata) {
|
||||
console.error("[geri-bildirim] Gönderilemedi:", hata);
|
||||
return {
|
||||
ok: false,
|
||||
error: `Mesajın gönderilemedi. ${DESTEK_ADRESI} adresine yazabilirsin.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user