style: clean up code with prettier and eslint
This commit is contained in:
1 parent
60278b9e71
commit
fb8e77bb68
378 files changed
+22407
-20689
No files matched your search
@@ -1,10 +1,10 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { Loader2, UserPlus } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { createUser } from '@/actions/users'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Loader2, UserPlus } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { createUser } from "@/actions/users";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -12,75 +12,69 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { useServerAction } from '@/hooks/use-server-action'
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
|
||||
interface CreateUserDialogProps {
|
||||
sessionRank: number
|
||||
sessionRank: number;
|
||||
}
|
||||
|
||||
const RANK_OPTIONS: { value: number; label: string }[] = [
|
||||
{ value: 1, label: 'User (1)' },
|
||||
{ value: 2, label: 'Bronze (2)' },
|
||||
{ value: 3, label: 'Silver (3)' },
|
||||
{ value: 4, label: 'Gold (4)' },
|
||||
{ value: 5, label: 'Moderator (5)' },
|
||||
{ value: 6, label: 'Admin (6)' },
|
||||
{ value: 7, label: 'Super Admin (7)' },
|
||||
]
|
||||
{ value: 1, label: "User (1)" },
|
||||
{ value: 2, label: "Bronze (2)" },
|
||||
{ value: 3, label: "Silver (3)" },
|
||||
{ value: 4, label: "Gold (4)" },
|
||||
{ value: 5, label: "Moderator (5)" },
|
||||
{ value: 6, label: "Admin (6)" },
|
||||
{ value: 7, label: "Super Admin (7)" },
|
||||
];
|
||||
|
||||
export function CreateUserDialog({ sessionRank }: CreateUserDialogProps) {
|
||||
const { run, isPending } = useServerAction()
|
||||
const [open, setOpen] = useState(false)
|
||||
const [username, setUsername] = useState('')
|
||||
const [mail, setMail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [rank, setRank] = useState('1')
|
||||
const [motto, setMotto] = useState('')
|
||||
const { run, isPending } = useServerAction();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [username, setUsername] = useState("");
|
||||
const [mail, setMail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [rank, setRank] = useState("1");
|
||||
const [motto, setMotto] = useState("");
|
||||
|
||||
const allowedRanks = RANK_OPTIONS.filter((r) => (sessionRank >= 7 ? true : r.value < sessionRank))
|
||||
const allowedRanks = RANK_OPTIONS.filter((r) => (sessionRank >= 7 ? true : r.value < sessionRank));
|
||||
|
||||
function reset() {
|
||||
setUsername('')
|
||||
setMail('')
|
||||
setPassword('')
|
||||
setRank('1')
|
||||
setMotto('')
|
||||
setUsername("");
|
||||
setMail("");
|
||||
setPassword("");
|
||||
setRank("1");
|
||||
setMotto("");
|
||||
}
|
||||
|
||||
function generatePassword() {
|
||||
const charset = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789'
|
||||
let out = ''
|
||||
const buf = new Uint32Array(12)
|
||||
crypto.getRandomValues(buf)
|
||||
for (let i = 0; i < buf.length; i++) out += charset[buf[i] % charset.length]
|
||||
setPassword(out)
|
||||
toast.message('Password generated', { description: out })
|
||||
const charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
|
||||
let out = "";
|
||||
const buf = new Uint32Array(12);
|
||||
crypto.getRandomValues(buf);
|
||||
for (let i = 0; i < buf.length; i++) out += charset[buf[i] % charset.length];
|
||||
setPassword(out);
|
||||
toast.message("Password generated", { description: out });
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
const u = username.trim()
|
||||
const m = mail.trim()
|
||||
const u = username.trim();
|
||||
const m = mail.trim();
|
||||
if (!u || !m || !password) {
|
||||
toast.error('Username, email and password are required')
|
||||
return
|
||||
toast.error("Username, email and password are required");
|
||||
return;
|
||||
}
|
||||
if (u.length < 3 || u.length > 20 || !/^[a-zA-Z0-9_-]+$/.test(u)) {
|
||||
toast.error('Invalid username (3-20 chars, letters/digits/_/-)')
|
||||
return
|
||||
toast.error("Invalid username (3-20 chars, letters/digits/_/-)");
|
||||
return;
|
||||
}
|
||||
if (password.length < 6) {
|
||||
toast.error('Password must be at least 6 characters')
|
||||
return
|
||||
toast.error("Password must be at least 6 characters");
|
||||
return;
|
||||
}
|
||||
|
||||
run(
|
||||
@@ -95,19 +89,19 @@ export function CreateUserDialog({ sessionRank }: CreateUserDialogProps) {
|
||||
{
|
||||
successMessage: `User "${u}" created.`,
|
||||
onSuccess: () => {
|
||||
setOpen(false)
|
||||
reset()
|
||||
setOpen(false);
|
||||
reset();
|
||||
},
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(next) => {
|
||||
setOpen(next)
|
||||
if (!next) reset()
|
||||
setOpen(next);
|
||||
if (!next) reset();
|
||||
}}
|
||||
>
|
||||
<DialogTrigger asChild>
|
||||
@@ -200,5 +194,5 @@ export function CreateUserDialog({ sessionRank }: CreateUserDialogProps) {
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user