Skip to content

Commit

Permalink
fix: showing error on input
Browse files Browse the repository at this point in the history
  • Loading branch information
yeasin2002 committed Sep 22, 2024
1 parent 994fe5e commit d9ab652
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/[lang]/(front-end)/(user-auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Auth = async ({ children, params }: Props) => {
"https://images.unsplash.com/photo-1667133295315-820bb6481730?w=500&h=500&auto=format&fit=crop&q=100&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTE1fHxkZW50YWx8ZW58MHwxfDB8fHwy"
}
alt="Logo"
className="hidden aspect-square object-cover md:block xl:size-full"
className="hidden aspect-square rounded-md object-cover md:block xl:size-full"
width={500}
height={500}
/>
Expand Down
3 changes: 3 additions & 0 deletions src/app/[lang]/(front-end)/(user-auth)/login/logInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ export const LoginForm = ({ dictionary }: Props) => {
error={errors.email?.message}
icon={<Email />}
placeholder={dictionary?.emailPlaceholder || "Email"}
labelName="Email"
/>

<InputComboForPassword
register={register("password")}
error={errors.password?.message}
icon={<Lock />}
placeholder="*******"
labelName="Password"
/>
<InputComboForPassword
register={register("confirmPassword")}
error={errors.confirmPassword?.message}
icon={<Lock />}
placeholder="******"
labelName="confirm Password"
/>
<div className="flex items-center justify-between">
<p className="text-zinc-800">{dictionary.ForgotPassword}</p>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/admin/(dashboard)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const Admin = async () => {
<DashboardAnalytics />
</section>
);
};
};

export default Admin;
8 changes: 7 additions & 1 deletion src/app/[lang]/admin/(doctors-auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ const Auth = async ({ children, params }: Props) => {
<Home className="size-6 text-gray-800" />
</Link>
<div>
<Image src={OT} alt="Logo" className="hidden aspect-square object-cover md:block" width={500} height={500} />
<Image
src={OT}
alt="Logo"
className="hidden aspect-square rounded-md object-cover md:block"
width={500}
height={500}
/>
</div>
<div>
<section className="dark:bg-gray-900">
Expand Down
8 changes: 7 additions & 1 deletion src/app/[lang]/admin/(doctors-auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Login = () => {
console.log("🚀 ~ onSubmit ~ data:", data);

setIsLoading(true);
const toastId = toast.loading("Processing...");
const toastId = toast.loading("Submitting...");
try {
const loginReq = await loginWithAuthJs({
email: data.email,
Expand All @@ -52,19 +52,25 @@ const Login = () => {
error={errors.email?.message}
icon={<Email />}
placeholder="Email address"
labelName="Email"
isShowError
/>

<InputComboForPassword
register={register("password")}
error={errors.password?.message}
icon={<Lock />}
placeholder="*******"
labelName="Password"
isShowError
/>
<InputComboForPassword
register={register("confirmPassword")}
error={errors.confirmPassword?.message}
icon={<Lock />}
placeholder="******"
labelName="Confirm Password"
isShowError
/>

<button
Expand Down
7 changes: 6 additions & 1 deletion src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@
@apply relative flex items-center 2xl:shadow-sm 2xl:placeholder:text-2xl;
}
.inputCombo-label {
@apply block font-bold text-gray-700;
@apply block font-bold capitalize text-gray-700;
}

.inputCombo-error {
@apply mt-[0.15rem] text-xs font-semibold text-red-400;
}

.inputCombo-warning {
@apply text-sm font-bold italic text-red-500;
}
Expand Down
1 change: 1 addition & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
await connectDB();
const user = await db.Doctors.findOne({ email: email });
if (!user) throw new Error("User not found");
if (user?.isPending) throw new Error("Wait for admin approval");

const isMatch = await bcrypt.compare(password, user?.password);
if (!isMatch) throw new Error("Email or Password is not correct");
Expand Down
15 changes: 13 additions & 2 deletions src/components/ui/inputCombo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ interface Props extends React.ComponentProps<"input"> {
register: UseFormRegisterReturn;
error: string | undefined;
wrapperClassName?: string;

labelName?: string;
isShowError?: boolean;
}

export const InputCombo = ({ icon, className, register, wrapperClassName, error, labelName, ...props }: Props) => {
export const InputCombo = ({
icon,
className,
register,
wrapperClassName,
error,
labelName,
isShowError = true,
...props
}: Props) => {
return (
<div>
{labelName && (
Expand All @@ -30,6 +39,8 @@ export const InputCombo = ({ icon, className, register, wrapperClassName, error,
{...props}
/>
</div>

{isShowError && <p className="inputCombo-error">{error || ""}</p>}
</div>
);
};
4 changes: 4 additions & 0 deletions src/components/ui/inputComboForPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props extends React.ComponentProps<"input"> {
error: string | undefined;
wrapperClassName?: string;
labelName?: string;
isShowError?: boolean;
}

export const InputComboForPassword = ({
Expand All @@ -20,6 +21,7 @@ export const InputComboForPassword = ({
wrapperClassName,
error,
labelName,
isShowError = true,
...props
}: Props) => {
const [isShow, setIsShow] = useState(false);
Expand Down Expand Up @@ -47,6 +49,8 @@ export const InputComboForPassword = ({
{!isShow ? <EyeOff className="text-gray-600" /> : <Eye className="text-gray-600" />}
</button>
</div>

{isShowError && <p className="inputCombo-error">{error}</p>}
</div>
);
};
5 changes: 2 additions & 3 deletions src/schema/loginSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { z } from "zod";
export const loginFormSchema = z
.object({
email: z.string().email(),
password: z.string().min(8, { message: "Password is too short" }).max(20, { message: "Password is too long" }),

password: z.string().min(8, { message: "Password is too short" }).max(40, { message: "Password is too long" }),
confirmPassword: z
.string()
.min(8, { message: "Password is too short" })
.max(20, { message: "Password is too long" }),
.max(40, { message: "Password is too long" }),
})
.refine((data) => data.password === data.confirmPassword, {
message: "Passwords do not match",
Expand Down

0 comments on commit d9ab652

Please sign in to comment.