%PDF- %PDF-
| Direktori : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/views/ |
| Current File : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/views/TenantView.tsx |
import React, { useState } from 'react';
import {
Building2, Search, Filter, Plus, MoreVertical, ExternalLink,
CheckCircle2, Clock, PauseCircle, XCircle, Download, Calendar,
ChevronLeft, ChevronRight, ChevronDown, Eye, Edit, Store, RotateCcw,
User, Check, ShieldAlert, Sparkles, Mail, Phone, Globe, DollarSign
} from 'lucide-react';
import { Tenant } from '../../types';
import { TenantDetailView } from './TenantDetailView';
interface ExtendedTenantItem {
id: string;
name: string;
domain: string;
email: string;
phone: string;
package: 'Enterprise' | 'Pro' | 'Basic' | 'Gratis';
priceText: string;
status: 'Aktif' | 'Trial' | 'Nonaktif' | 'Dibatalkan';
joinedDate: string;
joinedRelative: string;
endDate: string;
endRelative: string;
usersCount: number;
lastActiveTime: string;
lastActiveNote: string;
logoBg: string;
logoText: string;
}
interface TenantViewProps {
tenants?: Tenant[];
onOpenAddModal: () => void;
triggerToast: (msg: string) => void;
initialDetailTenantId?: string | null;
}
export const TenantView: React.FC<TenantViewProps> = ({ onOpenAddModal, triggerToast, initialDetailTenantId = null }) => {
const [selectedStatus, setSelectedStatus] = useState<string>('Semua Status');
const [selectedPackage, setSelectedPackage] = useState<string>('Semua Paket');
const [dateRange, setDateRange] = useState<string>('');
const [searchQuery, setSearchQuery] = useState<string>('');
const [currentPage, setCurrentPage] = useState<number>(1);
const [itemsPerPage, setItemsPerPage] = useState<number>(10);
// Active Action Menu
const [activeMenuId, setActiveMenuId] = useState<string | null>(null);
// Modals state
const [detailModalTenant, setDetailModalTenant] = useState<ExtendedTenantItem | null>(null);
const [editModalTenant, setEditModalTenant] = useState<ExtendedTenantItem | null>(null);
const [selectedDetailTenantId, setSelectedDetailTenantId] = useState<string | null>(initialDetailTenantId);
// Initial Mock Tenants matching the exact screenshot
const [tenantList, setTenantList] = useState<ExtendedTenantItem[]>([
{
id: '1',
name: 'Glow Bridal Studio',
domain: 'glowbridal.muakita.com',
email: 'glowbridal@gmail.com',
phone: '0812-1234-5678',
package: 'Enterprise',
priceText: 'Rp599.000 / bln',
status: 'Aktif',
joinedDate: '10 Mei 2025',
joinedRelative: '1 bulan lalu',
endDate: '10 Mei 2026',
endRelative: '11 bulan lagi',
usersCount: 8,
lastActiveTime: 'Hari ini, 10:24',
lastActiveNote: 'Login oleh Dewi',
logoBg: 'bg-slate-900',
logoText: 'Glow'
},
{
id: '2',
name: 'Lovely Makeup Artist',
domain: 'lovelymua.muakita.com',
email: 'lovelymua@gmail.com',
phone: '0812-2222-3344',
package: 'Pro',
priceText: 'Rp299.000 / bln',
status: 'Aktif',
joinedDate: '02 Mei 2025',
joinedRelative: '19 hari lalu',
endDate: '02 Mei 2026',
endRelative: '11 bulan lagi',
usersCount: 5,
lastActiveTime: 'Kemarin, 16:45',
lastActiveNote: 'Update data layanan',
logoBg: 'bg-pink-100 text-[#EC167F]',
logoText: 'Lovely'
},
{
id: '3',
name: 'Cantik Salon & Beauty',
domain: 'cantiksalon.muakita.com',
email: 'admin@cantiksalon.com',
phone: '0813-3333-4455',
package: 'Pro',
priceText: 'Rp299.000 / bln',
status: 'Aktif',
joinedDate: '25 Apr 2025',
joinedRelative: '26 hari lalu',
endDate: '25 Apr 2026',
endRelative: '10 bulan lagi',
usersCount: 6,
lastActiveTime: 'Kemarin, 09:12',
lastActiveNote: 'Buat reservasi baru',
logoBg: 'bg-amber-100 text-amber-800',
logoText: 'Cantik'
},
{
id: '4',
name: 'Aura Wedding Organizer',
domain: 'aura.muakita.com',
email: 'aura.wedding@gmail.com',
phone: '0812-4444-5566',
package: 'Enterprise',
priceText: 'Rp599.000 / bln',
status: 'Trial',
joinedDate: '18 Mei 2025',
joinedRelative: '3 hari lalu',
endDate: '01 Jun 2025',
endRelative: '9 hari lagi',
usersCount: 3,
lastActiveTime: 'Hari ini, 08:50',
lastActiveNote: 'Login oleh Admin',
logoBg: 'bg-sky-900 text-sky-200',
logoText: 'Aura'
},
{
id: '5',
name: 'Naya Makeup Studio',
domain: 'naya.muakita.com',
email: 'nayamakeup@gmail.com',
phone: '0813-5555-6677',
package: 'Basic',
priceText: 'Rp149.000 / bln',
status: 'Nonaktif',
joinedDate: '12 Mar 2025',
joinedRelative: '2 bulan lalu',
endDate: '12 Apr 2025',
endRelative: 'Berakhir',
usersCount: 2,
lastActiveTime: '-',
lastActiveNote: 'Tidak ada aktivitas',
logoBg: 'bg-black text-white',
logoText: 'NAYA'
},
{
id: '6',
name: 'Elegant MUA',
domain: 'elegantmua.muakita.com',
email: 'elegant.mua@gmail.com',
phone: '0812-6666-7788',
package: 'Pro',
priceText: 'Rp299.000 / bln',
status: 'Dibatalkan',
joinedDate: '05 Feb 2025',
joinedRelative: '4 bulan lalu',
endDate: '10 Mar 2025',
endRelative: 'Dibatalkan',
usersCount: 4,
lastActiveTime: '28 Mei 2025',
lastActiveNote: 'Tenant dibatalkan',
logoBg: 'bg-emerald-800 text-emerald-100',
logoText: 'Elegant'
},
{
id: '7',
name: 'Beauty Classy',
domain: 'beautyclassy.muakita.com',
email: 'hello@beautyclassy.com',
phone: '0813-7777-8899',
package: 'Enterprise',
priceText: 'Rp599.000 / bln',
status: 'Aktif',
joinedDate: '20 Apr 2025',
joinedRelative: '1 bulan lalu',
endDate: '20 Apr 2026',
endRelative: '10 bulan lagi',
usersCount: 7,
lastActiveTime: 'Hari ini, 11:30',
lastActiveNote: 'Update profil bisnis',
logoBg: 'bg-rose-950 text-rose-200',
logoText: 'Classy'
}
]);
// Filter handlers
const handleResetFilters = () => {
setSelectedStatus('Semua Status');
setSelectedPackage('Semua Paket');
setDateRange('');
setSearchQuery('');
triggerToast('Filter telah di-reset');
};
const handleExportCSV = () => {
const headers = ['Nama Tenant', 'Domain', 'Email', 'Telepon', 'Paket', 'Status', 'Tgl Bergabung', 'Tgl Berakhir'];
const rows = filteredTenants.map(t => [
t.name, t.domain, t.email, t.phone, t.package, t.status, t.joinedDate, t.endDate
]);
const csvContent = 'data:text/csv;charset=utf-8,' + [headers.join(','), ...rows.map(e => e.join(','))].join('\n');
const encodedUri = encodeURI(csvContent);
const link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('download', `data_tenant_muakita_${new Date().toISOString().slice(0, 10)}.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
triggerToast('Data Tenant berhasil diexport ke CSV!');
};
// Filter Logic
const filteredTenants = tenantList.filter(t => {
const matchesSearch = t.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
t.email.toLowerCase().includes(searchQuery.toLowerCase()) ||
t.domain.toLowerCase().includes(searchQuery.toLowerCase());
const matchesStatus = selectedStatus === 'Semua Status' || t.status === selectedStatus;
const matchesPackage = selectedPackage === 'Semua Paket' || t.package === selectedPackage;
return matchesSearch && matchesStatus && matchesPackage;
});
if (selectedDetailTenantId) {
return (
<TenantDetailView
tenantId={selectedDetailTenantId}
onBack={() => setSelectedDetailTenantId(null)}
triggerToast={triggerToast}
/>
);
}
return (
<div className="space-y-4 animate-in fade-in duration-200">
{/* 1. TITLE & SUBTITLE HEADER */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 bg-white p-4 rounded-2xl border border-slate-200/80 shadow-2xs">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-2xl bg-pink-50 border border-pink-100 flex items-center justify-center text-[#EC167F] shrink-0 shadow-2xs">
<Store className="w-5 h-5" />
</div>
<div>
<h1 className="text-xl font-black text-slate-900 tracking-tight">Manajemen Tenant</h1>
<p className="text-xs font-medium text-slate-500">Kelola semua tenant (owner bisnis) di platform MuaKita.</p>
</div>
</div>
<button
onClick={onOpenAddModal}
className="bg-[#EC167F] hover:bg-[#D41270] text-white text-xs font-black px-4 py-2.5 rounded-xl shadow-xs transition-all flex items-center justify-center gap-1.5 cursor-pointer shrink-0 active:scale-95"
>
<Plus className="w-4 h-4" />
<span>Tambah Tenant Baru</span>
</button>
</div>
{/* 2. TOP 5 STAT CARDS */}
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3">
{/* Card 1: Total Tenant */}
<div className="bg-white p-3.5 rounded-2xl border border-slate-200/80 shadow-2xs flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-blue-50 text-blue-600 flex items-center justify-center shrink-0">
<Building2 className="w-5 h-5" />
</div>
<div>
<span className="text-[11px] font-bold text-slate-500 block">Total Tenant</span>
<span className="text-2xl font-black text-slate-900 leading-tight block">312</span>
<span className="text-[10px] text-slate-400 font-medium">Semua tenant terdaftar</span>
</div>
</div>
{/* Card 2: Aktif */}
<div className="bg-white p-3.5 rounded-2xl border border-slate-200/80 shadow-2xs flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-emerald-50 text-emerald-600 flex items-center justify-center shrink-0">
<CheckCircle2 className="w-5 h-5" />
</div>
<div className="flex-1 min-w-0">
<span className="text-[11px] font-bold text-slate-500 block">Aktif</span>
<span className="text-2xl font-black text-slate-900 leading-tight block">245</span>
<div className="flex items-center gap-1 text-[10px] text-slate-400 font-medium truncate">
<span>78.5% dari total tenant</span>
{/* Green Sparkline */}
<svg className="w-8 h-3 text-emerald-500 shrink-0" viewBox="0 0 24 10" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M0 8 L6 6 L12 7 L18 2 L24 4" />
</svg>
</div>
</div>
</div>
{/* Card 3: Trial / Pending */}
<div className="bg-white p-3.5 rounded-2xl border border-slate-200/80 shadow-2xs flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-amber-50 text-amber-600 flex items-center justify-center shrink-0">
<Clock className="w-5 h-5" />
</div>
<div className="flex-1 min-w-0">
<span className="text-[11px] font-bold text-slate-500 block">Trial / Pending</span>
<span className="text-2xl font-black text-slate-900 leading-tight block">28</span>
<div className="flex items-center gap-1 text-[10px] text-slate-400 font-medium truncate">
<span>9.0% dari total tenant</span>
{/* Orange Sparkline */}
<svg className="w-8 h-3 text-amber-500 shrink-0" viewBox="0 0 24 10" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M0 6 L6 8 L12 4 L18 7 L24 2" />
</svg>
</div>
</div>
</div>
{/* Card 4: Nonaktif */}
<div className="bg-white p-3.5 rounded-2xl border border-slate-200/80 shadow-2xs flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-rose-50 text-rose-600 flex items-center justify-center shrink-0">
<PauseCircle className="w-5 h-5" />
</div>
<div className="flex-1 min-w-0">
<span className="text-[11px] font-bold text-slate-500 block">Nonaktif</span>
<span className="text-2xl font-black text-slate-900 leading-tight block">24</span>
<div className="flex items-center gap-1 text-[10px] text-slate-400 font-medium truncate">
<span>7.7% dari total tenant</span>
{/* Red Sparkline */}
<svg className="w-8 h-3 text-rose-500 shrink-0" viewBox="0 0 24 10" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M0 2 L6 5 L12 4 L18 8 L24 6" />
</svg>
</div>
</div>
</div>
{/* Card 5: Dibatalkan */}
<div className="bg-white p-3.5 rounded-2xl border border-slate-200/80 shadow-2xs flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-slate-100 text-slate-500 flex items-center justify-center shrink-0">
<XCircle className="w-5 h-5" />
</div>
<div className="flex-1 min-w-0">
<span className="text-[11px] font-bold text-slate-500 block">Dibatalkan</span>
<span className="text-2xl font-black text-slate-900 leading-tight block">15</span>
<div className="flex items-center gap-1 text-[10px] text-slate-400 font-medium truncate">
<span>4.8% dari total tenant</span>
{/* Gray Sparkline */}
<svg className="w-8 h-3 text-slate-400 shrink-0" viewBox="0 0 24 10" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M0 5 L6 3 L12 6 L18 4 L24 7" />
</svg>
</div>
</div>
</div>
</div>
{/* 3. FILTER & ACTION BAR */}
<div className="bg-white p-3.5 sm:p-4 rounded-2xl border border-slate-200/80 shadow-2xs">
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3 items-end">
{/* Status Filter */}
<div>
<label className="text-[11px] font-bold text-slate-700 mb-1.5 block">Status</label>
<div className="relative">
<select
value={selectedStatus}
onChange={(e) => setSelectedStatus(e.target.value)}
className="w-full pl-3 pr-8 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs font-semibold text-slate-800 appearance-none focus:outline-none focus:bg-white focus:border-pink-500 cursor-pointer"
>
<option value="Semua Status">Semua Status</option>
<option value="Aktif">Aktif</option>
<option value="Trial">Trial</option>
<option value="Nonaktif">Nonaktif</option>
<option value="Dibatalkan">Dibatalkan</option>
</select>
<ChevronDown className="w-3.5 h-3.5 text-slate-400 absolute right-2.5 top-3 pointer-events-none" />
</div>
</div>
{/* Paket Filter */}
<div>
<label className="text-[11px] font-bold text-slate-700 mb-1.5 block">Paket</label>
<div className="relative">
<select
value={selectedPackage}
onChange={(e) => setSelectedPackage(e.target.value)}
className="w-full pl-3 pr-8 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs font-semibold text-slate-800 appearance-none focus:outline-none focus:bg-white focus:border-pink-500 cursor-pointer"
>
<option value="Semua Paket">Semua Paket</option>
<option value="Enterprise">Enterprise</option>
<option value="Pro">Pro</option>
<option value="Basic">Basic</option>
<option value="Gratis">Gratis</option>
</select>
<ChevronDown className="w-3.5 h-3.5 text-slate-400 absolute right-2.5 top-3 pointer-events-none" />
</div>
</div>
{/* Tanggal Bergabung */}
<div>
<label className="text-[11px] font-bold text-slate-700 mb-1.5 block">Tanggal Bergabung</label>
<div className="relative">
<input
type="text"
placeholder="Pilih rentang tanggal"
value={dateRange}
onChange={(e) => setDateRange(e.target.value)}
className="w-full pl-8 pr-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs font-medium text-slate-800 focus:outline-none focus:bg-white focus:border-pink-500"
/>
<Calendar className="w-3.5 h-3.5 text-slate-400 absolute left-2.5 top-3" />
</div>
</div>
{/* Pencarian (Spans 2 cols on lg) */}
<div className="lg:col-span-2">
<label className="text-[11px] font-bold text-slate-700 mb-1.5 block">Pencarian</label>
<div className="relative">
<input
type="text"
placeholder="Cari nama bisnis, email, domain..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full pl-3 pr-8 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs font-medium text-slate-800 focus:outline-none focus:bg-white focus:border-pink-500"
/>
<Search className="w-3.5 h-3.5 text-slate-400 absolute right-2.5 top-3" />
</div>
</div>
{/* Action Buttons */}
<div className="flex items-center gap-2 lg:col-span-2 justify-between">
<div className="flex items-center gap-2 flex-1">
<button
onClick={() => triggerToast('Filter diterapkan')}
className="flex-1 py-2 px-3 bg-pink-50 hover:bg-pink-100 text-[#EC167F] border border-pink-200 rounded-xl text-xs font-extrabold flex items-center justify-center gap-1.5 transition-colors cursor-pointer"
>
<Filter className="w-3.5 h-3.5" />
<span>Filter</span>
</button>
<button
onClick={handleResetFilters}
className="py-2 px-3 bg-slate-50 hover:bg-slate-100 text-slate-600 border border-slate-200 rounded-xl text-xs font-semibold transition-colors cursor-pointer"
>
Reset
</button>
</div>
<button
onClick={handleExportCSV}
className="py-2 px-3.5 bg-white hover:bg-slate-50 text-slate-700 border border-slate-200 rounded-xl text-xs font-extrabold flex items-center gap-1.5 transition-colors cursor-pointer shrink-0 shadow-2xs"
>
<Download className="w-3.5 h-3.5 text-slate-500" />
<span>Export</span>
</button>
</div>
</div>
</div>
{/* 4. TENANTS TABLE */}
<div className="bg-white rounded-2xl border border-slate-200/80 shadow-2xs overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-left text-xs">
<thead className="bg-slate-50/90 border-b border-slate-200/80 text-slate-700 font-black text-[11px] tracking-tight">
<tr>
<th className="py-3.5 px-4">Tenant / Pemilik</th>
<th className="py-3.5 px-4">Kontak</th>
<th className="py-3.5 px-4">Paket</th>
<th className="py-3.5 px-4">Status</th>
<th className="py-3.5 px-4">Bergabung</th>
<th className="py-3.5 px-4">Berakhir</th>
<th className="py-3.5 px-4">Pengguna</th>
<th className="py-3.5 px-4">Aktivitas Terakhir</th>
<th className="py-3.5 px-4 text-center">Aksi</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-100 font-medium text-slate-800">
{filteredTenants.length === 0 ? (
<tr>
<td colSpan={9} className="py-12 text-center text-slate-400">
<Building2 className="w-10 h-10 mx-auto mb-2 text-slate-300" />
<p className="font-bold text-slate-600">Tidak ada tenant ditemukan</p>
<p className="text-xs text-slate-400 mt-0.5">Coba ubah kata kunci pencarian atau filter status</p>
</td>
</tr>
) : (
filteredTenants.map((t) => (
<tr key={t.id} className="hover:bg-slate-50/70 transition-colors group">
{/* Tenant / Pemilik */}
<td className="py-3.5 px-4">
<div className="flex items-center gap-3">
<div className={`w-9 h-9 rounded-full flex items-center justify-center font-extrabold text-xs shrink-0 shadow-2xs ${t.logoBg}`}>
{t.logoText}
</div>
<div>
<button
onClick={() => setSelectedDetailTenantId('TEN-000312')}
className="font-extrabold text-slate-900 block leading-tight hover:text-[#EC167F] transition-colors text-left cursor-pointer"
>
{t.name}
</button>
<a
href={`https://${t.domain}`}
target="_blank"
rel="noreferrer"
className="text-[11px] text-slate-400 hover:text-pink-600 font-medium block"
>
{t.domain}
</a>
</div>
</div>
</td>
{/* Kontak */}
<td className="py-3.5 px-4">
<span className="text-slate-700 font-medium block text-[11px]">{t.email}</span>
<span className="text-[11px] text-slate-400 font-medium block">{t.phone}</span>
</td>
{/* Paket */}
<td className="py-3.5 px-4">
<span className={`px-2 py-0.5 rounded-md text-[10px] font-black inline-block mb-0.5 ${
t.package === 'Enterprise' ? 'bg-purple-100 text-purple-700' :
t.package === 'Pro' ? 'bg-pink-100 text-[#EC167F]' :
t.package === 'Basic' ? 'bg-blue-100 text-blue-700' :
'bg-slate-100 text-slate-600'
}`}>
{t.package}
</span>
<span className="text-[11px] font-extrabold text-slate-900 block leading-none">{t.priceText}</span>
</td>
{/* Status */}
<td className="py-3.5 px-4">
<span className={`px-3 py-1 rounded-lg text-[11px] font-bold inline-block ${
t.status === 'Aktif' ? 'bg-emerald-100/80 text-emerald-700' :
t.status === 'Trial' ? 'bg-amber-100/80 text-amber-700' :
t.status === 'Nonaktif' ? 'bg-rose-100/80 text-rose-700' :
'bg-slate-100 text-slate-600'
}`}>
{t.status}
</span>
</td>
{/* Bergabung */}
<td className="py-3.5 px-4">
<span className="font-bold text-slate-900 block text-[11px]">{t.joinedDate}</span>
<span className="text-[10px] text-slate-400 font-medium block">{t.joinedRelative}</span>
</td>
{/* Berakhir */}
<td className="py-3.5 px-4">
<span className="font-bold text-slate-900 block text-[11px]">{t.endDate}</span>
<span className={`text-[10px] font-medium block ${
t.endRelative === 'Berakhir' || t.endRelative === 'Dibatalkan' ? 'text-rose-600 font-bold' : 'text-slate-400'
}`}>
{t.endRelative}
</span>
</td>
{/* Pengguna */}
<td className="py-3.5 px-4">
<span className="font-extrabold text-slate-900 block text-[11px]">{t.usersCount}</span>
<span className="text-[10px] text-slate-400 font-medium block">User</span>
</td>
{/* Aktivitas Terakhir */}
<td className="py-3.5 px-4">
<span className="font-bold text-slate-900 block text-[11px]">{t.lastActiveTime}</span>
<span className="text-[10px] text-slate-400 font-medium block truncate max-w-[140px]">{t.lastActiveNote}</span>
</td>
{/* Aksi */}
<td className="py-3.5 px-4 text-center">
<div className="flex items-center justify-center gap-1 relative">
{/* Detail Eye Button */}
<button
onClick={() => setSelectedDetailTenantId('TEN-000312')}
className="p-1.5 rounded-lg border border-slate-200 text-blue-600 hover:bg-blue-50 transition-colors cursor-pointer"
title="Lihat Detail Tenant"
>
<Eye className="w-3.5 h-3.5" />
</button>
{/* Edit Button */}
<button
onClick={() => setEditModalTenant(t)}
className="p-1.5 rounded-lg border border-slate-200 text-amber-600 hover:bg-amber-50 transition-colors cursor-pointer"
title="Edit Data Tenant"
>
<Edit className="w-3.5 h-3.5" />
</button>
{/* More Menu Dropdown */}
<button
onClick={() => setActiveMenuId(activeMenuId === t.id ? null : t.id)}
className="p-1.5 rounded-lg border border-slate-200 text-slate-500 hover:bg-slate-100 transition-colors cursor-pointer"
title="Menu Opsi"
>
<MoreVertical className="w-3.5 h-3.5" />
</button>
{/* Dropdown Popup Menu */}
{activeMenuId === t.id && (
<div className="absolute right-0 top-full mt-1 w-44 bg-white rounded-xl shadow-xl border border-slate-200 py-1.5 z-20 text-left text-xs animate-in fade-in zoom-in-95">
<button
onClick={() => {
setSelectedDetailTenantId('TEN-000312');
setActiveMenuId(null);
}}
className="w-full px-3 py-1.5 text-slate-700 hover:bg-slate-50 flex items-center gap-2 font-medium"
>
<Eye className="w-3.5 h-3.5 text-blue-600" />
<span>Lihat Detail</span>
</button>
<button
onClick={() => {
setEditModalTenant(t);
setActiveMenuId(null);
}}
className="w-full px-3 py-1.5 text-slate-700 hover:bg-slate-50 flex items-center gap-2 font-medium"
>
<Edit className="w-3.5 h-3.5 text-amber-600" />
<span>Edit Data</span>
</button>
<button
onClick={() => {
navigator.clipboard.writeText(`https://${t.domain}`);
triggerToast(`URL https://${t.domain} disalin!`);
setActiveMenuId(null);
}}
className="w-full px-3 py-1.5 text-slate-700 hover:bg-slate-50 flex items-center gap-2 font-medium"
>
<Globe className="w-3.5 h-3.5 text-pink-600" />
<span>Salin Subdomain</span>
</button>
<div className="my-1 border-t border-slate-100" />
<button
onClick={() => {
const newStatus = t.status === 'Aktif' ? 'Nonaktif' : 'Aktif';
setTenantList(prev => prev.map(item => item.id === t.id ? { ...item, status: newStatus } : item));
triggerToast(`Status ${t.name} diubah menjadi ${newStatus}`);
setActiveMenuId(null);
}}
className={`w-full px-3 py-1.5 flex items-center gap-2 font-semibold ${
t.status === 'Aktif' ? 'text-rose-600 hover:bg-rose-50' : 'text-emerald-600 hover:bg-emerald-50'
}`}
>
<PauseCircle className="w-3.5 h-3.5" />
<span>{t.status === 'Aktif' ? 'Nonaktifkan Tenant' : 'Aktifkan Tenant'}</span>
</button>
</div>
)}
</div>
</td>
</tr>
))
)}
</tbody>
</table>
</div>
{/* 5. FOOTER & PAGINATION */}
<div className="p-3.5 sm:p-4 bg-slate-50/50 border-t border-slate-200/80 flex flex-col sm:flex-row items-center justify-between gap-3 text-xs text-slate-600">
<div>
<span>Menampilkan 1 - 10 dari <strong className="text-slate-900 font-extrabold">312</strong> tenant</span>
</div>
<div className="flex items-center gap-3">
{/* Page Number Buttons */}
<div className="flex items-center gap-1">
<button
onClick={() => setCurrentPage(p => Math.max(1, p - 1))}
className="w-8 h-8 rounded-xl border border-slate-200/80 bg-white flex items-center justify-center text-slate-600 hover:bg-slate-100 transition-colors cursor-pointer"
>
<ChevronLeft className="w-4 h-4" />
</button>
<button
onClick={() => setCurrentPage(1)}
className="w-8 h-8 rounded-xl bg-[#EC167F] text-white font-extrabold flex items-center justify-center shadow-2xs"
>
1
</button>
<button
onClick={() => setCurrentPage(2)}
className="w-8 h-8 rounded-xl border border-slate-200/80 bg-white text-slate-700 font-semibold flex items-center justify-center hover:bg-slate-100 transition-colors cursor-pointer"
>
2
</button>
<button
onClick={() => setCurrentPage(3)}
className="w-8 h-8 rounded-xl border border-slate-200/80 bg-white text-slate-700 font-semibold flex items-center justify-center hover:bg-slate-100 transition-colors cursor-pointer"
>
3
</button>
<span className="px-1 text-slate-400 font-bold">...</span>
<button
onClick={() => setCurrentPage(32)}
className="w-8 h-8 rounded-xl border border-slate-200/80 bg-white text-slate-700 font-semibold flex items-center justify-center hover:bg-slate-100 transition-colors cursor-pointer"
>
32
</button>
<button
onClick={() => setCurrentPage(p => p + 1)}
className="w-8 h-8 rounded-xl border border-slate-200/80 bg-white flex items-center justify-center text-slate-600 hover:bg-slate-100 transition-colors cursor-pointer"
>
ChevronRight <ChevronRight className="w-4 h-4" />
</button>
</div>
{/* Per page selector */}
<div className="relative">
<select
value={itemsPerPage}
onChange={(e) => setItemsPerPage(Number(e.target.value))}
className="pl-3 pr-7 py-1.5 bg-white border border-slate-200/80 rounded-xl text-xs font-bold text-slate-800 appearance-none focus:outline-none cursor-pointer"
>
<option value={10}>10 / halaman</option>
<option value={20}>20 / halaman</option>
<option value={50}>50 / halaman</option>
</select>
<ChevronDown className="w-3.5 h-3.5 text-slate-400 absolute right-2 top-2.5 pointer-events-none" />
</div>
</div>
</div>
</div>
{/* MODAL: DETAIL TENANT */}
{detailModalTenant && (
<div className="fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center p-4 animate-in fade-in duration-200">
<div className="bg-white rounded-3xl max-w-lg w-full p-6 shadow-2xl border border-slate-100 space-y-4">
<div className="flex items-start justify-between pb-3 border-b border-slate-100">
<div className="flex items-center gap-3">
<div className={`w-12 h-12 rounded-2xl flex items-center justify-center text-sm font-black ${detailModalTenant.logoBg}`}>
{detailModalTenant.logoText}
</div>
<div>
<h3 className="text-base font-black text-slate-900">{detailModalTenant.name}</h3>
<a href={`https://${detailModalTenant.domain}`} target="_blank" rel="noreferrer" className="text-xs text-pink-600 font-bold flex items-center gap-1">
{detailModalTenant.domain} <ExternalLink className="w-3 h-3" />
</a>
</div>
</div>
<button
onClick={() => setDetailModalTenant(null)}
className="p-2 text-slate-400 hover:text-slate-600 rounded-full bg-slate-100"
>
✕
</button>
</div>
<div className="space-y-3 text-xs">
<div className="grid grid-cols-2 gap-3 p-3 bg-slate-50 rounded-2xl border border-slate-100">
<div>
<span className="text-slate-400 block font-medium">Paket Langganan</span>
<span className="font-black text-slate-900 text-sm">{detailModalTenant.package}</span>
<span className="text-[10px] text-slate-500 block">{detailModalTenant.priceText}</span>
</div>
<div>
<span className="text-slate-400 block font-medium">Status Akun</span>
<span className="font-extrabold text-emerald-600 text-sm">{detailModalTenant.status}</span>
<span className="text-[10px] text-slate-500 block">Sejak {detailModalTenant.joinedDate}</span>
</div>
</div>
<div className="space-y-2">
<h4 className="font-bold text-slate-800">Informasi Kontak Owner</h4>
<div className="flex items-center gap-2 text-slate-600">
<Mail className="w-4 h-4 text-slate-400" />
<span>{detailModalTenant.email}</span>
</div>
<div className="flex items-center gap-2 text-slate-600">
<Phone className="w-4 h-4 text-slate-400" />
<span>{detailModalTenant.phone}</span>
</div>
</div>
<div className="space-y-2 pt-2 border-t border-slate-100">
<h4 className="font-bold text-slate-800">Statistik Penggunaan</h4>
<div className="flex justify-between py-1 border-b border-slate-100 text-slate-600">
<span>Jumlah Pengguna Tim:</span>
<span className="font-bold text-slate-900">{detailModalTenant.usersCount} Staff / User</span>
</div>
<div className="flex justify-between py-1 border-b border-slate-100 text-slate-600">
<span>Aktivitas Terakhir:</span>
<span className="font-bold text-slate-900">{detailModalTenant.lastActiveTime} ({detailModalTenant.lastActiveNote})</span>
</div>
<div className="flex justify-between py-1 text-slate-600">
<span>Tanggal Masa Aktif Habis:</span>
<span className="font-bold text-slate-900">{detailModalTenant.endDate} ({detailModalTenant.endRelative})</span>
</div>
</div>
</div>
<div className="flex justify-end gap-2 pt-3 border-t border-slate-100">
<button
onClick={() => {
setEditModalTenant(detailModalTenant);
setDetailModalTenant(null);
}}
className="px-4 py-2 bg-pink-50 hover:bg-pink-100 text-[#EC167F] font-bold text-xs rounded-xl transition-colors cursor-pointer"
>
Edit Tenant
</button>
<button
onClick={() => setDetailModalTenant(null)}
className="px-4 py-2 bg-slate-900 hover:bg-slate-800 text-white font-bold text-xs rounded-xl transition-colors cursor-pointer"
>
Tutup
</button>
</div>
</div>
</div>
)}
{/* MODAL: EDIT TENANT */}
{editModalTenant && (
<div className="fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center p-4 animate-in fade-in duration-200">
<div className="bg-white rounded-3xl max-w-md w-full p-6 shadow-2xl border border-slate-100 space-y-4">
<div className="flex items-center justify-between pb-3 border-b border-slate-100">
<h3 className="text-base font-black text-slate-900">Edit Data Tenant</h3>
<button
onClick={() => setEditModalTenant(null)}
className="p-2 text-slate-400 hover:text-slate-600 rounded-full bg-slate-100"
>
✕
</button>
</div>
<div className="space-y-3 text-xs">
<div>
<label className="font-bold text-slate-700 block mb-1">Nama Tenant / Bisnis</label>
<input
type="text"
value={editModalTenant.name}
onChange={(e) => setEditModalTenant({ ...editModalTenant, name: e.target.value })}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl font-semibold text-slate-900"
/>
</div>
<div>
<label className="font-bold text-slate-700 block mb-1">Subdomain</label>
<input
type="text"
value={editModalTenant.domain}
onChange={(e) => setEditModalTenant({ ...editModalTenant, domain: e.target.value })}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl font-semibold text-slate-900"
/>
</div>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="font-bold text-slate-700 block mb-1">Paket Langganan</label>
<select
value={editModalTenant.package}
onChange={(e) => setEditModalTenant({ ...editModalTenant, package: e.target.value as any })}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl font-semibold text-slate-900 cursor-pointer"
>
<option value="Enterprise">Enterprise</option>
<option value="Pro">Pro</option>
<option value="Basic">Basic</option>
<option value="Gratis">Gratis</option>
</select>
</div>
<div>
<label className="font-bold text-slate-700 block mb-1">Status Akun</label>
<select
value={editModalTenant.status}
onChange={(e) => setEditModalTenant({ ...editModalTenant, status: e.target.value as any })}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl font-semibold text-slate-900 cursor-pointer"
>
<option value="Aktif">Aktif</option>
<option value="Trial">Trial</option>
<option value="Nonaktif">Nonaktif</option>
<option value="Dibatalkan">Dibatalkan</option>
</select>
</div>
</div>
<div>
<label className="font-bold text-slate-700 block mb-1">Email Owner</label>
<input
type="email"
value={editModalTenant.email}
onChange={(e) => setEditModalTenant({ ...editModalTenant, email: e.target.value })}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl font-semibold text-slate-900"
/>
</div>
<div>
<label className="font-bold text-slate-700 block mb-1">No. WhatsApp / Handphone</label>
<input
type="text"
value={editModalTenant.phone}
onChange={(e) => setEditModalTenant({ ...editModalTenant, phone: e.target.value })}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl font-semibold text-slate-900"
/>
</div>
</div>
<div className="flex justify-end gap-2 pt-3 border-t border-slate-100">
<button
onClick={() => setEditModalTenant(null)}
className="px-4 py-2 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold text-xs rounded-xl transition-colors cursor-pointer"
>
Batal
</button>
<button
onClick={() => {
setTenantList(prev => prev.map(item => item.id === editModalTenant.id ? editModalTenant : item));
triggerToast(`Data tenant ${editModalTenant.name} berhasil diperbarui!`);
setEditModalTenant(null);
}}
className="px-4 py-2 bg-[#EC167F] hover:bg-[#D41270] text-white font-bold text-xs rounded-xl transition-colors cursor-pointer shadow-xs"
>
Simpan Perubahan
</button>
</div>
</div>
</div>
)}
</div>
);
};