diff --git a/frontend/src/hooks/useRegister.ts b/frontend/src/hooks/useRegister.ts index 98d4386..e400411 100644 --- a/frontend/src/hooks/useRegister.ts +++ b/frontend/src/hooks/useRegister.ts @@ -1,12 +1,12 @@ import { useMutation } from "@tanstack/react-query"; import { RolesType } from "models/User.ts"; import useApi from "./useApi.ts"; -import { LoginPath } from "./api/constants.ts"; +import { RegisterPath } from "./api/constants.ts"; interface RegisterRequest { username: string; - firstname: string; - lastname: string; + firstName: string; + lastName: string; role: RolesType; password: string; } @@ -14,10 +14,10 @@ interface RegisterRequest { export default function useRegister() { const callApi = useApi(); return useMutation({ - mutationFn: ({ username, password, firstname, lastname, role }: RegisterRequest) => + mutationFn: ({ username, password, firstName, lastName, role }: RegisterRequest) => callApi<{ name: string }>({ - url: LoginPath, - body: { username, password, firstname, lastname, role }, + url: RegisterPath, + body: { username, password, firstName, lastName, role }, method: "POST", }), }); diff --git a/frontend/src/pages/Auth/Register.tsx b/frontend/src/pages/Auth/Register.tsx index 38c833f..d44b171 100644 --- a/frontend/src/pages/Auth/Register.tsx +++ b/frontend/src/pages/Auth/Register.tsx @@ -1,8 +1,33 @@ import InputWithLabel from "ui/InputWithLabel.tsx"; import LinkText from "ui/LinkText.tsx"; -import FormSubmitButton from "./components/FormSubmitButton.tsx"; +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import Button from "ui/Button.tsx"; +import useRegister from "hooks/useRegister.ts"; +import Checkbox from "ui/Checkbox.tsx"; +import { Roles } from "models/User.ts"; function Register() { + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const [passwordCheck, setCheckPassword] = useState(""); + const [firstName, setFirstName] = useState(""); + const [lastName, setLastName] = useState(""); + const [premium, setPremium] = useState(false); + const { mutateAsync, isPending } = useRegister(); + const navigate = useNavigate(); + + const onSubmit = async () => { + await mutateAsync({ + username, + password, + firstName, + lastName, + role: premium ? Roles.PAID : Roles.FREE, + }); + navigate("/login"); + }; + return (