import React, { useContext, useMemo, 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 useBackend from "../../hooks/useBackend" import ContextUser from "../../contexts/ContextUser" import FormAlert from "../base/formparts/FormAlert" export default function BoxUserCreate({ children, ...props }) { const { fetchDataAuth } = useContext(ContextUser) const [username, setUsername] = useState("") const [email, setEmail] = useState("") const [password, setPassword] = useState("") const body = useMemo( () => { return { "email": email, "username": username, "password": password, } }, [email, username, password], ) const { error, fetchNow: createNow } = useBackend(fetchDataAuth, "POST", "/api/v1/users/", body) return ( setUsername(event.target.value)} /> setEmail(event.target.value)} /> setPassword(event.target.value)} /> {error ? {error.toString()} : null} createNow()} > Create {children} ) }