-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentsModeration.tsx
More file actions
210 lines (199 loc) · 8.54 KB
/
CommentsModeration.tsx
File metadata and controls
210 lines (199 loc) · 8.54 KB
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
"use client"
import { useMemo } from 'react'
import { Check, Loader2, MessageSquareWarning, RefreshCcw, Trash2, XCircle } from 'lucide-react'
import { CommentStatus, type AdminCommentSummary } from '@/utils/types'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
interface CommentsModerationProps {
comments: AdminCommentSummary[]
isLoading: boolean
activeFilter: CommentStatus | 'all'
onChangeFilter: (filter: CommentStatus | 'all') => void
onRefresh: () => void
onApprove: (id: string) => void
onReject: (id: string) => void
onDelete: (id: string) => void
}
const FILTER_OPTIONS: { label: string; value: CommentStatus | 'all' }[] = [
{ label: 'All', value: 'all' },
{ label: 'Pending', value: CommentStatus.PENDING },
{ label: 'Approved', value: CommentStatus.APPROVED },
{ label: 'Rejected', value: CommentStatus.REJECTED },
]
const STATUS_STYLES: Record<
CommentStatus,
{ badge: string; badgeText: string; row: string }
> = {
[CommentStatus.PENDING]: {
badge:
'border-amber-400/60 bg-amber-50 text-amber-700 dark:border-amber-300/50 dark:bg-amber-400/20 dark:text-amber-100',
badgeText: 'Pending',
row: 'bg-white dark:bg-slate-900/70',
},
[CommentStatus.APPROVED]: {
badge:
'border-emerald-400/60 bg-emerald-50 text-emerald-700 dark:border-emerald-300/40 dark:bg-emerald-400/20 dark:text-emerald-100',
badgeText: 'Approved',
row:
'bg-emerald-50/60 dark:bg-emerald-500/15 border-l-4 border-emerald-400/70 dark:border-emerald-300/60',
},
[CommentStatus.REJECTED]: {
badge:
'border-rose-400/60 bg-rose-50 text-rose-700 dark:border-rose-300/40 dark:bg-rose-400/20 dark:text-rose-100',
badgeText: 'Rejected',
row:
'bg-rose-50/60 dark:bg-rose-500/15 border-l-4 border-rose-400/70 dark:border-rose-300/60',
},
}
export const CommentsModeration = ({
comments,
isLoading,
activeFilter,
onChangeFilter,
onRefresh,
onApprove,
onReject,
onDelete,
}: CommentsModerationProps) => {
const filtered = useMemo(() => {
if (activeFilter === 'all') {
return comments
}
return comments.filter((comment) => comment.status === activeFilter)
}, [activeFilter, comments])
return (
<div className="space-y-6">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<h1 className="text-3xl font-bold text-[#2A2A2A]">Comment moderation</h1>
<p className="text-sm text-[#2A2A2A]/70">
Approve, reject, or remove reader feedback across the blog.
</p>
</div>
<button
type="button"
onClick={() => onRefresh()}
className="inline-flex items-center gap-2 rounded-md border-2 border-[#6C63FF] px-4 py-2 font-semibold text-[#6C63FF] transition hover:-translate-y-[1px] hover:bg-[#6C63FF]/10"
>
<RefreshCcw className="h-4 w-4" aria-hidden="true" /> Refresh
</button>
</div>
<div className="flex flex-wrap items-center gap-2">
{FILTER_OPTIONS.map((option) => (
<button
key={option.value}
type="button"
onClick={() => onChangeFilter(option.value)}
className={`rounded-full border-2 px-4 py-1 text-sm font-semibold transition ${
activeFilter === option.value
? 'border-black bg-black text-white'
: 'border-black/20 bg-white text-[#2A2A2A] hover:border-black/40'
}`}
>
{option.label}
</button>
))}
</div>
<div className="rounded-xl border-4 border-black bg-white">
<div className="border-b-4 border-black bg-[#f3f3ff] px-4 py-3 text-sm font-semibold uppercase tracking-wide text-[#2A2A2A]/80">
{isLoading ? 'Loading comments…' : `${filtered.length} ${filtered.length === 1 ? 'comment' : 'comments'}`}
</div>
{isLoading ? (
<div className="flex items-center gap-3 px-6 py-8 text-[#2A2A2A]/80">
<Loader2 className="h-5 w-5 animate-spin" aria-hidden="true" /> Loading comment feed…
</div>
) : filtered.length === 0 ? (
<div className="flex flex-col items-center gap-3 px-6 py-16 text-center text-[#2A2A2A]/70">
<MessageSquareWarning className="h-10 w-10 text-[#6C63FF]" aria-hidden="true" />
<p className="text-base font-semibold">No comments match this filter yet.</p>
<p className="text-sm">Try selecting another status or check back after readers chime in.</p>
</div>
) : (
<ul className="divide-y-4 divide-black/5">
{filtered.map((comment) => (
<li
key={comment.id}
className={`grid gap-3 px-6 py-5 transition-shadow md:grid-cols-[minmax(0,1fr)_auto] md:items-center ${
STATUS_STYLES[comment.status].row
}`}
>
<div className="space-y-2">
<div className="flex flex-wrap items-center gap-2 text-xs uppercase tracking-wide text-[#2A2A2A]/70">
<span
className={`rounded-full border px-2 py-0.5 font-semibold ${
STATUS_STYLES[comment.status].badge
}`}
>
{STATUS_STYLES[comment.status].badgeText}
</span>
<span className="font-semibold text-[#2A2A2A]">
{comment.authorDisplayName ?? 'Community member'}
</span>
<span aria-hidden="true">•</span>
<span>{new Date(comment.createdAt).toLocaleString()}</span>
</div>
<p className="text-sm text-[#2A2A2A]">{comment.content}</p>
<p className="text-xs text-[#2A2A2A]/60">
On <span className="font-semibold">{comment.postTitle}</span>
</p>
</div>
<div className="flex flex-wrap items-center justify-end gap-2">
<button
type="button"
onClick={() => onApprove(comment.id)}
className="inline-flex items-center gap-1 rounded-md border-2 border-green-500/40 px-3 py-1 text-sm font-semibold text-green-600 transition hover:bg-green-50"
disabled={comment.status === CommentStatus.APPROVED}
>
<Check className="h-4 w-4" aria-hidden="true" /> Approve
</button>
<button
type="button"
onClick={() => onReject(comment.id)}
className="inline-flex items-center gap-1 rounded-md border-2 border-amber-500/40 px-3 py-1 text-sm font-semibold text-amber-600 transition hover:bg-amber-50"
disabled={comment.status === CommentStatus.REJECTED}
>
<XCircle className="h-4 w-4" aria-hidden="true" /> Reject
</button>
<AlertDialog>
<AlertDialogTrigger asChild>
<button
type="button"
className="inline-flex items-center gap-1 rounded-md border-2 border-red-500/40 px-3 py-1 text-sm font-semibold text-red-600 transition hover:bg-red-50"
>
<Trash2 className="h-4 w-4" aria-hidden="true" /> Delete
</button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete comment?</AlertDialogTitle>
<AlertDialogDescription>
This will permanently delete this comment from {comment.authorDisplayName ?? 'this reader'}. This
action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={() => onDelete(comment.id)}>
Delete Comment
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</li>
))}
</ul>
)}
</div>
</div>
)
}