2025-01-15 02:09:43 -05:00
|
|
|
"use client"
|
|
|
|
|
|
|
|
import { useState } from "react"
|
|
|
|
import strings from "@/strings.json"
|
|
|
|
import { Input } from "@/components/ui/input"
|
|
|
|
import { Label } from "@/components/ui/label"
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
|
|
|
|
|
|
|
|
export default function CreateUser() {
|
2025-01-15 09:31:23 -05:00
|
|
|
const [username, setUsername] = useState("")
|
2025-01-15 02:09:43 -05:00
|
|
|
const [email, setEmail] = useState("")
|
|
|
|
const [password, setPassword] = useState("")
|
|
|
|
|
2025-01-15 09:31:23 -05:00
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
2025-01-15 02:09:43 -05:00
|
|
|
e.preventDefault()
|
2025-01-15 09:31:23 -05:00
|
|
|
try {
|
|
|
|
const response = await fetch('http://localhost:3001/api/users/add', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ username, email, password }),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
2025-01-30 19:59:24 -05:00
|
|
|
throw new Error(strings.errorsCreateUserFail);
|
2025-01-15 09:31:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const data = await response.json();
|
2025-01-30 19:59:24 -05:00
|
|
|
console.log(`${strings.successSuperGeneric}: ${data}`);
|
2025-01-15 09:31:23 -05:00
|
|
|
} catch (error) {
|
2025-01-30 19:59:24 -05:00
|
|
|
console.error(`${strings.errorsSuperGeneric}: ${error}`);
|
2025-01-15 09:31:23 -05:00
|
|
|
}
|
|
|
|
console.log({ username, email, password })
|
2025-01-15 02:09:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="space-y-8">
|
|
|
|
<h1 className="text-4xl font-bold text-primary">{strings.adminNewUserHeader}</h1>
|
|
|
|
<Card>
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<CardHeader>
|
|
|
|
<CardTitle>{strings.newUserCardTitle}</CardTitle>
|
|
|
|
</CardHeader>
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
<div className="space-y-2">
|
2025-01-15 09:31:23 -05:00
|
|
|
<Label htmlFor="username">{strings.newUserNameFieldLabel}</Label>
|
2025-01-15 02:09:43 -05:00
|
|
|
<Input
|
2025-01-15 09:31:23 -05:00
|
|
|
id="username"
|
|
|
|
value={username}
|
|
|
|
onChange={(e) => setUsername(e.target.value)}
|
2025-01-15 02:09:43 -05:00
|
|
|
placeholder={strings.newUserNameFieldPlaceholder}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
|
|
<Label htmlFor="email">{strings.newUserEmailFieldLabel}</Label>
|
|
|
|
<Input
|
|
|
|
id="email"
|
|
|
|
value={email}
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
|
|
placeholder={strings.newUserEmailFieldPlaceholder}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
|
|
<Label htmlFor="password">{strings.newUserPasswordFieldLabel}</Label>
|
|
|
|
<Input
|
|
|
|
id="password"
|
|
|
|
type="password"
|
|
|
|
value={password}
|
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
|
|
placeholder={strings.newUserPasswordFieldPlaceholder}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</CardContent>
|
|
|
|
<CardFooter>
|
|
|
|
<Button type="submit">{strings.createUserButtonText}</Button>
|
|
|
|
</CardFooter>
|
|
|
|
</form>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|