"use client"; import { useState } from "react"; import { motion } from "framer-motion"; import { LayoutGrid, Save, Loader2, CheckCircle2, RefreshCw } from "lucide-react"; import { useAdminPlans, useAdminUpdatePlan } from "@/hooks/use-api"; const fadeUp = { hidden: { opacity: 0, y: 14 }, show: { opacity: 1, y: 0, transition: { duration: 0.4 } }, }; type PlanField = { key: string; label: string; type: "number" | "text" | "toggle"; suffix?: string; }; const PLAN_FIELDS: PlanField[] = [ { key: "displayName", label: "Görünen Ad", type: "text" }, { key: "monthlyPrice", label: "Aylık Fiyat", type: "number", suffix: "$¢ (cent)" }, { key: "yearlyPrice", label: "Yıllık Fiyat", type: "number", suffix: "$¢ (cent)" }, { key: "monthlyCredits", label: "Aylık Kredi", type: "number" }, { key: "maxDuration", label: "Max Süre", type: "number", suffix: "sn" }, { key: "maxResolution", label: "Max Çözünürlük", type: "text" }, { key: "maxProjects", label: "Max Proje", type: "number" }, { key: "isActive", label: "Aktif", type: "toggle" }, ]; export default function AdminPlansPage() { const { data, isLoading, refetch } = useAdminPlans(); const updatePlan = useAdminUpdatePlan(); const [savedIds, setSavedIds] = useState>(new Set()); // eslint-disable-next-line @typescript-eslint/no-explicit-any const [edits, setEdits] = useState>({}); // eslint-disable-next-line @typescript-eslint/no-explicit-any const rawPlans = (data as any)?.data ?? data; // eslint-disable-next-line @typescript-eslint/no-explicit-any const plans = (Array.isArray(rawPlans) ? rawPlans : []) as any[]; // eslint-disable-next-line @typescript-eslint/no-explicit-any function getValue(plan: any, key: string) { return edits[plan.id]?.[key] !== undefined ? edits[plan.id][key] : plan[key]; } // eslint-disable-next-line @typescript-eslint/no-explicit-any function setEdit(planId: string, key: string, value: any) { setEdits((prev) => ({ ...prev, [planId]: { ...prev[planId], [key]: value } })); } function savePlan(planId: string) { if (!edits[planId]) return; updatePlan.mutate( { id: planId, data: edits[planId] }, { onSuccess: () => { setSavedIds((prev) => new Set([...prev, planId])); setTimeout(() => setSavedIds((prev) => { const n = new Set(prev); n.delete(planId); return n; }), 2000); setEdits((prev) => { const n = { ...prev }; delete n[planId]; return n; }); refetch(); }, } ); } const PLAN_COLORS: Record = { free: "from-gray-500/10 to-gray-600/5 border-gray-500/20", pro: "from-violet-500/10 to-violet-600/5 border-violet-500/20", business: "from-amber-500/10 to-amber-600/5 border-amber-500/20", }; return (

Plan Yönetimi

Abonelik planlarını düzenle ve fiyatları güncelle

{isLoading ? (
) : (
{plans.map((plan) => { const colorKey = plan.name?.toLowerCase() ?? "free"; const gradient = PLAN_COLORS[colorKey] ?? PLAN_COLORS.free; const hasEdits = !!edits[plan.id]; return (

{plan.name}

{plan._count?.subscriptions ?? 0} abone
{PLAN_FIELDS.map((field) => { const val = getValue(plan, field.key); return (
{field.type === "toggle" ? ( ) : field.type === "number" ? ( setEdit(plan.id, field.key, Number(e.target.value))} className="input w-full text-sm" /> ) : ( setEdit(plan.id, field.key, e.target.value)} className="input w-full text-sm" /> )}
); })}
); })}
)}
); }