import * as React from 'react' import { Link } from '@tanstack/react-router' import { twMerge } from 'tailwind-merge' import { Table, TableHeader, TableHeaderRow, TableHeaderCell, TableBody, TableRow, TableCell, } from './TableComponents' import { PaginationControls } from './PaginationControls' import { Spinner } from './Spinner' import type { DocFeedback } from '~/db/types' import { calculatePoints } from '~/utils/docFeedback.shared' import { getRowFieldId } from '~/utils/route-encoding' import { CheckIcon, LightbulbIcon, WarningIcon } from '@phosphor-icons/react' import { ChatCenteredIcon, XIcon } from '@phosphor-icons/react' import { Badge, Button } from '~/ui' interface FeedbackModerationListProps { data: | { feedback: Array<{ feedback: DocFeedback user: { id: string name: string | null email: string image: string | null } | null }> pagination: { page: number pageSize: number total: number totalPages: number } } | undefined isLoading: boolean error: Error | null page: number pageSize: number onPageChange: (page: number) => void onPageSizeChange: (pageSize: number) => void onModerate: ( feedbackId: string, action: 'approve' | 'deny', note?: string, ) => void isModeratingId?: string } export function FeedbackModerationList({ data, isLoading, error, page, pageSize, onPageChange, onPageSizeChange, onModerate, isModeratingId, }: FeedbackModerationListProps) { const [expandedIds, setExpandedIds] = React.useState>(new Set()) const [moderationNotes, setModerationNotes] = React.useState< Record >({}) const toggleExpanded = (id: string) => { setExpandedIds((prev) => { const next = new Set(prev) if (next.has(id)) { next.delete(id) } else { next.add(id) } return next }) } const handleModerationNoteChange = (feedbackId: string, note: string) => { setModerationNotes((prev) => ({ ...prev, [feedbackId]: note })) } const handleModerate = (feedbackId: string, action: 'approve' | 'deny') => { const note = moderationNotes[feedbackId] onModerate(feedbackId, action, note) // Clear note after submission setModerationNotes((prev) => { const next = { ...prev } delete next[feedbackId] return next }) } if (error) { return (

Failed to load feedback: {error.message}

) } const feedbackList = data?.feedback || [] const pagination = data?.pagination || { page: 1, pageSize: 50, total: 0, totalPages: 0, } if (isLoading) { return (

Loading feedback...

) } if (feedbackList.length === 0) { return (

No feedback found matching the current filters.

) } return ( <> # Type Status User Library Points Date Actions {feedbackList.map((entry, index) => { const { feedback, user } = entry const isExpanded = expandedIds.has(feedback.id) const isPending = feedback.status === 'pending' const isModeratingThis = isModeratingId === feedback.id const moderationNoteId = getRowFieldId( 'feedback-moderation', feedback.id, 'note', ) return ( toggleExpanded(feedback.id)} > e.stopPropagation()} > {(page - 1) * pageSize + index + 1} e.stopPropagation()} > {feedback.type === 'note' ? ( ) : ( )} {feedback.type === 'note' ? 'Note' : 'Improvement'} {feedback.status.charAt(0).toUpperCase() + feedback.status.slice(1)}
{user?.name || 'Unknown'}
{user?.email}
{feedback.libraryId} {feedback.isDetached && (
Detached
)}
{calculatePoints( feedback.characterCount, feedback.type, ).toFixed(1)} {new Date(feedback.createdAt).toLocaleDateString()} e.stopPropagation()}> {isPending && !isModeratingThis && (
)} {isModeratingThis && (
Processing...
)} {!isPending && (
{feedback.status === 'approved' ? 'Approved' : 'Denied'}
)}
{isExpanded && (
{/* Original Block Content */} {feedback.blockMarkdown && (

Original Block Content:

{feedback.blockMarkdown}
)} {/* Feedback */}

Feedback:

{feedback.content}
{/* Location */}

Location:

Path: {' '} {feedback.pagePath}
Version: {' '} {feedback.libraryVersion}
Selector: {' '} {feedback.blockSelector}
{/* Moderation Note Input (for pending only) */} {isPending && (