import React, { useCallback, useState } from "react" import FormLabelled from "../base/FormLabelled" import FormLabel from "../base/formparts/FormLabel" import InputWithIcon from "../base/InputWithIcon" import { faEnvelope, faKey, faPlus, faUser } from "@fortawesome/free-solid-svg-icons" import FormButton from "../base/formparts/FormButton" import BoxFull from "../base/BoxFull" import FormAlert from "../base/formparts/FormAlert" import useStrings from "../../hooks/useStrings" /** * A {@link BoxFull} allowing an administrator user to create a new user. * * @param createUser - Async function to call to create an user. * @param running - Whether another request is currently running. * @param props - Additional props to pass to the box. * @returns {JSX.Element} * @constructor */ export default function BoxUserCreate({ createUser, running, ...props }) { const [username, setUsername] = useState("") const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState(undefined) const strings = useStrings() const onButtonClick = useCallback( async () => { const result = await createUser({ "email": email, "username": username, "password": password, }) setError(result.error) }, [createUser, email, username, password], ) return ( setUsername(event.target.value)} /> setEmail(event.target.value)} /> setPassword(event.target.value)} /> {error ? {error.toString()} : null} {strings.create} ) }