1 parent
27de078f54
commit
e85e4d74ea
378 files changed
+20710
-22428
No files matched your search
@@ -1,43 +1,49 @@
|
||||
"use client";
|
||||
'use client'
|
||||
|
||||
import { Ban, ShieldOff } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { banUser, unbanUser } from "@/actions/users";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
import { Ban, ShieldOff } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { banUser, unbanUser } from '@/actions/users'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { useServerAction } from '@/hooks/use-server-action'
|
||||
|
||||
interface BanInfo {
|
||||
id: number;
|
||||
reason: string;
|
||||
type: string;
|
||||
staffName: string;
|
||||
timestamp: number;
|
||||
banExpire: number;
|
||||
id: number
|
||||
reason: string
|
||||
type: string
|
||||
staffName: string
|
||||
timestamp: number
|
||||
banExpire: number
|
||||
}
|
||||
|
||||
interface UserBanSectionProps {
|
||||
userId: number;
|
||||
username: string;
|
||||
bans: BanInfo[];
|
||||
userId: number
|
||||
username: string
|
||||
bans: BanInfo[]
|
||||
}
|
||||
|
||||
export function UserBanSection({ userId, username, bans }: UserBanSectionProps) {
|
||||
const { isPending, run } = useServerAction();
|
||||
const [showBanForm, setShowBanForm] = useState(false);
|
||||
const [reason, setReason] = useState("");
|
||||
const [duration, setDuration] = useState("24");
|
||||
const [banType, setBanType] = useState("account");
|
||||
const { isPending, run } = useServerAction()
|
||||
const [showBanForm, setShowBanForm] = useState(false)
|
||||
const [reason, setReason] = useState('')
|
||||
const [duration, setDuration] = useState('24')
|
||||
const [banType, setBanType] = useState('account')
|
||||
|
||||
const activeBan = bans.find((b) => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
return b.banExpire === 0 || b.banExpire > now;
|
||||
});
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
return b.banExpire === 0 || b.banExpire > now
|
||||
})
|
||||
|
||||
function handleBan() {
|
||||
run(
|
||||
@@ -46,22 +52,22 @@ export function UserBanSection({ userId, username, bans }: UserBanSectionProps)
|
||||
userId,
|
||||
reason,
|
||||
duration: parseInt(duration, 10),
|
||||
type: banType as "account" | "ip" | "machine",
|
||||
type: banType as 'account' | 'ip' | 'machine',
|
||||
}),
|
||||
{
|
||||
successMessage: `${username} has been banned.`,
|
||||
onSuccess: () => {
|
||||
setShowBanForm(false);
|
||||
setReason("");
|
||||
setShowBanForm(false)
|
||||
setReason('')
|
||||
},
|
||||
},
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function handleUnban() {
|
||||
run(() => unbanUser({ userId }), {
|
||||
successMessage: `${username} has been unbanned.`,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -88,9 +94,9 @@ export function UserBanSection({ userId, username, bans }: UserBanSectionProps)
|
||||
<p className="text-sm font-medium text-destructive">Active Ban</p>
|
||||
<p className="text-sm">{activeBan.reason}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
By {activeBan.staffName} ·{" "}
|
||||
By {activeBan.staffName} ·{' '}
|
||||
{activeBan.banExpire === 0
|
||||
? "Permanent"
|
||||
? 'Permanent'
|
||||
: `Expires ${new Date(activeBan.banExpire * 1000).toLocaleString()}`}
|
||||
</p>
|
||||
</div>
|
||||
@@ -131,7 +137,7 @@ export function UserBanSection({ userId, username, bans }: UserBanSectionProps)
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="destructive" onClick={handleBan} disabled={isPending || !reason}>
|
||||
{isPending ? "Banning..." : "Confirm Ban"}
|
||||
{isPending ? 'Banning...' : 'Confirm Ban'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
@@ -156,5 +162,5 @@ export function UserBanSection({ userId, username, bans }: UserBanSectionProps)
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user