restore: old src/ components, subscriptions, audit-log, client detail pages; fix tsconfig @/* paths; merge api.ts
This commit is contained in:
114
app/(app)/audit-log/page.tsx
Normal file
114
app/(app)/audit-log/page.tsx
Normal file
@@ -0,0 +1,114 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { ChevronLeft, ChevronRight, RefreshCw } from "lucide-react";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import { Table, TableHead, TableBody, TableRow, Th, Td, EmptyState } from "@/components/ui/Table";
|
||||
import { Badge } from "@/components/ui/Badge";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { formatDateTime } from "@/lib/utils";
|
||||
import api from "@/lib/api";
|
||||
import type { AuditLog, PaginatedResponse } from "@/types";
|
||||
|
||||
export default function AuditLogPage() {
|
||||
const [page, setPage] = useState(1);
|
||||
|
||||
const { data, isLoading, refetch } = useQuery<PaginatedResponse<AuditLog>>({
|
||||
queryKey: ["audit-logs", page],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<PaginatedResponse<AuditLog>>(`/api/v1/audit-logs?page=${page}&limit=50`);
|
||||
return res.data;
|
||||
},
|
||||
});
|
||||
|
||||
const logs = data?.data ?? [];
|
||||
const meta = data?.meta;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Audit Log</h1>
|
||||
<p className="text-sm text-gray-500">Track all system activity</p>
|
||||
</div>
|
||||
<Button size="sm" variant="outline" onClick={() => refetch()}>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Activity Log</CardTitle></CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<Th>Timestamp</Th>
|
||||
<Th>User</Th>
|
||||
<Th>Action</Th>
|
||||
<Th>Entity</Th>
|
||||
<Th>Entity ID</Th>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{isLoading ? (
|
||||
Array.from({ length: 5 }).map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
{Array.from({ length: 5 }).map((_, j) => (
|
||||
<Td key={j}><div className="h-4 w-24 animate-pulse bg-gray-100 rounded" /></Td>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : logs.length === 0 ? (
|
||||
<EmptyState message="No audit logs yet" />
|
||||
) : (
|
||||
logs.map((log) => (
|
||||
<TableRow key={log.id}>
|
||||
<Td className="text-xs text-gray-400 whitespace-nowrap">
|
||||
{formatDateTime(log.createdAt)}
|
||||
</Td>
|
||||
<Td className="text-gray-700">
|
||||
{log.user
|
||||
? `${log.user.firstName} ${log.user.lastName}`
|
||||
: log.userId?.slice(0, 8) ?? "System"}
|
||||
</Td>
|
||||
<Td>
|
||||
<Badge variant={
|
||||
log.action?.includes("CREATE") || log.action?.includes("create") ? "success" :
|
||||
log.action?.includes("DELETE") || log.action?.includes("delete") ? "danger" :
|
||||
log.action?.includes("UPDATE") || log.action?.includes("update") ? "default" : "muted"
|
||||
}>
|
||||
{log.action}
|
||||
</Badge>
|
||||
</Td>
|
||||
<Td className="text-gray-600">
|
||||
{log.entityType ?? log.entity ?? "—"}
|
||||
</Td>
|
||||
<Td className="font-mono text-xs text-gray-400">
|
||||
{log.entityId?.slice(0, 12) ?? "—"}
|
||||
</Td>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
{meta && meta.totalPages > 1 && (
|
||||
<div className="flex items-center justify-between px-4 py-3 border-t border-gray-100">
|
||||
<p className="text-sm text-gray-500">Page {meta.page} of {meta.totalPages}</p>
|
||||
<div className="flex gap-2">
|
||||
<Button size="sm" variant="outline" disabled={page <= 1} onClick={() => setPage(page - 1)}>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" disabled={page >= meta.totalPages} onClick={() => setPage(page + 1)}>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
298
app/(app)/clients/[id]/page.tsx
Normal file
298
app/(app)/clients/[id]/page.tsx
Normal file
@@ -0,0 +1,298 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { ArrowLeft, Wifi, FileText, Ticket, RefreshCw } from "lucide-react";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import { Badge } from "@/components/ui/Badge";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { Table, TableHead, TableBody, TableRow, Th, Td, EmptyState } from "@/components/ui/Table";
|
||||
import { formatDate, formatCurrency } from "@/lib/utils";
|
||||
import api from "@/lib/api";
|
||||
import type { Client, Subscription, Invoice, Ticket as TicketType, PaginatedResponse, LegacyPaginatedResponse } from "@/types";
|
||||
|
||||
type Tab = "profile" | "subscriptions" | "invoices" | "tickets";
|
||||
|
||||
const statusColor: Record<string, "success" | "warning" | "danger" | "muted"> = {
|
||||
active: "success",
|
||||
ACTIVE: "success",
|
||||
suspended: "warning",
|
||||
SUSPENDED: "warning",
|
||||
cancelled: "danger",
|
||||
CANCELLED: "danger",
|
||||
disconnected: "danger",
|
||||
pending: "muted",
|
||||
PENDING: "muted",
|
||||
};
|
||||
|
||||
export default function ClientDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const router = useRouter();
|
||||
const [activeTab, setActiveTab] = useState<Tab>("profile");
|
||||
|
||||
const { data: client, isLoading, refetch: refetchClient } = useQuery<Client>({
|
||||
queryKey: ["client", id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<Client>(`/api/v1/clients/${id}`);
|
||||
return res.data;
|
||||
},
|
||||
});
|
||||
|
||||
const { data: subscriptions, isError: subsError } = useQuery<Subscription[]>({
|
||||
queryKey: ["client-subscriptions", id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<Subscription[]>(`/api/v1/clients/${id}/subscriptions`);
|
||||
return Array.isArray(res.data) ? res.data : [];
|
||||
},
|
||||
enabled: activeTab === "subscriptions",
|
||||
retry: false,
|
||||
});
|
||||
|
||||
const { data: invoicesData } = useQuery<LegacyPaginatedResponse<Invoice>>({
|
||||
queryKey: ["client-invoices", id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<LegacyPaginatedResponse<Invoice>>(`/api/v1/invoices?clientId=${id}&page=1&limit=20`);
|
||||
return res.data;
|
||||
},
|
||||
enabled: activeTab === "invoices",
|
||||
});
|
||||
|
||||
const { data: ticketsData } = useQuery<PaginatedResponse<TicketType>>({
|
||||
queryKey: ["client-tickets", id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<PaginatedResponse<TicketType>>(`/api/v1/tickets?clientId=${id}&page=1&limit=20`);
|
||||
return res.data;
|
||||
},
|
||||
enabled: activeTab === "tickets",
|
||||
});
|
||||
|
||||
const tabs: { key: Tab; label: string; icon: React.ComponentType<{ className?: string }> }[] = [
|
||||
{ key: "profile", label: "Profile", icon: ArrowLeft },
|
||||
{ key: "subscriptions", label: "Subscriptions", icon: Wifi },
|
||||
{ key: "invoices", label: "Invoices", icon: FileText },
|
||||
{ key: "tickets", label: "Tickets", icon: Ticket },
|
||||
];
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="h-8 w-48 animate-pulse bg-gray-200 rounded" />
|
||||
<Card>
|
||||
<CardContent className="py-10">
|
||||
<div className="h-32 animate-pulse bg-gray-100 rounded-lg" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!client) {
|
||||
return (
|
||||
<div className="text-center py-20 text-gray-400">
|
||||
<p>Client not found</p>
|
||||
<Button variant="secondary" className="mt-4" onClick={() => router.push("/clients")}>
|
||||
Back to Clients
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-3">
|
||||
<Button variant="ghost" size="sm" onClick={() => router.push("/clients")}>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">
|
||||
{client.firstName} {client.lastName}
|
||||
</h1>
|
||||
<p className="text-sm text-gray-500">
|
||||
{client.accountNumber} • {client.area?.name ?? ""}
|
||||
</p>
|
||||
</div>
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<Badge variant={client.isActive ? "success" : "muted"}>
|
||||
{client.isActive ? "Active" : "Inactive"}
|
||||
</Badge>
|
||||
<Button size="sm" variant="outline" onClick={() => refetchClient()}>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="flex border-b border-gray-200">
|
||||
{[
|
||||
{ key: "profile" as Tab, label: "Profile" },
|
||||
{ key: "subscriptions" as Tab, label: "Subscriptions" },
|
||||
{ key: "invoices" as Tab, label: "Invoices" },
|
||||
{ key: "tickets" as Tab, label: "Tickets" },
|
||||
].map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
onClick={() => setActiveTab(tab.key)}
|
||||
className={`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${
|
||||
activeTab === tab.key
|
||||
? "border-blue-600 text-blue-600"
|
||||
: "border-transparent text-gray-500 hover:text-gray-700"
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Profile Tab */}
|
||||
{activeTab === "profile" && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Client Profile</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
{[
|
||||
{ label: "Account Number", value: client.accountNumber },
|
||||
{ label: "Full Name", value: `${client.firstName} ${client.lastName}` },
|
||||
{ label: "Email", value: client.email },
|
||||
{ label: "Phone", value: client.phone },
|
||||
{ label: "Address", value: client.address || "—" },
|
||||
{ label: "Area", value: client.area?.name || "—" },
|
||||
{ label: "Status", value: client.isActive ? "Active" : "Inactive" },
|
||||
{ label: "Joined", value: formatDate(client.createdAt) },
|
||||
].map(({ label, value }) => (
|
||||
<div key={label}>
|
||||
<dt className="text-xs font-medium text-gray-400 uppercase tracking-wide">{label}</dt>
|
||||
<dd className="mt-0.5 text-sm text-gray-900">{value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Subscriptions Tab */}
|
||||
{activeTab === "subscriptions" && (
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Subscriptions</CardTitle></CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<Th>Plan</Th>
|
||||
<Th>Status</Th>
|
||||
<Th>Start Date</Th>
|
||||
<Th>Monthly Rate</Th>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{subsError ? (
|
||||
<tr><td colSpan={4} className="py-8 text-center text-gray-400 text-sm">No data yet</td></tr>
|
||||
) : !subscriptions || subscriptions.length === 0 ? (
|
||||
<EmptyState message="No subscriptions yet" />
|
||||
) : (
|
||||
subscriptions.map((sub) => (
|
||||
<TableRow key={sub.id} className="hover:bg-gray-50 transition-colors">
|
||||
<Td className="font-medium">{sub.plan?.name ?? sub.planId}</Td>
|
||||
<Td>
|
||||
<Badge variant={statusColor[sub.status] ?? "muted"}>
|
||||
{sub.status}
|
||||
</Badge>
|
||||
</Td>
|
||||
<Td>{formatDate(sub.startDate)}</Td>
|
||||
<Td>{formatCurrency(sub.plan?.monthlyPrice ?? sub.monthlyRate ?? sub.mrc ?? 0)}</Td>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Invoices Tab */}
|
||||
{activeTab === "invoices" && (
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Invoices</CardTitle></CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<Th>Invoice #</Th>
|
||||
<Th>Amount</Th>
|
||||
<Th>Due Date</Th>
|
||||
<Th>Status</Th>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{!invoicesData?.data || invoicesData.data.length === 0 ? (
|
||||
<EmptyState message="No invoices yet" />
|
||||
) : (
|
||||
invoicesData.data.map((inv) => (
|
||||
<TableRow key={inv.id}>
|
||||
<Td className="font-mono text-xs">{inv.invoiceNumber ?? inv.id.slice(0, 8)}</Td>
|
||||
<Td>{formatCurrency(inv.amount ?? inv.totalAmount ?? 0)}</Td>
|
||||
<Td>{formatDate(inv.dueDate)}</Td>
|
||||
<Td>
|
||||
<Badge
|
||||
variant={
|
||||
inv.status === "paid" || inv.status === "PAID" ? "success" :
|
||||
inv.status === "overdue" || inv.status === "OVERDUE" ? "danger" : "warning"
|
||||
}
|
||||
>
|
||||
{inv.status}
|
||||
</Badge>
|
||||
</Td>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Tickets Tab */}
|
||||
{activeTab === "tickets" && (
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Tickets</CardTitle></CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<Th>Subject</Th>
|
||||
<Th>Type</Th>
|
||||
<Th>Priority</Th>
|
||||
<Th>Status</Th>
|
||||
<Th>Created</Th>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{!ticketsData?.data || ticketsData.data.length === 0 ? (
|
||||
<EmptyState message="No tickets yet" />
|
||||
) : (
|
||||
ticketsData.data.map((ticket) => (
|
||||
<TableRow key={ticket.id}>
|
||||
<Td className="font-medium">{ticket.subject}</Td>
|
||||
<Td><Badge variant="muted">{ticket.type}</Badge></Td>
|
||||
<Td>
|
||||
<Badge variant={
|
||||
ticket.priority === "urgent" ? "danger" :
|
||||
ticket.priority === "high" ? "warning" : "muted"
|
||||
}>{ticket.priority}</Badge>
|
||||
</Td>
|
||||
<Td><Badge variant="default">{ticket.status}</Badge></Td>
|
||||
<Td className="text-xs text-gray-400">{formatDate(ticket.createdAt)}</Td>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
157
app/(app)/subscriptions/page.tsx
Normal file
157
app/(app)/subscriptions/page.tsx
Normal file
@@ -0,0 +1,157 @@
|
||||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { RefreshCw, Wifi, AlertCircle } from "lucide-react";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import { Table, TableHead, TableBody, TableRow, Th, Td } from "@/components/ui/Table";
|
||||
import { Badge } from "@/components/ui/Badge";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { formatDate, formatCurrency } from "@/lib/utils";
|
||||
import api from "@/lib/api";
|
||||
import type { PaginatedResponse } from "@/types";
|
||||
|
||||
interface Subscription {
|
||||
id: string;
|
||||
clientId: string;
|
||||
status: string;
|
||||
startDate: string;
|
||||
endDate?: string;
|
||||
client?: { firstName: string; lastName: string; accountNumber: string };
|
||||
plan?: { name: string; type: string; monthlyPrice: number };
|
||||
planId?: string;
|
||||
monthlyRate?: number;
|
||||
mrc?: number;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
const statusVariant: Record<string, "success" | "warning" | "danger" | "muted"> = {
|
||||
ACTIVE: "success",
|
||||
active: "success",
|
||||
SUSPENDED: "warning",
|
||||
suspended: "warning",
|
||||
CANCELLED: "danger",
|
||||
cancelled: "danger",
|
||||
DISCONNECTED: "danger",
|
||||
disconnected: "danger",
|
||||
PENDING: "muted",
|
||||
pending: "muted",
|
||||
};
|
||||
|
||||
export default function SubscriptionsPage() {
|
||||
const router = useRouter();
|
||||
|
||||
const { data, isLoading, isError, error, refetch, isFetching } = useQuery<PaginatedResponse<Subscription>>({
|
||||
queryKey: ["subscriptions"],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<PaginatedResponse<Subscription>>("/api/v1/subscriptions?page=1&limit=50");
|
||||
return res.data;
|
||||
},
|
||||
retry: false,
|
||||
});
|
||||
|
||||
const subscriptions = data?.data ?? [];
|
||||
const meta = data?.meta;
|
||||
|
||||
const isNotFound =
|
||||
isError &&
|
||||
(error as { response?: { status?: number } })?.response?.status === 404;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Subscriptions</h1>
|
||||
<p className="text-sm text-gray-500">{meta?.total ?? 0} total subscriptions</p>
|
||||
</div>
|
||||
<Button size="sm" variant="outline" onClick={() => refetch()} disabled={isFetching}>
|
||||
<RefreshCw className={`h-4 w-4 ${isFetching ? "animate-spin" : ""}`} />
|
||||
{isFetching ? "Checking…" : "Retry"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>All Subscriptions</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
{isLoading ? (
|
||||
<div className="p-6 space-y-3">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div key={i} className="h-10 animate-pulse bg-gray-100 rounded-lg" />
|
||||
))}
|
||||
</div>
|
||||
) : isNotFound || (isError && !data) ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 text-center px-6">
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-blue-50 mb-4">
|
||||
<Wifi className="h-8 w-8 text-blue-400" />
|
||||
</div>
|
||||
<h3 className="text-base font-semibold text-gray-700 mb-2">Subscriptions Module Not Yet Available</h3>
|
||||
<p className="text-sm text-gray-500 max-w-sm mb-4">
|
||||
Subscription data will appear here once the module is deployed.
|
||||
</p>
|
||||
<div className="flex items-center gap-1.5 text-xs text-amber-600 bg-amber-50 px-3 py-1.5 rounded-full mb-5">
|
||||
<AlertCircle className="h-3.5 w-3.5" />
|
||||
<span>API endpoint not yet available</span>
|
||||
</div>
|
||||
<Button variant="secondary" onClick={() => refetch()} disabled={isFetching}>
|
||||
<RefreshCw className={`h-4 w-4 ${isFetching ? "animate-spin" : ""}`} />
|
||||
{isFetching ? "Checking…" : "Retry Now"}
|
||||
</Button>
|
||||
</div>
|
||||
) : subscriptions.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 text-center px-6">
|
||||
<div className="flex h-14 w-14 items-center justify-center rounded-full bg-gray-100 mb-3">
|
||||
<Wifi className="h-7 w-7 text-gray-400" />
|
||||
</div>
|
||||
<p className="text-sm text-gray-500">No subscriptions yet.</p>
|
||||
<Button variant="secondary" size="sm" className="mt-3" onClick={() => refetch()}>
|
||||
<RefreshCw className="h-4 w-4" /> Refresh
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<Th>Client</Th>
|
||||
<Th>Plan</Th>
|
||||
<Th>Type</Th>
|
||||
<Th>Status</Th>
|
||||
<Th>Start Date</Th>
|
||||
<Th>MRC</Th>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{subscriptions.map((sub) => (
|
||||
<TableRow
|
||||
key={sub.id}
|
||||
className="hover:bg-gray-50 transition-colors cursor-pointer"
|
||||
onClick={() => sub.clientId && router.push(`/clients/${sub.clientId}`)}
|
||||
>
|
||||
<Td>
|
||||
{sub.client ? (
|
||||
<div>
|
||||
<p className="font-medium text-sm">{sub.client.firstName} {sub.client.lastName}</p>
|
||||
<p className="text-xs text-gray-400 font-mono">{sub.client.accountNumber}</p>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-gray-400 text-sm">—</span>
|
||||
)}
|
||||
</Td>
|
||||
<Td className="font-medium">{sub.plan?.name ?? sub.planId ?? "—"}</Td>
|
||||
<Td><Badge variant="muted">{sub.plan?.type ?? sub.type ?? "—"}</Badge></Td>
|
||||
<Td>
|
||||
<Badge variant={statusVariant[sub.status] ?? "muted"}>{sub.status}</Badge>
|
||||
</Td>
|
||||
<Td>{formatDate(sub.startDate)}</Td>
|
||||
<Td>{formatCurrency(sub.plan?.monthlyPrice ?? sub.monthlyRate ?? sub.mrc ?? 0)}</Td>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,76 +4,58 @@ import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useAuthStore } from '@/lib/auth-store';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Users,
|
||||
FileText,
|
||||
CreditCard,
|
||||
ArrowLeftRight,
|
||||
Ticket,
|
||||
BarChart3,
|
||||
Settings,
|
||||
LayoutDashboard, Users, FileText, CreditCard, ArrowLeftRight,
|
||||
Ticket, BarChart3, Settings, Wifi, ClipboardList, ScrollText,
|
||||
} from 'lucide-react';
|
||||
|
||||
const navItems = [
|
||||
{ label: 'Dashboard', href: '/dashboard', icon: LayoutDashboard, roles: [] },
|
||||
{ label: 'Clients', href: '/clients', icon: Users, roles: [] },
|
||||
{ label: 'Subscriptions', href: '/subscriptions', icon: Wifi, roles: [] },
|
||||
{ label: 'Invoices', href: '/invoices', icon: FileText, roles: [] },
|
||||
{ label: 'Payments', href: '/payments', icon: CreditCard, roles: [] },
|
||||
{ label: 'Remittances', href: '/remittances', icon: ArrowLeftRight, roles: [] },
|
||||
{ label: 'Tickets', href: '/tickets', icon: Ticket, roles: [] },
|
||||
{ label: 'Reports', href: '/reports', icon: BarChart3, roles: ['admin', 'staff'] },
|
||||
{ label: 'Tasks', href: '/tasks', icon: ClipboardList, roles: ['admin','staff'] },
|
||||
{ label: 'Reports', href: '/reports', icon: BarChart3, roles: ['admin','staff'] },
|
||||
{ label: 'Audit Log', href: '/audit-log', icon: ScrollText, roles: ['admin'] },
|
||||
{ label: 'Settings', href: '/settings/tenant', icon: Settings, roles: ['admin'] },
|
||||
];
|
||||
|
||||
export default function Sidebar() {
|
||||
const pathname = usePathname();
|
||||
const user = useAuthStore((s) => s.user);
|
||||
const userRoles = user?.roles ?? [];
|
||||
const userRoles: string[] = (user?.roles ?? []).map((r: string) => r.toLowerCase());
|
||||
|
||||
const visibleItems = navItems.filter(
|
||||
(item) => item.roles.length === 0 || item.roles.some((r) => userRoles.includes(r))
|
||||
);
|
||||
|
||||
return (
|
||||
<aside
|
||||
className="flex flex-col w-64 min-h-screen"
|
||||
style={{ backgroundColor: '#0F172A' }}
|
||||
>
|
||||
<aside className="flex flex-col w-64 min-h-screen" style={{ backgroundColor: '#0F172A' }}>
|
||||
{/* Logo */}
|
||||
<div className="flex items-center gap-2 px-6 py-5 border-b border-slate-700">
|
||||
<div
|
||||
className="w-8 h-8 rounded-lg flex items-center justify-center text-white font-bold text-sm"
|
||||
style={{ backgroundColor: '#0891B2' }}
|
||||
>
|
||||
F
|
||||
</div>
|
||||
<div className="w-8 h-8 rounded-lg flex items-center justify-center text-white font-bold text-sm"
|
||||
style={{ backgroundColor: '#0891B2' }}>F</div>
|
||||
<span className="text-white font-semibold text-lg">FiberOps</span>
|
||||
</div>
|
||||
|
||||
{/* Nav */}
|
||||
<nav className="flex-1 px-3 py-4 space-y-1">
|
||||
<nav className="flex-1 px-3 py-4 space-y-0.5 overflow-y-auto">
|
||||
{visibleItems.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive =
|
||||
pathname === item.href || pathname.startsWith(item.href + '/');
|
||||
const isActive = pathname === item.href || pathname.startsWith(item.href + '/');
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
<Link key={item.href} href={item.href}
|
||||
className="flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors"
|
||||
style={{
|
||||
backgroundColor: isActive ? '#0891B2' : 'transparent',
|
||||
color: isActive ? '#fff' : '#94A3B8',
|
||||
}}
|
||||
>
|
||||
<Icon size={18} />
|
||||
{item.label}
|
||||
}}>
|
||||
<Icon size={18} />{item.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="px-6 py-4 border-t border-slate-700">
|
||||
<p className="text-slate-500 text-xs">FiberOps v1.0</p>
|
||||
</div>
|
||||
|
||||
29
src/components/Providers.tsx
Normal file
29
src/components/Providers.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"use client";
|
||||
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { AuthProvider } from "@/contexts/AuthContext";
|
||||
import { Toaster } from "sonner";
|
||||
import { useState } from "react";
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 30 * 1000,
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AuthProvider>
|
||||
{children}
|
||||
<Toaster richColors position="top-right" />
|
||||
</AuthProvider>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
34
src/components/layout/AppLayout.tsx
Normal file
34
src/components/layout/AppLayout.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Sidebar } from "./Sidebar";
|
||||
import { TopBar } from "./TopBar";
|
||||
import { useAuth } from "@/contexts/AuthContext";
|
||||
|
||||
export function AppLayout({ children }: { children: React.ReactNode }) {
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
const { isAuthenticated } = useAuth();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
const token = localStorage.getItem("accessToken");
|
||||
if (!token) {
|
||||
router.push("/login");
|
||||
}
|
||||
}
|
||||
}, [isAuthenticated, router]);
|
||||
|
||||
return (
|
||||
<div className="flex h-screen bg-gray-50 overflow-hidden">
|
||||
<Sidebar isOpen={sidebarOpen} onClose={() => setSidebarOpen(false)} />
|
||||
<div className="flex flex-1 flex-col min-w-0 overflow-hidden">
|
||||
<TopBar onMenuClick={() => setSidebarOpen(true)} />
|
||||
<main className="flex-1 overflow-y-auto p-4 md:p-6">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
110
src/components/layout/Sidebar.tsx
Normal file
110
src/components/layout/Sidebar.tsx
Normal file
@@ -0,0 +1,110 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Users,
|
||||
CreditCard,
|
||||
FileText,
|
||||
Banknote,
|
||||
Ticket,
|
||||
CheckSquare,
|
||||
UserCog,
|
||||
ClipboardList,
|
||||
Settings,
|
||||
Wifi,
|
||||
Briefcase,
|
||||
BarChart2,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
|
||||
const navItems = [
|
||||
{ href: "/dashboard", label: "Dashboard", icon: LayoutDashboard },
|
||||
{ href: "/clients", label: "Clients", icon: Users },
|
||||
{ href: "/subscriptions", label: "Subscriptions", icon: Wifi },
|
||||
{ href: "/invoices", label: "Invoices", icon: FileText },
|
||||
{ href: "/payments", label: "Payments", icon: Banknote },
|
||||
{ href: "/remittances", label: "Remittances", icon: Briefcase },
|
||||
{ href: "/tickets", label: "Tickets", icon: Ticket },
|
||||
{ href: "/tasks", label: "Tasks", icon: CheckSquare },
|
||||
{ href: "/users", label: "Users", icon: UserCog },
|
||||
{ href: "/audit-log", label: "Audit Log", icon: ClipboardList },
|
||||
{ href: "/reports", label: "Reports", icon: BarChart2 },
|
||||
{ href: "/settings", label: "Settings", icon: Settings },
|
||||
];
|
||||
|
||||
interface SidebarProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
const pathname = usePathname();
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Mobile overlay */}
|
||||
{isOpen && (
|
||||
<div
|
||||
className="fixed inset-0 z-20 bg-black/30 lg:hidden"
|
||||
onClick={onClose}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Sidebar */}
|
||||
<aside
|
||||
className={cn(
|
||||
"fixed top-0 left-0 z-30 h-full w-60 bg-white border-r border-gray-200 flex flex-col transition-transform duration-200",
|
||||
"lg:translate-x-0 lg:static lg:z-auto",
|
||||
isOpen ? "translate-x-0" : "-translate-x-full"
|
||||
)}
|
||||
>
|
||||
{/* Logo */}
|
||||
<div className="flex items-center justify-between px-4 py-4 border-b border-gray-100">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-blue-600">
|
||||
<Wifi className="h-4 w-4 text-white" />
|
||||
</div>
|
||||
<span className="text-base font-bold text-gray-900">FiberOps</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="rounded-lg p-1 text-gray-400 hover:bg-gray-100 lg:hidden"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Nav items */}
|
||||
<nav className="flex-1 overflow-y-auto px-3 py-4 space-y-0.5">
|
||||
{navItems.map(({ href, label, icon: Icon }) => {
|
||||
const isActive = pathname === href || pathname.startsWith(href + "/");
|
||||
return (
|
||||
<Link
|
||||
key={href}
|
||||
href={href}
|
||||
onClick={onClose}
|
||||
className={cn(
|
||||
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors",
|
||||
isActive
|
||||
? "bg-blue-50 text-blue-700"
|
||||
: "text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
||||
)}
|
||||
>
|
||||
<Icon className={cn("h-4 w-4 shrink-0", isActive ? "text-blue-600" : "text-gray-400")} />
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="border-t border-gray-100 px-3 py-3">
|
||||
<p className="text-xs text-gray-400 text-center">FiberOps v1.0</p>
|
||||
</div>
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
44
src/components/layout/TopBar.tsx
Normal file
44
src/components/layout/TopBar.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import { useAuth } from "@/contexts/AuthContext";
|
||||
import { Menu, LogOut, User } from "lucide-react";
|
||||
|
||||
interface TopBarProps {
|
||||
onMenuClick: () => void;
|
||||
}
|
||||
|
||||
export function TopBar({ onMenuClick }: TopBarProps) {
|
||||
const { user, tenantSlug, logout } = useAuth();
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-10 flex h-14 items-center justify-between border-b border-gray-200 bg-white px-4 shadow-sm">
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={onMenuClick}
|
||||
className="rounded-lg p-1.5 text-gray-500 hover:bg-gray-100 lg:hidden"
|
||||
>
|
||||
<Menu className="h-5 w-5" />
|
||||
</button>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-medium text-gray-400 uppercase tracking-wide">Tenant:</span>
|
||||
<span className="text-sm font-semibold text-blue-600">{tenantSlug}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="hidden sm:flex items-center gap-2 text-sm text-gray-600">
|
||||
<User className="h-4 w-4 text-gray-400" />
|
||||
<span>{user?.name || user?.email || "User"}</span>
|
||||
<span className="text-xs text-gray-400 bg-gray-100 px-2 py-0.5 rounded-full">{user?.role}</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={logout}
|
||||
className="flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm text-gray-600 hover:bg-red-50 hover:text-red-600 transition-colors"
|
||||
>
|
||||
<LogOut className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">Logout</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
31
src/components/ui/Badge.tsx
Normal file
31
src/components/ui/Badge.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface BadgeProps {
|
||||
children: React.ReactNode;
|
||||
variant?: "default" | "success" | "warning" | "danger" | "info" | "muted" | "purple";
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const variantClasses: Record<string, string> = {
|
||||
default: "bg-blue-100 text-blue-800",
|
||||
success: "bg-green-100 text-green-800",
|
||||
warning: "bg-amber-100 text-amber-800",
|
||||
danger: "bg-red-100 text-red-800",
|
||||
info: "bg-sky-100 text-sky-800",
|
||||
muted: "bg-gray-100 text-gray-700",
|
||||
purple: "bg-purple-100 text-purple-800",
|
||||
};
|
||||
|
||||
export function Badge({ children, variant = "default", className }: BadgeProps) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",
|
||||
variantClasses[variant],
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
50
src/components/ui/Button.tsx
Normal file
50
src/components/ui/Button.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ButtonHTMLAttributes, forwardRef } from "react";
|
||||
|
||||
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: "primary" | "secondary" | "danger" | "ghost" | "outline";
|
||||
size?: "sm" | "md" | "lg";
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
const variantClasses: Record<string, string> = {
|
||||
primary: "bg-blue-600 hover:bg-blue-700 text-white border-transparent",
|
||||
secondary: "bg-gray-100 hover:bg-gray-200 text-gray-700 border-transparent",
|
||||
danger: "bg-red-600 hover:bg-red-700 text-white border-transparent",
|
||||
ghost: "bg-transparent hover:bg-gray-100 text-gray-700 border-transparent",
|
||||
outline: "bg-white hover:bg-gray-50 text-gray-700 border-gray-300",
|
||||
};
|
||||
|
||||
const sizeClasses: Record<string, string> = {
|
||||
sm: "px-3 py-1.5 text-sm",
|
||||
md: "px-4 py-2 text-sm",
|
||||
lg: "px-6 py-3 text-base",
|
||||
};
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ variant = "primary", size = "md", isLoading, className, children, disabled, ...props }, ref) => {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
disabled={disabled || isLoading}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center gap-2 rounded-lg border font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 disabled:opacity-50 disabled:cursor-not-allowed",
|
||||
variantClasses[variant],
|
||||
sizeClasses[size],
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{isLoading && (
|
||||
<svg className="animate-spin h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||
</svg>
|
||||
)}
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Button.displayName = "Button";
|
||||
34
src/components/ui/Card.tsx
Normal file
34
src/components/ui/Card.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface CardProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
export function Card({ children, className, onClick }: CardProps) {
|
||||
return (
|
||||
<div
|
||||
className={cn("rounded-xl border border-gray-200 bg-white shadow-sm", className)}
|
||||
onClick={onClick}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CardHeader({ children, className }: CardProps) {
|
||||
return (
|
||||
<div className={cn("flex items-center justify-between border-b border-gray-100 px-6 py-4", className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CardTitle({ children, className }: CardProps) {
|
||||
return <h3 className={cn("text-base font-semibold text-gray-900", className)}>{children}</h3>;
|
||||
}
|
||||
|
||||
export function CardContent({ children, className }: CardProps) {
|
||||
return <div className={cn("px-6 py-4", className)}>{children}</div>;
|
||||
}
|
||||
39
src/components/ui/Input.tsx
Normal file
39
src/components/ui/Input.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
import { InputHTMLAttributes, forwardRef } from "react";
|
||||
|
||||
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
||||
label?: string;
|
||||
error?: string;
|
||||
hint?: string;
|
||||
}
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
({ label, error, hint, className, id, ...props }, ref) => {
|
||||
const inputId = id || label?.toLowerCase().replace(/\s+/g, "-");
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{label && (
|
||||
<label htmlFor={inputId} className="text-sm font-medium text-gray-700">
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<input
|
||||
ref={ref}
|
||||
id={inputId}
|
||||
className={cn(
|
||||
"block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400",
|
||||
"focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",
|
||||
"disabled:bg-gray-50 disabled:cursor-not-allowed",
|
||||
error && "border-red-500 focus:border-red-500 focus:ring-red-500",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
{error && <p className="text-xs text-red-600">{error}</p>}
|
||||
{hint && !error && <p className="text-xs text-gray-500">{hint}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Input.displayName = "Input";
|
||||
48
src/components/ui/Modal.tsx
Normal file
48
src/components/ui/Modal.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { X } from "lucide-react";
|
||||
|
||||
interface ModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
title: string;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Modal({ isOpen, onClose, title, children, className }: ModalProps) {
|
||||
const overlayRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") onClose();
|
||||
};
|
||||
if (isOpen) document.addEventListener("keydown", handleKey);
|
||||
return () => document.removeEventListener("keydown", handleKey);
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={overlayRef}
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
|
||||
onClick={(e) => e.target === overlayRef.current && onClose()}
|
||||
>
|
||||
<div className={cn("w-full max-w-lg rounded-xl bg-white shadow-xl", className)}>
|
||||
<div className="flex items-center justify-between border-b border-gray-100 px-6 py-4">
|
||||
<h3 className="text-base font-semibold text-gray-900">{title}</h3>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="rounded-lg p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="px-6 py-4">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
58
src/components/ui/Table.tsx
Normal file
58
src/components/ui/Table.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface TableProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Table({ children, className }: TableProps) {
|
||||
return (
|
||||
<div className="overflow-x-auto rounded-xl border border-gray-200 bg-white">
|
||||
<table className={cn("w-full text-sm", className)}>
|
||||
{children}
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TableHead({ children }: TableProps) {
|
||||
return <thead className="bg-gray-50 text-xs uppercase text-gray-500">{children}</thead>;
|
||||
}
|
||||
|
||||
export function TableBody({ children }: TableProps) {
|
||||
return <tbody className="divide-y divide-gray-100">{children}</tbody>;
|
||||
}
|
||||
|
||||
export function TableRow({ children, className, onClick }: TableProps & { onClick?: () => void }) {
|
||||
return (
|
||||
<tr
|
||||
className={cn("transition-colors", onClick && "cursor-pointer hover:bg-blue-50", className)}
|
||||
onClick={onClick}
|
||||
>
|
||||
{children}
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
export function Th({ children, className }: TableProps) {
|
||||
return <th className={cn("px-4 py-3 text-left font-medium", className)}>{children}</th>;
|
||||
}
|
||||
|
||||
export function Td({ children, className }: TableProps) {
|
||||
return <td className={cn("px-4 py-3 text-gray-700", className)}>{children}</td>;
|
||||
}
|
||||
|
||||
export function EmptyState({ message = "No data yet" }: { message?: string }) {
|
||||
return (
|
||||
<tr>
|
||||
<td colSpan={100} className="py-12 text-center text-gray-400">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<svg className="h-12 w-12 text-gray-300" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4" />
|
||||
</svg>
|
||||
<span className="text-sm">{message}</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
71
src/contexts/AuthContext.tsx
Normal file
71
src/contexts/AuthContext.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
"use client";
|
||||
|
||||
import React, { createContext, useContext, useState, useEffect, useCallback } from "react";
|
||||
import api from "@/lib/api";
|
||||
import type { AuthState, User } from "@/types";
|
||||
|
||||
const AuthContext = createContext<AuthState | null>(null);
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [accessToken, setAccessToken] = useState<string | null>(null);
|
||||
const [tenantSlug, setTenantSlug] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const token = localStorage.getItem("accessToken");
|
||||
const slug = localStorage.getItem("tenantSlug");
|
||||
const storedUser = localStorage.getItem("user");
|
||||
if (token && slug && storedUser) {
|
||||
setAccessToken(token);
|
||||
setTenantSlug(slug);
|
||||
try {
|
||||
setUser(JSON.parse(storedUser) as User);
|
||||
} catch {
|
||||
// ignore parse error
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
const login = useCallback(async (slug: string, email: string, password: string) => {
|
||||
const res = await api.post<{ accessToken: string; refreshToken: string; user: User }>(
|
||||
"/api/v1/auth/login",
|
||||
{ tenantSlug: slug, email, password }
|
||||
);
|
||||
const { accessToken: token, user: userData } = res.data;
|
||||
localStorage.setItem("accessToken", token);
|
||||
localStorage.setItem("tenantSlug", slug);
|
||||
localStorage.setItem("user", JSON.stringify(userData));
|
||||
setAccessToken(token);
|
||||
setTenantSlug(slug);
|
||||
setUser(userData);
|
||||
}, []);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
localStorage.clear();
|
||||
setAccessToken(null);
|
||||
setTenantSlug(null);
|
||||
setUser(null);
|
||||
window.location.href = "/login";
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
value={{
|
||||
user,
|
||||
accessToken,
|
||||
tenantSlug,
|
||||
isAuthenticated: !!accessToken,
|
||||
login,
|
||||
logout,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAuth(): AuthState {
|
||||
const ctx = useContext(AuthContext);
|
||||
if (!ctx) throw new Error("useAuth must be used within AuthProvider");
|
||||
return ctx;
|
||||
}
|
||||
39
src/lib/api.ts
Normal file
39
src/lib/api.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL || 'https://fiberops-api.juankibin.space',
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
if (typeof window !== 'undefined') {
|
||||
// Support both auth patterns: zustand persist key and direct localStorage
|
||||
const authRaw = localStorage.getItem('fiberops_auth');
|
||||
const token = authRaw
|
||||
? JSON.parse(authRaw)?.state?.accessToken
|
||||
: localStorage.getItem('accessToken');
|
||||
const tenantSlug = authRaw
|
||||
? JSON.parse(authRaw)?.state?.tenantSlug
|
||||
: localStorage.getItem('tenantSlug');
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`;
|
||||
if (tenantSlug) {
|
||||
config.headers['x-tenant-slug'] = tenantSlug;
|
||||
config.headers['X-Tenant-Slug'] = tenantSlug;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
api.interceptors.response.use(
|
||||
(res) => res,
|
||||
(err) => {
|
||||
if (err.response?.status === 401 && typeof window !== 'undefined') {
|
||||
localStorage.removeItem('fiberops_auth');
|
||||
localStorage.removeItem('accessToken');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
|
||||
export { api };
|
||||
export default api;
|
||||
31
src/lib/utils.ts
Normal file
31
src/lib/utils.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export function formatCurrency(amount: number): string {
|
||||
return new Intl.NumberFormat("en-PH", {
|
||||
style: "currency",
|
||||
currency: "PHP",
|
||||
}).format(amount);
|
||||
}
|
||||
|
||||
export function formatDate(date: string | Date): string {
|
||||
return new Intl.DateTimeFormat("en-PH", {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
}).format(new Date(date));
|
||||
}
|
||||
|
||||
export function formatDateTime(date: string | Date): string {
|
||||
return new Intl.DateTimeFormat("en-PH", {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
}).format(new Date(date));
|
||||
}
|
||||
209
src/types/index.ts
Normal file
209
src/types/index.ts
Normal file
@@ -0,0 +1,209 @@
|
||||
export interface User {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone?: string;
|
||||
isActive: boolean;
|
||||
lastLoginAt?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
roleAssignments?: RoleAssignment[];
|
||||
}
|
||||
|
||||
export interface RoleAssignment {
|
||||
id: string;
|
||||
userId: string;
|
||||
role: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface AuthUser {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
name?: string;
|
||||
role?: string;
|
||||
}
|
||||
|
||||
export interface AuthState {
|
||||
user: AuthUser | null;
|
||||
accessToken: string | null;
|
||||
tenantSlug: string | null;
|
||||
isAuthenticated: boolean;
|
||||
login: (tenantSlug: string, email: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export interface Client {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
accountNumber: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
address?: string;
|
||||
isActive: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
area?: { id: string; name: string };
|
||||
subscriptions?: Subscription[];
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
id: string;
|
||||
clientId: string;
|
||||
planId: string;
|
||||
plan?: Plan;
|
||||
status: string;
|
||||
type?: string;
|
||||
startDate: string;
|
||||
endDate?: string;
|
||||
monthlyRate?: number;
|
||||
mrc?: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Plan {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
speedDownMbps: number;
|
||||
speedUpMbps: number;
|
||||
monthlyPrice: number;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export interface Invoice {
|
||||
id: string;
|
||||
invoiceNumber?: string;
|
||||
clientId: string;
|
||||
client?: { firstName: string; lastName: string; accountNumber: string };
|
||||
amount: number;
|
||||
totalAmount?: number;
|
||||
dueDate: string;
|
||||
status: string;
|
||||
paidAt?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Payment {
|
||||
id: string;
|
||||
clientId: string;
|
||||
client?: { firstName: string; lastName: string; accountNumber: string };
|
||||
amount: number;
|
||||
channel: string;
|
||||
reference?: string;
|
||||
referenceNumber?: string;
|
||||
status: string;
|
||||
date?: string;
|
||||
paymentDate?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Ticket {
|
||||
id: string;
|
||||
ticketNumber?: string;
|
||||
subject: string;
|
||||
description?: string;
|
||||
clientId?: string;
|
||||
client?: { id: string; firstName: string; lastName: string; accountNumber: string };
|
||||
type: string;
|
||||
priority: string;
|
||||
status: string;
|
||||
assignedToId?: string;
|
||||
assignedTo?: { id: string; firstName: string; lastName: string } | string;
|
||||
assignedUser?: { id: string; firstName: string; lastName: string };
|
||||
createdById?: string;
|
||||
createdBy?: { firstName: string; lastName: string };
|
||||
resolvedAt?: string;
|
||||
updatedAt?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Remittance {
|
||||
id: string;
|
||||
collectorId?: string;
|
||||
collector?: { firstName: string; lastName: string };
|
||||
amount: number | string;
|
||||
notes?: string;
|
||||
status: string;
|
||||
payments?: Payment[];
|
||||
createdAt: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
id: string;
|
||||
title: string;
|
||||
type: string;
|
||||
status: string;
|
||||
assignedTo?: string;
|
||||
assignedUser?: { firstName: string; lastName: string };
|
||||
dueDate?: string;
|
||||
ticketId?: string;
|
||||
ticket?: { subject: string };
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface AuditLog {
|
||||
id: string;
|
||||
userId?: string;
|
||||
user?: { firstName: string; lastName: string; email: string };
|
||||
action: string;
|
||||
entity?: string;
|
||||
entityType?: string;
|
||||
entityId?: string;
|
||||
details?: Record<string, unknown>;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface DashboardSummary {
|
||||
subscribers: {
|
||||
total: number;
|
||||
active: number;
|
||||
pending: number;
|
||||
suspended: number;
|
||||
};
|
||||
billing: {
|
||||
unpaidInvoices: number;
|
||||
overdueInvoices: number;
|
||||
};
|
||||
support: {
|
||||
openTickets: number;
|
||||
inProgressTickets: number;
|
||||
};
|
||||
tasks: {
|
||||
pending: number;
|
||||
};
|
||||
revenue: {
|
||||
thisMonth: number;
|
||||
lastMonth: number;
|
||||
growth: number | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[];
|
||||
meta: Meta;
|
||||
}
|
||||
|
||||
// For /users which returns plain array
|
||||
export type UsersResponse = User[];
|
||||
|
||||
// For invoices/payments which return { data, total, page, limit }
|
||||
export interface LegacyPaginatedResponse<T> {
|
||||
data: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"strict": false,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
@@ -12,14 +12,11 @@
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"plugins": [{ "name": "next" }],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
"@/*": ["./src/*", "./*"]
|
||||
},
|
||||
"target": "ES2017"
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
Reference in New Issue
Block a user