Skip to content

Commit

Permalink
fix: some tweaks for sign-in and sign-up forms
Browse files Browse the repository at this point in the history
  • Loading branch information
paabloLC committed Feb 4, 2025
1 parent eb6c334 commit e21c973
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 9 additions & 2 deletions ui/components/auth/oss/auth-form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { Checkbox, Link } from "@nextui-org/react";
import { Checkbox, Link, Spacer } from "@nextui-org/react";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand Down Expand Up @@ -172,20 +172,25 @@ export const AuthForm = ({
/>
</>
)}

<CustomInput
control={form.control}
name="email"
type="email"
label="Email"
placeholder="Enter your email"
isInvalid={!!form.formState.errors.email}
showFormMessage={type !== "sign-in"}
/>

<CustomInput
control={form.control}
name="password"
password
isInvalid={!!form.formState.errors.password}
isInvalid={
!!form.formState.errors.password ||
!!form.formState.errors.email
}
/>

{/* {type === "sign-in" && (
Expand Down Expand Up @@ -259,6 +264,8 @@ export const AuthForm = ({
</div>
)}

{type === "sign-in" && <Spacer y={2} />}

<CustomButton
type="submit"
ariaLabel={type === "sign-in" ? "Log In" : "Sign Up"}
Expand Down
6 changes: 5 additions & 1 deletion ui/components/ui/custom/custom-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface CustomInputProps<T extends FieldValues> {
isRequired?: boolean;
isInvalid?: boolean;
isDisabled?: boolean;
showFormMessage?: boolean;
}

export const CustomInput = <T extends FieldValues>({
Expand All @@ -41,6 +42,7 @@ export const CustomInput = <T extends FieldValues>({
isRequired = true,
isInvalid,
isDisabled = false,
showFormMessage = true,
}: CustomInputProps<T>) => {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const [isConfirmPasswordVisible, setIsConfirmPasswordVisible] =
Expand Down Expand Up @@ -112,7 +114,9 @@ export const CustomInput = <T extends FieldValues>({
{...field}
/>
</FormControl>
<FormMessage className="text-system-error dark:text-system-error" />
{showFormMessage && (
<FormMessage className="text-system-error dark:text-system-error" />
)}
</>
)}
/>
Expand Down
9 changes: 6 additions & 3 deletions ui/types/authFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export const authFormSchema = (type: string) =>

// Fields for Sign In and Sign Up
email: z.string().email(),
password: z.string().min(12, {
message: "It must contain at least 12 characters.",
}),
password:
type === "sign-in"
? z.string()
: z.string().min(12, {
message: "It must contain at least 12 characters.",
}),
})
.refine(
(data) => type === "sign-in" || data.password === data.confirmPassword,
Expand Down

0 comments on commit e21c973

Please sign in to comment.