import Link from 'next/link' import { notFound } from 'next/navigation' import { supabaseAdmin, listAuthUsers, listCustomerOptions } from '@/lib/supabaseAdmin' import { updateLicenseAction, removeActivationAction } from '../actions' import DeleteLicenseButton from './DeleteLicenseButton' interface LicenseRow { id: string customer_id: string | null plan: string status: string max_devices: number expires_at: string | null created_at: string } interface ActivationRow { id: string device_id: string device_name: string | null platform: string | null app_version: string | null last_seen_at: string | null } function toDateInputValue(iso: string | null) { if (!iso) return '' return new Date(iso).toISOString().slice(0, 10) } function formatDateTime(iso: string | null) { if (!iso) return '—' return new Date(iso).toLocaleString('tr-TR', { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' }) } export default async function LicenseEditPage({ params, searchParams, }: { params: Promise<{ id: string }> searchParams: Promise<{ error?: string; success?: string }> }) { const { id } = await params const { error, success } = await searchParams const [{ data: license }, { data: profiles }, authUsers, customers, { data: activations }] = await Promise.all([ supabaseAdmin.from('licenses').select('id, customer_id, plan, status, max_devices, expires_at, created_at').eq('id', id).maybeSingle(), supabaseAdmin.from('profiles').select('id, full_name'), listAuthUsers(), listCustomerOptions(), supabaseAdmin.from('license_activations').select('id, device_id, device_name, platform, app_version, last_seen_at').eq('license_id', id).order('last_seen_at', { ascending: false }), ]) if (!license) notFound() const l = license as LicenseRow const profileNameById = new Map((profiles || []).map((p: { id: string; full_name: string | null }) => [p.id, p.full_name])) const currentEmail = l.customer_id ? authUsers.get(l.customer_id)?.email || '' : '' const currentName = l.customer_id ? profileNameById.get(l.customer_id) : null return (
← Lisanslar

Lisans Düzenle

{l.id}

{error && (
{error}
)} {success && (
Değişiklikler kaydedildi.
)}

{currentName ? `Şu an: ${currentName} (${currentEmail})` : currentEmail ? `Şu an: ${currentEmail}` : 'Şu an bağlı kullanıcı yok.'} {' '}Kullanıcılar listesinden seçin. "Bağlantı yok" seçilirse bağlantı kaldırılır.

Vazgeç

Aktif Cihazlar ({(activations as ActivationRow[] | null)?.length || 0} / {l.max_devices})

{!activations || activations.length === 0 ? (

Bu lisansta aktive edilmiş cihaz yok.

) : ( )}

Tehlikeli Bölge

) }