Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | 1x 337x 337x 337x 337x 337x 337x 337x 9x 337x 337x 337x 10x 4x 4x 2x 16x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 4x 4x 3x 1x 64x 3x 3x 1x 1x 327x 1x 4x | import { useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { MessageSquareText, ChevronDown, ChevronRight } from "lucide-react";
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "../../components/ui/card";
import { Button } from "../../components/ui/button";
import { EmptyState } from "../../components/ui/empty-state";
import { cn } from "../../lib/utils";
import { adminApi, type FeedbackEntry } from "../../lib/api";
import { queryKeys } from "../../lib/query-keys";
import {
useAdminFeedback,
type FeedbackFilters,
} from "../../hooks/queries/useAdminQueries";
const PAGE_SIZE = 20;
// ─── Status badge ────────────────────────────────────────────────────────────
function StatusBadge({ status }: { status: string }) {
const classes: Record<string, string> = {
new: "bg-blue-100 text-blue-800",
reviewed: "bg-yellow-100 text-yellow-800",
resolved: "bg-green-100 text-green-800",
};
const cls = classes[status] ?? "bg-gray-100 text-gray-600";
return (
<span
className={cn(
"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium capitalize",
cls,
)}
>
{status}
</span>
);
}
// ─── Category badge ──────────────────────────────────────────────────────────
function CategoryBadge({ category }: { category: string }) {
const classes: Record<string, string> = {
general: "bg-gray-100 text-gray-700",
bug: "bg-red-100 text-red-700",
feature_request: "bg-purple-100 text-purple-700",
};
const cls = classes[category] ?? "bg-gray-100 text-gray-600";
const labels: Record<string, string> = {
general: "General",
bug: "Bug",
feature_request: "Feature Request",
};
return (
<span
className={cn(
"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",
cls,
)}
>
{labels[category] ?? category}
</span>
);
}
// ─── Row detail panel ────────────────────────────────────────────────────────
function RowDetail({ entry }: { entry: FeedbackEntry }) {
return (
<tr>
<td colSpan={7} className="px-4 pb-4 pt-0">
<div className="rounded-lg bg-background-subtle border border-border-default p-4 text-sm space-y-3">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
{entry.browser && (
<div>
<span className="text-foreground-muted font-medium">Browser:</span>{" "}
<span className="text-foreground-default">{entry.browser}</span>
</div>
)}
{entry.screenResolution && (
<div>
<span className="text-foreground-muted font-medium">Resolution:</span>{" "}
<span className="text-foreground-default">{entry.screenResolution}</span>
</div>
)}
{entry.location && (
<div>
<span className="text-foreground-muted font-medium">Timezone:</span>{" "}
<span className="text-foreground-default">{entry.location}</span>
</div>
)}
{entry.userId && (
<div>
<span className="text-foreground-muted font-medium">User ID:</span>{" "}
<span className="font-mono text-xs text-foreground-default">{entry.userId}</span>
</div>
)}
{entry.proId && (
<div>
<span className="text-foreground-muted font-medium">Pro ID:</span>{" "}
<span className="font-mono text-xs text-foreground-default">{entry.proId}</span>
</div>
)}
</div>
<div>
<p className="text-foreground-muted font-medium mb-1">Full Message:</p>
<p className="text-foreground-default whitespace-pre-wrap text-xs bg-background-base rounded p-2">
{entry.message}
</p>
</div>
</div>
</td>
</tr>
);
}
// ─── Table row ───────────────────────────────────────────────────────────────
function FeedbackRow({
entry,
onStatusChange,
}: {
entry: FeedbackEntry;
onStatusChange: (id: number, status: string) => void;
}) {
const [expanded, setExpanded] = useState(false);
const nextStatus: Record<string, string> = {
new: "reviewed",
reviewed: "resolved",
};
return (
<>
<tr
className="cursor-pointer hover:bg-background-muted transition-colors"
onClick={() => setExpanded((v) => !v)}
>
<td className="px-4 py-3 text-xs text-foreground-muted whitespace-nowrap">
{new Date(entry.createdAt).toLocaleString()}
</td>
<td className="px-4 py-3">
<CategoryBadge category={entry.category} />
</td>
<td className="px-4 py-3 text-sm text-foreground-default max-w-xs truncate">
{entry.message}
</td>
<td className="px-4 py-3 text-sm text-foreground-muted font-mono text-xs">
{entry.userEmail ?? "—"}
</td>
<td className="px-4 py-3">
<StatusBadge status={entry.status} />
</td>
<td className="px-4 py-3 text-sm text-foreground-muted max-w-[200px] truncate">
{entry.pageUrl ?? "—"}
</td>
<td className="px-4 py-3">
<div className="flex items-center gap-2">
{nextStatus[entry.status] && (
<Button
variant="outline"
size="sm"
onClick={(e) => {
e.stopPropagation();
onStatusChange(entry.id, nextStatus[entry.status]);
}}
>
Mark {nextStatus[entry.status]}
</Button>
)}
{expanded ? (
<ChevronDown className="h-4 w-4 text-foreground-subtle" />
) : (
<ChevronRight className="h-4 w-4 text-foreground-subtle" />
)}
</div>
</td>
</tr>
{expanded && <RowDetail entry={entry} />}
</>
);
}
// ─── Skeleton rows ───────────────────────────────────────────────────────────
function SkeletonRows() {
return (
<>
{[1, 2, 3, 4, 5, 6, 7, 8].map((i) => (
<tr key={i}>
<td colSpan={7} className="px-4 py-3">
<div className="h-5 bg-background-muted rounded animate-pulse" />
</td>
</tr>
))}
</>
);
}
// ─── Main page ───────────────────────────────────────────────────────────────
export function AdminFeedbackPage() {
const queryClient = useQueryClient();
const [statusFilter, setStatusFilter] = useState("");
const [page, setPage] = useState(1);
const filters: FeedbackFilters = {
page,
limit: PAGE_SIZE,
status: statusFilter || undefined,
};
const { data, isLoading, error } = useAdminFeedback(filters);
const items: FeedbackEntry[] = data?.data ?? [];
const total = data?.meta?.total ?? 0;
const totalPages = data?.meta?.totalPages ?? 1;
const hasPrev = page > 1;
const hasNext = page < totalPages;
async function handleStatusChange(id: number, newStatus: string) {
try {
await adminApi.updateFeedbackStatus(id, newStatus);
queryClient.invalidateQueries({
queryKey: queryKeys.admin.feedback.all,
});
} catch (err) {
console.error("Failed to update feedback status:", err);
}
}
return (
<div className="space-y-6">
{/* Header */}
<div>
<h1 className="text-2xl font-bold text-foreground-default">
Feedback
</h1>
<p className="text-foreground-muted mt-1">
View and manage user feedback submissions.
</p>
</div>
{/* Filters */}
<Card>
<CardContent className="pt-6">
<div className="flex flex-col sm:flex-row gap-3">
<select
aria-label="Filter by status"
value={statusFilter}
onChange={(e) => {
setStatusFilter(e.target.value);
setPage(1);
}}
className="h-10 rounded-md border border-border-default bg-background-base px-3 py-2 text-sm text-foreground-default focus:outline-none focus:ring-2 focus:ring-primary-500"
>
<option value="">All Statuses</option>
<option value="new">New</option>
<option value="reviewed">Reviewed</option>
<option value="resolved">Resolved</option>
</select>
{statusFilter && (
<Button
variant="outline"
onClick={() => {
setStatusFilter("");
setPage(1);
}}
>
Clear
</Button>
)}
</div>
</CardContent>
</Card>
{/* Table */}
<Card>
<CardHeader>
<CardTitle className="text-lg">
{isLoading ? "Loading..." : `${total.toLocaleString()} feedback entries`}
</CardTitle>
</CardHeader>
<CardContent className="p-0">
{error ? (
<div className="p-6 text-sm text-notification-error-text bg-notification-error-bg border border-notification-error-border rounded-b-lg">
Failed to load feedback. Please refresh the page.
</div>
) : (
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead className="bg-background-subtle border-b border-border-default">
<tr>
<th className="px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider">
Date
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider">
Category
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider">
Message
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider">
Email
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider">
Status
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider">
Page URL
</th>
<th className="px-4 py-3 w-8" />
</tr>
</thead>
<tbody className="divide-y divide-border-default">
{isLoading ? (
<SkeletonRows />
) : items.length === 0 ? (
<tr>
<td colSpan={7} className="px-4 py-12">
<EmptyState
icon={MessageSquareText}
title="No feedback found"
description="Try adjusting your filters or check back later."
/>
</td>
</tr>
) : (
items.map((entry) => (
<FeedbackRow
key={entry.id}
entry={entry}
onStatusChange={handleStatusChange}
/>
))
)}
</tbody>
</table>
</div>
)}
{/* Pagination */}
{!isLoading && !error && total > PAGE_SIZE && (
<div className="flex items-center justify-between px-4 py-3 border-t border-border-default">
<p className="text-sm text-foreground-muted">
Page {page} of {totalPages} ({total.toLocaleString()} total)
</p>
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
onClick={() => setPage((p) => Math.max(1, p - 1))}
disabled={!hasPrev}
>
Previous
</Button>
<Button
variant="outline"
size="sm"
onClick={() => setPage((p) => p + 1)}
disabled={!hasNext}
>
Next
</Button>
</div>
</div>
)}
</CardContent>
</Card>
</div>
);
}
|