|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import { FC } from 'react'; |
| 3 | +import { FC, useState } from 'react'; |
4 | 4 | import { Button } from '@/components/ui/Button'; |
5 | | -import { CheckCircle, XCircle } from 'lucide-react'; |
| 5 | +import { CheckCircle, XCircle, Ban } from 'lucide-react'; |
| 6 | +import { ConfirmModal } from '@/components/modals/ConfirmModal'; |
| 7 | +import { UserModerationService } from '@/services/user-moderation.service'; |
| 8 | +import { cn } from '@/utils/styles'; |
| 9 | +import { toast } from 'react-hot-toast'; |
6 | 10 |
|
7 | 11 | interface ModerationActionsProps { |
8 | 12 | onDismiss: () => void; |
9 | 13 | onRemove: () => void; |
| 14 | + onRefresh?: () => void; |
10 | 15 | view?: 'pending' | 'dismissed' | 'removed'; |
11 | 16 | hasVerdict?: boolean; |
12 | 17 | className?: string; |
| 18 | + authorId?: number | null; |
| 19 | + authorName?: string; |
13 | 20 | } |
14 | 21 |
|
15 | 22 | export const ModerationActions: FC<ModerationActionsProps> = ({ |
16 | 23 | onDismiss, |
17 | 24 | onRemove, |
| 25 | + onRefresh, |
18 | 26 | view = 'pending', |
19 | 27 | hasVerdict = false, |
20 | | - className = '', |
| 28 | + className, |
| 29 | + authorId, |
| 30 | + authorName, |
21 | 31 | }) => { |
22 | | - // Only show action buttons for pending items without verdicts |
23 | | - const showActionButtons = view === 'pending' && !hasVerdict; |
| 32 | + const [showSuspendConfirm, setShowSuspendConfirm] = useState(false); |
24 | 33 |
|
25 | | - if (!showActionButtons) { |
| 34 | + if (view !== 'pending' || hasVerdict) { |
26 | 35 | return null; |
27 | 36 | } |
28 | 37 |
|
| 38 | + const handleSuspendUser = async () => { |
| 39 | + if (!authorId) return; |
| 40 | + try { |
| 41 | + await UserModerationService.suspendUser(String(authorId)); |
| 42 | + toast.success('User has been suspended'); |
| 43 | + onRefresh?.(); |
| 44 | + } catch (error) { |
| 45 | + console.error('Failed to suspend user:', error); |
| 46 | + toast.error('Failed to suspend user'); |
| 47 | + } |
| 48 | + }; |
| 49 | + |
29 | 50 | return ( |
30 | | - <div className={`flex items-center space-x-2 ${className}`}> |
31 | | - <Button |
32 | | - variant="ghost" |
33 | | - size="sm" |
34 | | - onClick={onDismiss} |
35 | | - className="text-green-600 hover:text-green-700 hover:bg-green-50" |
36 | | - > |
37 | | - <CheckCircle className="h-4 w-4 mr-1" /> |
38 | | - Dismiss |
39 | | - </Button> |
40 | | - |
41 | | - <Button |
42 | | - variant="ghost" |
43 | | - size="sm" |
44 | | - onClick={onRemove} |
45 | | - className="text-red-600 hover:text-red-700 hover:bg-red-50" |
46 | | - > |
47 | | - <XCircle className="h-4 w-4 mr-1" /> |
48 | | - Remove |
49 | | - </Button> |
50 | | - </div> |
| 51 | + <> |
| 52 | + <div className={cn('flex items-center space-x-2', className)}> |
| 53 | + <Button |
| 54 | + variant="ghost" |
| 55 | + size="sm" |
| 56 | + onClick={onDismiss} |
| 57 | + className="text-green-600 hover:text-green-700 hover:bg-green-50" |
| 58 | + > |
| 59 | + <CheckCircle className="h-4 w-4 mr-1" /> |
| 60 | + Dismiss |
| 61 | + </Button> |
| 62 | + |
| 63 | + <Button |
| 64 | + variant="ghost" |
| 65 | + size="sm" |
| 66 | + onClick={onRemove} |
| 67 | + className="text-red-600 hover:text-red-700 hover:bg-red-50" |
| 68 | + > |
| 69 | + <XCircle className="h-4 w-4 mr-1" /> |
| 70 | + Remove |
| 71 | + </Button> |
| 72 | + |
| 73 | + {authorId && ( |
| 74 | + <Button |
| 75 | + variant="ghost" |
| 76 | + size="sm" |
| 77 | + onClick={() => setShowSuspendConfirm(true)} |
| 78 | + className="text-red-600 hover:text-red-700 hover:bg-red-50" |
| 79 | + > |
| 80 | + <Ban className="h-4 w-4 mr-1" /> |
| 81 | + Remove + Suspend |
| 82 | + </Button> |
| 83 | + )} |
| 84 | + </div> |
| 85 | + |
| 86 | + {authorId && ( |
| 87 | + <ConfirmModal |
| 88 | + isOpen={showSuspendConfirm} |
| 89 | + onClose={() => setShowSuspendConfirm(false)} |
| 90 | + onConfirm={handleSuspendUser} |
| 91 | + title="Remove + Suspend" |
| 92 | + message={`Are you sure you want to suspend ${authorName || 'this user'}? This will remove their content and prevent them from using the platform.`} |
| 93 | + confirmText="Remove + Suspend" |
| 94 | + confirmButtonClass="bg-red-600 hover:bg-red-700" |
| 95 | + /> |
| 96 | + )} |
| 97 | + </> |
51 | 98 | ); |
52 | 99 | }; |
0 commit comments