Merge branch 'gece/1030-olcum' into gece/1030-entegrasyon
This commit is contained in:
39
src/features/kullanici/components/bayat-oturum-tazele.tsx
Normal file
39
src/features/kullanici/components/bayat-oturum-tazele.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
"use client";
|
||||
|
||||
// Navbar "girişli" gösterirken sunucuda oturum yoksa (BACKLOG #11) header'ı
|
||||
// tazeler. Kök neden: header kök layout'ta; istemci gezinmelerinde layout
|
||||
// yeniden render edilmez, ilk yüklemedeki "girişli" görünüm oturum düştükten
|
||||
// sonra da (süre dolumu, başka cihazdan çıkış) sert yenilemeye kadar kalır.
|
||||
// Korumalı sayfa verifySession ile /giris'e attığında giriş kartı yine
|
||||
// görünür ama header "Çıkış yap · kredi" demeye devam ediyordu.
|
||||
//
|
||||
// Yalnız giriş kartı (sunucu "oturum yok" dediğinde) render eder. Header'ın
|
||||
// istemci sinyali (ListeSenkron → useOturumDurumu) hâlâ `true` ise bir kez
|
||||
// router.refresh(): layout yeniden çizilir, navbar "Giriş yap"a döner ve sinyal
|
||||
// `false` olur. Normal girişsiz ziyarette sinyal zaten `false` — ek istek yok.
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useOturumDurumu } from "@/features/liste/liste-oturum-sinyali";
|
||||
|
||||
export function BayatOturumTazele() {
|
||||
const router = useRouter();
|
||||
const girisli = useOturumDurumu();
|
||||
const tazelendi = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (girisli !== true || tazelendi.current) return;
|
||||
tazelendi.current = true;
|
||||
router.refresh();
|
||||
}, [girisli, router]);
|
||||
|
||||
// cacheComponents: /giris gizli <Activity> içinde saklanınca effect'ler
|
||||
// sökülür; sonraki ziyarette (yeni bir düşmüş oturum) yine tazeleyebilsin.
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
tazelendi.current = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { PixelCorner } from "@/components/pixel-decor";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { GirisForm } from "./giris-form";
|
||||
import { GirisBaslik } from "./giris-baslik";
|
||||
import { BayatOturumTazele } from "./bayat-oturum-tazele";
|
||||
|
||||
export async function GirisKarti({
|
||||
callback,
|
||||
@@ -65,6 +66,8 @@ export async function GirisKarti({
|
||||
)}
|
||||
</p>
|
||||
<GirisForm callbackURL={callbackURL} />
|
||||
{/* Navbar hâlâ eski "girişli" görünümdeyse tazeler (BACKLOG #11) */}
|
||||
<BayatOturumTazele />
|
||||
</div>
|
||||
<div
|
||||
aria-hidden
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { olay } from "@/lib/analitik";
|
||||
|
||||
// iyzico'nun checkoutFormContent'i tek bir <script> bloğudur; içindeki JS,
|
||||
// sayfadaki #iyzipay-checkout-form div'ine formu (iframe) çizer. React
|
||||
@@ -41,7 +42,10 @@ export function IyzicoFormu({ icerik }: { icerik: string }) {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!govde) return;
|
||||
if (!govde) {
|
||||
olay("odeme_hata", { kod: "form_yuklenemedi" });
|
||||
return;
|
||||
}
|
||||
iyziInitSifirla();
|
||||
const script = document.createElement("script");
|
||||
script.text = govde;
|
||||
|
||||
23
src/features/odeme/components/odeme-hata-olayi.tsx
Normal file
23
src/features/odeme/components/odeme-hata-olayi.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
// Başarısız ödeme sonuç kartının görüntülenmesini `odeme_hata` olarak ölçer.
|
||||
// Sonuç kartı sunucu bileşeni; olay mount sonrası buradan atılır. Yalnız
|
||||
// durum adı gider (sipariş no gitmez); yenileme sayıyı şişirmesin diye oturum
|
||||
// başına durum başına bir kez.
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { olayBirKez } from "@/lib/analitik";
|
||||
|
||||
export function OdemeHataOlayi({
|
||||
durum,
|
||||
}: {
|
||||
/** SiparisDurumu (`@/lib/odeme`): pending | failed | not_found */
|
||||
durum: string;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const kod = `sonuc_${durum}`;
|
||||
olayBirKez("odeme_hata", { kod }, kod);
|
||||
}, [durum]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { PagePixelDivider } from "@/components/pixel-decor";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { RaporYokCta } from "./rapor-yok-cta";
|
||||
import { OdemeHataOlayi } from "./odeme-hata-olayi";
|
||||
|
||||
export async function OdemeSonucKarti({ siparis }: { siparis?: string }) {
|
||||
// Oturum düşmüşse geri dönüşte ?siparis= kaybolmasın (başarı/unblur deneyimi)
|
||||
@@ -118,6 +119,7 @@ export async function OdemeSonucKarti({ siparis }: { siparis?: string }) {
|
||||
</div>
|
||||
) : (
|
||||
<div className="rounded-2xl border border-red-200 bg-card p-8 shadow-sm">
|
||||
<OdemeHataOlayi durum={durum} />
|
||||
<XCircle className="mx-auto size-12 text-red-500" aria-hidden />
|
||||
<h1 className="mt-4 font-heading text-2xl font-bold">
|
||||
Ödeme tamamlanamadı
|
||||
|
||||
@@ -46,10 +46,13 @@ export function SatinAlForm({
|
||||
try {
|
||||
sonuc = await baslatOdeme(urun);
|
||||
} catch {
|
||||
// Action'a hiç ulaşılamadı (ağ, deploy arası, sunucu çöktü)
|
||||
olay("odeme_hata", { kod: "baglanti", urun });
|
||||
toast.error(BAGLANTI_HATASI);
|
||||
return;
|
||||
}
|
||||
if ("error" in sonuc) {
|
||||
olay("odeme_hata", { kod: sonuc.kod, urun });
|
||||
toast.error(sonuc.error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,22 @@ import { initializeCheckoutForm, initImzaDurumu } from "@/lib/iyzico";
|
||||
// promise'ini reddedip formu RedirectBoundary üzerinden yeniden mount ediyor;
|
||||
// cacheComponents altında /paket gizli <Activity> içinde canlı tutulduğu için
|
||||
// bu yarım kalmış durum geri dönüşte butonu tıklamalara sağır bırakıyordu.
|
||||
export type OdemeBaslatDurum = { error: string } | { yonlendir: string };
|
||||
//
|
||||
// Hata dalları `kod` taşır: istemci bunu `odeme_hata {kod}` olayına koyar
|
||||
// (7 Ağu–12 Eyl arasında ~100 sipariş token alamadı ve hiçbir ölçüm bunu
|
||||
// göstermedi). Kod yalnız dal adıdır; kullanıcıya ait hiçbir değer taşımaz.
|
||||
export type OdemeHataKodu =
|
||||
| "gecersiz_urun"
|
||||
| "paket_aktif"
|
||||
| "paket_yok"
|
||||
| "anahtar_eksik"
|
||||
| "iyzico_istisna"
|
||||
| "iyzico_basarisiz"
|
||||
| "imza_gecersiz";
|
||||
|
||||
export type OdemeBaslatDurum =
|
||||
| { error: string; kod: OdemeHataKodu }
|
||||
| { yonlendir: string };
|
||||
|
||||
const GENEL_HATA =
|
||||
"Ödeme şu anda başlatılamıyor; kartından çekim yapılmadı. Birazdan tekrar dener misin?";
|
||||
@@ -32,7 +47,7 @@ export async function baslatOdeme(
|
||||
// Ucuz senkron doğrulama pahalı oturum turundan önce (argüman client'tan
|
||||
// gelir; tipine güvenilmez)
|
||||
if (product !== "paket" && product !== "topup") {
|
||||
return { error: "Geçersiz ürün." };
|
||||
return { error: "Geçersiz ürün.", kod: "gecersiz_urun" };
|
||||
}
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
@@ -42,10 +57,16 @@ export async function baslatOdeme(
|
||||
// sekmede alındı) gelen istek ikinci kez ücret çekmesin.
|
||||
const kullanici = await getCurrentUser();
|
||||
if (product === "paket" && kullanici?.hasPaket) {
|
||||
return { error: "Paketin zaten aktif; yeniden ödeme alınmadı." };
|
||||
return {
|
||||
error: "Paketin zaten aktif; yeniden ödeme alınmadı.",
|
||||
kod: "paket_aktif",
|
||||
};
|
||||
}
|
||||
if (product === "topup" && !kullanici?.hasPaket) {
|
||||
return { error: "Ek kredi için önce paketi alman gerekiyor." };
|
||||
return {
|
||||
error: "Ek kredi için önce paketi alman gerekiyor.",
|
||||
kod: "paket_yok",
|
||||
};
|
||||
}
|
||||
const urun = URUNLER[product];
|
||||
|
||||
@@ -84,10 +105,10 @@ export async function baslatOdeme(
|
||||
if (err instanceof Error && err.message === "IYZICO_KEYS_MISSING") {
|
||||
// Yapılandırma detayı log'a; kullanıcıya altyapı sızdırmayan mesaj
|
||||
console.error("[odeme] iyzico anahtarları eksik — ödeme başlatılamadı");
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "anahtar_eksik" };
|
||||
}
|
||||
console.error("[odeme] iyzico initialize hatası", err);
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "iyzico_istisna" };
|
||||
}
|
||||
|
||||
if (init.status !== "success" || !init.checkoutFormContent || !init.token) {
|
||||
@@ -99,13 +120,13 @@ export async function baslatOdeme(
|
||||
errorCode: init.errorCode,
|
||||
errorMessage: init.errorMessage,
|
||||
});
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "iyzico_basarisiz" };
|
||||
}
|
||||
|
||||
// Yanıtın bütünlüğü: imza tutmuyorsa kullanıcıyı o ödeme sayfasına yollama.
|
||||
if (initImzaDurumu(init) === "gecersiz") {
|
||||
console.error("[odeme] initialize imzası geçersiz", { orderId });
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "imza_gecersiz" };
|
||||
}
|
||||
|
||||
// Form içeriği de saklanır: /odeme/[siparis] sayfası yenilense bile aynı
|
||||
|
||||
69
src/features/rehber/components/rehber-kaydirma-olayi.tsx
Normal file
69
src/features/rehber/components/rehber-kaydirma-olayi.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
// Rehber yazısında "okundu mu, terk mi" ölçümü: yazı gövdesinin %25/50/75/100'ü
|
||||
// ekranın alt kenarından geçtiğinde `rehber_kaydirma {slug, yuzde}` atılır.
|
||||
// Görsel çıktı yok. Seri başlangıcı: 30 Eki 2026 (BACKLOG #20).
|
||||
//
|
||||
// - Ölçü yazı gövdesine göre (`govdeId`), sayfaya göre değil: altbilgi, CTA ve
|
||||
// "diğer yazılar" yüzdeyi şişirmesin. Gövde ekrandan kısaysa ilk ölçümde
|
||||
// bütün eşikler birden düşer (yazının tamamı görülmüştür).
|
||||
// - Her eşik bileşen ömrü başına bir kez (ref). cacheComponents altında Next
|
||||
// eski yazıyı gizli <Activity> içinde tutar; geri gelindiğinde ref korunur,
|
||||
// aynı eşik ikinci kez sayılmaz. Gövde kimliği yazıya özgü olduğu için
|
||||
// gizli kopyanın gövdesi bulunmaz (icindekiler.tsx ile aynı gerekçe).
|
||||
// - Kaydırma dinleyicisi pasif, hesap kare başına en fazla bir kez; dört
|
||||
// eşik de düşünce dinleyici kalkar.
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { olay } from "@/lib/analitik";
|
||||
|
||||
const ESIKLER = [25, 50, 75, 100] as const;
|
||||
|
||||
export function RehberKaydirmaOlayi({
|
||||
slug,
|
||||
govdeId,
|
||||
}: {
|
||||
slug: string;
|
||||
govdeId: string;
|
||||
}) {
|
||||
const dusenler = useRef(new Set<number>());
|
||||
|
||||
useEffect(() => {
|
||||
const govde = document.getElementById(govdeId);
|
||||
if (!govde || dusenler.current.size === ESIKLER.length) return;
|
||||
|
||||
let kare = 0;
|
||||
function olc() {
|
||||
kare = 0;
|
||||
if (!govde) return;
|
||||
const { top, height } = govde.getBoundingClientRect();
|
||||
if (height <= 0) return;
|
||||
// Gövdenin ekranın alt kenarına kadar görülmüş oranı
|
||||
const oran = ((window.innerHeight - top) / height) * 100;
|
||||
for (const yuzde of ESIKLER) {
|
||||
if (oran >= yuzde && !dusenler.current.has(yuzde)) {
|
||||
dusenler.current.add(yuzde);
|
||||
olay("rehber_kaydirma", { slug, yuzde });
|
||||
}
|
||||
}
|
||||
if (dusenler.current.size === ESIKLER.length) birak();
|
||||
}
|
||||
function planla() {
|
||||
if (kare === 0) kare = requestAnimationFrame(olc);
|
||||
}
|
||||
function birak() {
|
||||
window.removeEventListener("scroll", planla);
|
||||
window.removeEventListener("resize", planla);
|
||||
}
|
||||
|
||||
window.addEventListener("scroll", planla, { passive: true });
|
||||
window.addEventListener("resize", planla, { passive: true });
|
||||
planla();
|
||||
return () => {
|
||||
birak();
|
||||
if (kare !== 0) cancelAnimationFrame(kare);
|
||||
};
|
||||
}, [slug, govdeId]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { CtaSiraForm } from "@/features/sihirbaz/components/cta-sira-form";
|
||||
import { ElCizimiSema } from "./el-cizimi-sema";
|
||||
import { Icindekiler } from "@/components/icindekiler";
|
||||
import { RehberKapak } from "./rehber-kapak";
|
||||
import { RehberKaydirmaOlayi } from "./rehber-kaydirma-olayi";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
||||
// Sayfanın generateStaticParams'ı için — sayfalar *-queries import etmez.
|
||||
@@ -122,6 +123,7 @@ export function RehberMakale({ slug }: { slug: string }) {
|
||||
)}
|
||||
<div id={`${govdeId}-son`} aria-hidden />
|
||||
</div>
|
||||
<RehberKaydirmaOlayi slug={slug} govdeId={govdeId} />
|
||||
</article>
|
||||
|
||||
<div className="mt-12 lg:col-start-2">
|
||||
|
||||
Reference in New Issue
Block a user