%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/pages/
Upload File :
Create Path :
Current File : //home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/pages/AdminUsersPage.tsx

import { useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";
import Button from "@/components/ui/Button";
import Card, { CardBody, CardHeader } from "@/components/ui/Card";
import Badge from "@/components/ui/Badge";
import Input from "@/components/ui/Input";
import Modal from "@/components/ui/Modal";
import DropdownMenu, { type DropdownMenuItem } from "@/components/ui/DropdownMenu";
import { useAdminUsers, type AdminStatusFilter } from "@/hooks/useAdminUsers";
import { formatCompact, formatCredit, formatDate, formatIDR } from "@/lib/format";

/* ─── Kartu ringkasan (KPI) ───────────────────────────────────── */

function StatCard({
  label,
  value,
  tone = "default",
  bare = false,
}: {
  label: string;
  value: string;
  tone?: "default" | "success" | "danger" | "info";
  bare?: boolean;
}) {
  const toneClasses: Record<string, string> = {
    default: "text-white",
    success: "text-emerald-300",
    danger: "text-red-300",
    info: "text-blue-300",
  };
  return (
    <div className={bare ? "" : "rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3"}>
      <p className="text-[10px] font-medium uppercase tracking-wider text-slate-500">
        {label}
      </p>
      <p className={`mt-1 text-xl font-bold tabular-nums sm:text-2xl ${toneClasses[tone]}`}>
        {value}
      </p>
    </div>
  );
}

function IconUsers({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <circle cx="9" cy="8" r="3.5" stroke="currentColor" strokeWidth="1.7" />
      <path
        d="M3.5 20c.6-3.5 2.8-5.5 5.5-5.5s4.9 2 5.5 5.5M16 4.8a3.5 3.5 0 0 1 0 6.4m1.5 3.8c1.8.8 2.8 2.4 3 5"
        stroke="currentColor"
        strokeWidth="1.7"
        strokeLinecap="round"
      />
    </svg>
  );
}

function IconCheckCircleSm({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <circle cx="12" cy="12" r="8.5" stroke="currentColor" strokeWidth="1.7" />
      <path
        d="m8.5 12.2 2.4 2.4 4.6-5"
        stroke="currentColor"
        strokeWidth="1.8"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

function IconBanSm({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <circle cx="12" cy="12" r="8.5" stroke="currentColor" strokeWidth="1.7" />
      <path d="m5.6 5.6 12.8 12.8" stroke="currentColor" strokeWidth="1.7" />
    </svg>
  );
}

function IconShieldSm({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <path
        d="M12 3.5 5 6v5.5c0 4.2 2.9 7.6 7 9 4.1-1.4 7-4.8 7-9V6l-7-2.5z"
        stroke="currentColor"
        strokeWidth="1.7"
        strokeLinejoin="round"
      />
    </svg>
  );
}

/* ─── Ikon SVG kecil untuk menu aksi ──────────────────────────── */

function IconChart({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <path
        d="M4 20V10m5.5 10V4m5.5 16v-7m5.5 7V7"
        stroke="currentColor"
        strokeWidth="1.7"
        strokeLinecap="round"
      />
    </svg>
  );
}

function IconWalletMini({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <path
        d="M4 7.5A2.5 2.5 0 0 1 6.5 5H18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6.5A2.5 2.5 0 0 1 4 16.5v-9z"
        stroke="currentColor"
        strokeWidth="1.7"
        strokeLinejoin="round"
      />
      <path
        d="M15 12.5h3.5a1.5 1.5 0 0 1 0 3H15a1.5 1.5 0 0 1 0-3z"
        fill="currentColor"
      />
    </svg>
  );
}

function IconBan({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <circle cx="12" cy="12" r="8.5" stroke="currentColor" strokeWidth="1.7" />
      <path d="m5.6 5.6 12.8 12.8" stroke="currentColor" strokeWidth="1.7" />
    </svg>
  );
}

function IconRotateCw({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <path
        d="M20 8v4h-4M19.2 12a7.5 7.5 0 1 1-2-5.2"
        stroke="currentColor"
        strokeWidth="1.7"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

function IconTrash({ className = "h-4 w-4" }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" className={className} aria-hidden>
      <path
        d="M4 7h16m-9 4v6m4-6v6M6.5 7l1 13h9l1-13M9.5 7V4h5v3"
        stroke="currentColor"
        strokeWidth="1.7"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

export default function AdminUsersPage() {
  const { users, summary, loading, error, status, setStatus, setActive, removeUser, setBalance } =
    useAdminUsers();
  const navigate = useNavigate();
  const [q, setQ] = useState("");
  const [working, setWorking] = useState<number | null>(null);

  // Edit saldo wallet
  const [balOpen, setBalOpen] = useState(false);
  const [balTarget, setBalTarget] = useState<(typeof users)[number] | null>(
    null,
  );
  const [balValue, setBalValue] = useState("");
  const [balBusy, setBalBusy] = useState(false);
  const [balError, setBalError] = useState<string | null>(null);

  // Hapus akun permanen
  const [delOpen, setDelOpen] = useState(false);
  const [delTarget, setDelTarget] = useState<(typeof users)[number] | null>(
    null,
  );
  const [delConfirmEmail, setDelConfirmEmail] = useState("");
  const [delBusy, setDelBusy] = useState(false);
  const [delError, setDelError] = useState<string | null>(null);

  const handleDelete = async () => {
    if (!delTarget) return;
    setDelBusy(true);
    setDelError(null);
    try {
      await removeUser(delTarget.id);
      setDelOpen(false);
      setDelTarget(null);
      setDelConfirmEmail("");
    } catch (e) {
      setDelError(e instanceof Error ? e.message : "Gagal menghapus akun");
      setDelBusy(false);
    }
  };

  const openDelete = (u: (typeof users)[number]) => {
    setDelTarget(u);
    setDelConfirmEmail("");
    setDelError(null);
    setDelOpen(true);
  };

  const openBalance = (u: (typeof users)[number]) => {
    setBalTarget(u);
    setBalValue(String(Number(u.balance) || 0));
    setBalError(null);
    setBalOpen(true);
  };

  const handleSaveBalance = async () => {
    if (!balTarget) return;
    const raw = balValue.trim();
    if (!/^\d+(\.\d{1,6})?$/.test(raw)) {
      setBalError("Saldo tidak valid (angka ≥ 0, maks 6 desimal).");
      return;
    }
    const n = Number(raw);
    if (!Number.isFinite(n) || n < 0 || n > 1_000_000_000) {
      setBalError("Saldo di luar rentang (0 – Rp1.000.000.000).");
      return;
    }
    setBalBusy(true);
    setBalError(null);
    try {
      await setBalance(balTarget.id, raw);
      setBalOpen(false);
      setBalTarget(null);
      setBalValue("");
    } catch (e) {
      setBalError(e instanceof Error ? e.message : "Gagal menyimpan saldo");
      setBalBusy(false);
    }
  };

  const filtered = useMemo(() => {
    const s = q.trim().toLowerCase();
    if (!s) return users;
    return users.filter(
      (u) =>
        u.email.toLowerCase().includes(s) || u.name.toLowerCase().includes(s),
    );
  }, [users, q]);

  const toggle = async (u: (typeof users)[number]) => {
    setWorking(u.id);
    try {
      await setActive(u.id, u.is_active !== 1);
    } catch {
      /* sederhana: abaikan error */
    } finally {
      setWorking(null);
    }
  };

  const actionMenuItems = (u: (typeof users)[number]): DropdownMenuItem[] => {
    const items: DropdownMenuItem[] = [
      {
        key: "analytics",
        label: "Analisa",
        icon: <IconChart />,
        onClick: () => navigate(`/admin/analytics?user=${u.id}`),
      },
    ];
    if (Number(u.is_admin) !== 1) {
      items.push({
        key: "balance",
        label: "Edit Saldo",
        icon: <IconWalletMini />,
        onClick: () => openBalance(u),
      });
      items.push(
        Number(u.is_active) === 1
          ? {
              key: "suspend",
              label: "Suspend",
              icon: <IconBan />,
              disabled: working === u.id,
              onClick: () => toggle(u),
            }
          : {
              key: "reactivate",
              label: "Reaktivasi",
              icon: <IconRotateCw />,
              disabled: working === u.id,
              onClick: () => toggle(u),
            },
      );
      items.push({
        key: "delete",
        label: "Hapus",
        tone: "danger",
        icon: <IconTrash />,
        onClick: () => openDelete(u),
      });
    }
    return items;
  };

  return (
    <div className="space-y-4">
    {/* Ringkasan (KPI) */}
    <div className="grid grid-cols-2 gap-3 lg:grid-cols-4 lg:gap-4">
      <div className="relative overflow-hidden rounded-xl border border-white/[0.06] bg-white/[0.02] p-4 sm:p-5">
        <div className="pointer-events-none absolute -right-3 -top-3 text-slate-700/50">
          <IconUsers className="h-10 w-10" />
        </div>
        <StatCard bare label="Total Pengguna" value={String(summary.total)} />
        <p className="mt-1.5 text-[10px] text-slate-500">
          {summary.active} aktif · {summary.suspended} suspend
        </p>
      </div>
      <div className="relative overflow-hidden rounded-xl border border-emerald-500/15 bg-emerald-500/[0.05] p-4 sm:p-5">
        <div className="pointer-events-none absolute -right-3 -top-3 text-emerald-700/40">
          <IconCheckCircleSm className="h-10 w-10" />
        </div>
        <StatCard bare label="Aktif" value={String(summary.active)} tone="success" />
        <p className="mt-1.5 text-[10px] text-slate-500">
          {summary.total > 0
            ? `${Math.round((summary.active / summary.total) * 100)}% dari total`
            : "—"}
        </p>
      </div>
      <div className="relative overflow-hidden rounded-xl border border-red-500/15 bg-red-500/[0.05] p-4 sm:p-5">
        <div className="pointer-events-none absolute -right-3 -top-3 text-red-700/40">
          <IconBanSm className="h-10 w-10" />
        </div>
        <StatCard bare label="Suspend" value={String(summary.suspended)} tone="danger" />
        <p className="mt-1.5 text-[10px] text-slate-500">
          {summary.suspended > 0 ? "Perlu perhatian" : "Tidak ada suspend"}
        </p>
      </div>
      <div className="relative overflow-hidden rounded-xl border border-white/[0.06] bg-white/[0.02] p-4 sm:p-5">
        <div className="pointer-events-none absolute -right-3 -top-3 text-slate-700/50">
          <IconShieldSm className="h-10 w-10" />
        </div>
        <StatCard bare label="Total Saldo Wallet" value={formatIDR(summary.total_balance)} />
        <p className="mt-1.5 text-[10px] text-slate-500">
          {summary.admins} admin terdaftar
        </p>
      </div>
    </div>

    {/* Filter status */}
    <div className="flex flex-wrap items-center gap-2.5">
      {(
        [
          { key: "all", label: "Semua" },
          { key: "active", label: "Aktif" },
          { key: "suspended", label: "Suspend" },
          { key: "admin", label: "Admin" },
        ] as { key: AdminStatusFilter; label: string }[]
      ).map((opt) => (
        <button
          key={opt.key}
          type="button"
          onClick={() => setStatus(opt.key)}
          className={`rounded-full border px-4 py-2 text-xs font-semibold transition ${
            status === opt.key
              ? "border-blue-400/40 bg-blue-500/15 text-blue-200"
              : "border-white/[0.08] bg-white/[0.02] text-slate-400 hover:bg-white/[0.05] hover:text-slate-200"
          }`}
        >
          {opt.label}
        </button>
      ))}
      <span className="w-full text-xs text-slate-600 sm:ml-auto sm:w-auto">
        Menampilkan {filtered.length} dari {summary.total} pengguna
      </span>
    </div>

    <Card>
      <CardHeader
        title="Daftar Pengguna"
        subtitle="Akun & pemakaian 30 hari terakhir"
        action={
          <input
            type="search"
            placeholder="Cari nama / email…"
            value={q}
            onChange={(e) => setQ(e.target.value)}
            className="input-solid w-full sm:w-56"
          />
        }
      />
      <CardBody className="p-0">
        {error && (
          <div className="p-5 text-sm text-red-300">Gagal memuat: {error}</div>
        )}
        {loading ? (
          <div className="space-y-3 p-4 sm:p-5">
            {[...Array(4)].map((_, i) => (
              <div
                key={i}
                className="h-20 animate-pulse rounded-xl bg-white/[0.02]"
              />
            ))}
          </div>
        ) : filtered.length === 0 ? (
          <div className="px-5 py-10 text-center text-sm text-slate-500">
            Tidak ada pengguna yang cocok.
          </div>
        ) : (
          <>
            {/* ── Mobile: kartu per pengguna ── */}
            <div className="divide-y divide-white/[0.04] md:hidden">
              {filtered.map((u) => (
                <div
                  key={u.id}
                  onClick={() => navigate(`/admin/users/${u.id}`)}
                  className="cursor-pointer p-4 transition-colors hover:bg-white/[0.02] sm:p-5"
                >
                  <div className="flex items-start gap-3">
                    <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-ink-700 text-xs font-semibold text-white">
                      {u.name.charAt(0).toUpperCase()}
                    </div>
                    <div className="min-w-0 flex-1">
                      <p className="flex flex-wrap items-center gap-2 font-medium text-white">
                        <span className="truncate">{u.name}</span>
                        {Number(u.is_admin) === 1 && (
                          <Badge tone="info">Admin</Badge>
                        )}
                        {Number(u.is_unlimited) === 1 && (
                          <Badge tone="warning">Unlimited</Badge>
                        )}
                        {Number(u.is_active) === 1 ? (
                          <Badge tone="success">Aktif</Badge>
                        ) : (
                          <Badge tone="danger">Suspend</Badge>
                        )}
                      </p>
                      <p className="truncate text-xs text-slate-500">
                        {u.email}
                      </p>
                      <p className="mt-0.5 text-[10px] tabular-nums text-slate-600">
                        Terdaftar {formatDate(u.created_at)}
                      </p>
                    </div>
                  </div>

                  <div className="mt-3.5 grid grid-cols-2 gap-2.5 text-xs">
                    <div className="rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2">
                      <p className="text-[10px] text-slate-500">Saldo</p>
                      <p className="mt-0.5 font-semibold tabular-nums text-slate-200">
                        {formatCredit(u.balance)}
                      </p>
                    </div>
                    <div className="rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2">
                      <p className="text-[10px] text-slate-500">Requests</p>
                      <p className="mt-0.5 font-semibold tabular-nums text-slate-200">
                        {u.requests}
                      </p>
                    </div>
                    <div className="rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2">
                      <p className="text-[10px] text-slate-500">Input</p>
                      <p className="mt-0.5 font-medium tabular-nums text-slate-300">
                        {formatCompact(u.input_tokens)}
                      </p>
                    </div>
                    <div className="rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2">
                      <p className="text-[10px] text-slate-500">Output</p>
                      <p className="mt-0.5 font-medium tabular-nums text-slate-300">
                        {formatCompact(u.output_tokens)}
                      </p>
                    </div>
                    <div className="rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2">
                      <p className="text-[10px] text-slate-500">IP Terakhir</p>
                      <p className="mt-0.5 truncate font-medium font-mono text-[11px] text-slate-400">
                        {u.last_ip || "—"}
                      </p>
                    </div>
                  </div>

                  <div
                    className="mt-3.5 flex items-center justify-end border-t border-white/[0.04] pt-3"
                    onClick={(e) => e.stopPropagation()}
                  >
                    <DropdownMenu items={actionMenuItems(u)} />
                  </div>
                </div>
              ))}
            </div>

            {/* ── Desktop: tabel ── */}
            <div className="hidden overflow-x-auto md:block">
              <table className="w-full min-w-[820px] text-left text-sm">
              <thead>
                <tr className="border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500">
                  <th className="px-5 py-3 font-semibold">Pengguna</th>
                  <th className="px-4 py-3 text-right font-semibold">
                    Saldo
                  </th>
                  <th className="px-4 py-3 text-right font-semibold">
                    Requests
                  </th>
                  <th className="px-4 py-3 text-right font-semibold">
                    Input
                  </th>
                  <th className="px-4 py-3 text-right font-semibold">
                    Cached
                  </th>
                  <th className="px-4 py-3 text-right font-semibold">
                    Output
                  </th>
                  <th className="px-4 py-3 font-semibold">Status</th>
                  <th className="px-4 py-3 font-semibold">IP Terakhir</th>
                  <th className="px-4 py-3 font-semibold">Terdaftar</th>
                  <th className="px-5 py-3 text-right font-semibold">Aksi</th>
                </tr>
              </thead>
              <tbody>
                {filtered.map((u) => (
                  <tr
                    key={u.id}
                    onClick={() => navigate(`/admin/users/${u.id}`)}
                    className="cursor-pointer border-b border-white/[0.04] align-middle transition-colors last:border-0 hover:bg-white/[0.02]"
                  >
                    <td className="px-5 py-3.5">
                      <div className="flex items-center gap-3">
                        <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-ink-700 text-xs font-semibold text-white">
                          {u.name.charAt(0).toUpperCase()}
                        </div>
                        <div className="min-w-0">
                          <p className="flex items-center gap-2 font-medium text-white">
                            {u.name}
                            {Number(u.is_admin) === 1 && (
                              <Badge tone="info">Admin</Badge>
                            )}
                            {Number(u.is_unlimited) === 1 && (
                              <Badge tone="warning">Unlimited</Badge>
                            )}
                          </p>
                          <p className="truncate text-xs text-slate-500">
                            {u.email}
                          </p>
                        </div>
                      </div>
                    </td>
                    <td className="px-4 py-3.5 text-right font-medium tabular-nums text-slate-300">
                      {formatCredit(u.balance)}
                    </td>
                    <td className="px-4 py-3.5 text-right font-medium tabular-nums whitespace-nowrap text-slate-300">
                      {u.requests}
                    </td>
                    <td className="px-4 py-3.5 text-right font-medium tabular-nums whitespace-nowrap text-slate-400">
                      {formatCompact(u.input_tokens)}
                    </td>
                    <td className="px-4 py-3.5 text-right font-medium tabular-nums whitespace-nowrap text-slate-500">
                      {formatCompact(u.cached_tokens)}
                    </td>
                    <td className="px-4 py-3.5 text-right font-medium tabular-nums whitespace-nowrap text-slate-400">
                      {formatCompact(u.output_tokens)}
                    </td>
                    <td className="px-4 py-3.5">
                      {Number(u.is_active) === 1 ? (
                        <Badge tone="success">Aktif</Badge>
                      ) : (
                        <Badge tone="danger">Suspend</Badge>
                      )}
                    </td>
                    <td className="px-4 py-3.5 text-xs tabular-nums text-slate-400">
                      {u.last_ip || "—"}
                    </td>
                    <td className="px-4 py-3.5 text-xs tabular-nums text-slate-500">
                      {formatDate(u.created_at)}
                    </td>
                    <td className="px-5 py-3.5 text-right">
                      <div
                        className="flex items-center justify-end"
                        onClick={(e) => e.stopPropagation()}
                      >
                        <DropdownMenu items={actionMenuItems(u)} />
                      </div>
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
            </div>
          </>
        )}
      </CardBody>
    </Card>

    {/* Modal konfirmasi hapus akun permanen */}
    <Modal
      open={delOpen}
      onClose={() => {
        if (!delBusy) setDelOpen(false);
      }}
      title="Hapus Akun Permanen"
      subtitle="Tindakan ini tidak dapat dibatalkan"
    >
      <div className="space-y-4">
        <div className="rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-xs leading-relaxed text-red-300">
          Anda akan <strong>menghapus permanen</strong> akun{" "}
          <strong>{delTarget?.name}</strong> (
          <strong>{delTarget?.email}</strong>). Semua data akan hilang: saldo,
          transaksi, API key, riwayat pemakaian, paket, dan sesi. Tindakan ini
          tidak bisa dikembalikan.
        </div>
        <Input
          label={`Ketik email untuk konfirmasi: ${delTarget?.email ?? ""}`}
          value={delConfirmEmail}
          onChange={(e) => {
            setDelConfirmEmail(e.target.value);
            setDelError(null);
          }}
          placeholder={delTarget?.email ?? ""}
          autoFocus
        />
        {delError && (
          <p className="text-xs font-medium text-red-400">{delError}</p>
        )}
        <div className="flex justify-end gap-2 pt-1">
          <Button
            variant="ghost"
            onClick={() => setDelOpen(false)}
            disabled={delBusy}
          >
            Batal
          </Button>
          <Button
            variant="danger"
            isLoading={delBusy}
            disabled={delConfirmEmail.trim() !== delTarget?.email}
            onClick={handleDelete}
          >
            Ya, Hapus Permanen
          </Button>
        </div>
        {delConfirmEmail.trim() !== delTarget?.email && (
          <p className="text-right text-[11px] text-slate-500">
            Ketik email lengkap untuk mengaktifkan tombol.
          </p>
        )}
      </div>
    </Modal>

    {/* Modal edit saldo wallet */}
    <Modal
      open={balOpen}
      onClose={() => {
        if (!balBusy) setBalOpen(false);
      }}
      title="Edit Saldo Wallet"
      subtitle={balTarget ? `${balTarget.name} · ${balTarget.email}` : ""}
    >
      <div className="space-y-4">
        <div className="rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3 text-xs">
          <div className="flex items-center justify-between gap-2">
            <span className="text-slate-500">Saldo saat ini</span>
            <span className="font-semibold tabular-nums text-slate-200">
              {balTarget ? formatCredit(balTarget.balance) : "…"}
            </span>
          </div>
          <p className="mt-1.5 text-[11px] leading-relaxed text-slate-500">
            Saldo akan di-<strong>set</strong> ke nilai baru (bukan
            ditambah/dikurangi). Perubahan dicatat di riwayat transaksi.
          </p>
        </div>
        <Input
          label="Saldo baru (IDR)"
          type="number"
          min={0}
          step={1000}
          inputMode="decimal"
          placeholder="cth: 25000"
          value={balValue}
          onChange={(e) => {
            setBalValue(e.target.value);
            setBalError(null);
          }}
          autoFocus
        />
        {balError && (
          <p className="text-xs font-medium text-red-400">{balError}</p>
        )}
        <div className="flex justify-end gap-2 pt-1">
          <Button
            variant="ghost"
            onClick={() => setBalOpen(false)}
            disabled={balBusy}
          >
            Batal
          </Button>
          <Button
            isLoading={balBusy}
            disabled={balValue.trim() === ""}
            onClick={handleSaveBalance}
          >
            Simpan Saldo
          </Button>
        </div>
      </div>
    </Modal>
    </div>
  );
}

Zerion Mini Shell 1.0