diff --git a/components/AuthSubmitButton.tsx b/components/AuthSubmitButton.tsx new file mode 100644 index 0000000..434d0af --- /dev/null +++ b/components/AuthSubmitButton.tsx @@ -0,0 +1,35 @@ +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { IconProp } from "@fortawesome/fontawesome-svg-core"; + +type Props = { + onClick?: Function; + icon?: IconProp; + label: string; + loading: boolean; + className?: string; +}; + +export default function AuthSubmitButton({ + onClick, + icon, + label, + loading, + className, +}: Props) { + return ( + + ); +} diff --git a/pages/login.tsx b/pages/login.tsx index f6968cc..3c39284 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -3,8 +3,9 @@ import TextInput from "@/components/TextInput"; import CenteredForm from "@/layouts/CenteredForm"; import { signIn } from "next-auth/react"; import Link from "next/link"; -import { useState } from "react"; +import { useState, FormEvent } from "react"; import { toast } from "react-hot-toast"; +import AuthSubmitButton from "@/components/AuthSubmitButton"; interface FormData { username: string; @@ -21,7 +22,9 @@ export default function Login() { password: "", }); - async function loginUser() { + async function loginUser(event: FormEvent) { + event.preventDefault(); + if (form.username !== "" && form.password !== "") { setSubmitLoader(true); @@ -47,67 +50,69 @@ export default function Login() { return ( -
-

- Enter your credentials -

- -
-

- Username - {emailEnabled ? " or Email" : undefined} +

+
+

+ Enter your credentials

- setForm({ ...form, username: e.target.value })} - /> -
+
+

+ Username + {emailEnabled ? " or Email" : undefined} +

-
-

- Password -

+ setForm({ ...form, username: e.target.value })} + /> +
- setForm({ ...form, password: e.target.value })} +
+

+ Password +

+ + setForm({ ...form, password: e.target.value })} + /> + {emailEnabled && ( +
+ + Forgot Password? + +
+ )} +
+ + - {emailEnabled && ( -
+ {process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? undefined : ( +
+

New here?

- Forgot Password? + Sign Up
)}
- - - {process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? undefined : ( -
-

New here?

- - Sign Up - -
- )} -
+
); } diff --git a/pages/register.tsx b/pages/register.tsx index 75ba525..a681c01 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -1,11 +1,12 @@ import Link from "next/link"; -import { useState } from "react"; +import { useState, FormEvent } from "react"; import { toast } from "react-hot-toast"; import SubmitButton from "@/components/SubmitButton"; import { signIn } from "next-auth/react"; import { useRouter } from "next/router"; import CenteredForm from "@/layouts/CenteredForm"; import TextInput from "@/components/TextInput"; +import AuthSubmitButton from "@/components/AuthSubmitButton"; const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER; @@ -29,7 +30,9 @@ export default function Register() { passwordConfirmation: "", }); - async function registerUser() { + async function registerUser(event: FormEvent) { + event.preventDefault(); + const checkFields = () => { if (emailEnabled) { return ( @@ -107,7 +110,8 @@ export default function Register() {

) : ( -
+
+

Enter your details

@@ -117,6 +121,7 @@ export default function Register() {

) : undefined} -
+ )} );