Skip to content

Commit

Permalink
refactor form validation in login and signup pages
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWTE committed Jul 15, 2024
1 parent 2a985f7 commit 9f03f18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions app/[...login]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,12 @@ const LoginPage = ({ params }: { params: { login: string[] } }) => {
setPassword(event.target.value);
};

const isValidForm = () => {
return formData.fqe && password;
};

const handleSubmit = async (e: any) => {
e.preventDefault();

setIsSubmitting(true);

if (!isValidForm()) {
if (!formData.fqe || !password) {
setIsSubmitting(false);
return;
}
Expand Down Expand Up @@ -336,7 +332,7 @@ const LoginPage = ({ params }: { params: { login: string[] } }) => {
<button
type="submit"
className="bg-blue-500 hover:bg-blue-600 text-white font-bold w-full py-3 rounded transition duration-200 flex justify-center items-center"
disabled={!isValidForm() || isSubmitting}
disabled={isSubmitting || !formData.fqe || !password}
>
{isSubmitting && (
<FontAwesomeIcon
Expand Down
2 changes: 1 addition & 1 deletion app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ const RegisterPage = () => {
<button
type="submit"
className="bg-blue-500 hover:bg-blue-600 text-white font-bold w-full py-3 rounded transition duration-200 flex justify-center items-center"
disabled={!isValidForm() || isSubmitting || disabled}
disabled={isValidForm() ? false : true || isSubmitting || disabled}
>
{isSubmitting && (
<FontAwesomeIcon
Expand Down

0 comments on commit 9f03f18

Please sign in to comment.