From b279e8f9753e4ba7408a42493a2692d184d97e1d Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:43:22 +0530 Subject: [PATCH] feat(ui): add password show input and fix submit button also i add login user name in dashboard. --- app/(public)/login/form.tsx | 13 ++++++-- app/(public)/signup/form.tsx | 13 ++++++-- app/dashboard/layout.tsx | 26 +-------------- components/ui/PasswordInput .tsx | 56 ++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 components/ui/PasswordInput .tsx diff --git a/app/(public)/login/form.tsx b/app/(public)/login/form.tsx index 16bf029..e922b44 100644 --- a/app/(public)/login/form.tsx +++ b/app/(public)/login/form.tsx @@ -6,9 +6,12 @@ import { Label } from '@/components/ui/label'; import { login } from '@/app/auth/01-auth'; import Link from 'next/link'; import { useFormState, useFormStatus } from 'react-dom'; +import { PasswordInput } from '@/components/ui/PasswordInput '; +import { useState } from 'react'; export function LoginForm() { const [state, action] = useFormState(login, undefined); + const [password, setPassword] = useState(''); return (
@@ -32,7 +35,13 @@ export function LoginForm() { Forgot your password? - + setPassword(e.target.value)} + id="password" + name="password" + placeholder="******" + /> {state?.errors?.password && (

{state.errors.password}

)} @@ -51,7 +60,7 @@ export function LoginButton() { return ( ); } diff --git a/app/(public)/signup/form.tsx b/app/(public)/signup/form.tsx index a9edca8..3617f13 100644 --- a/app/(public)/signup/form.tsx +++ b/app/(public)/signup/form.tsx @@ -5,9 +5,12 @@ import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { signup } from '@/app/auth/01-auth'; import { useFormState, useFormStatus } from 'react-dom'; +import { PasswordInput } from '@/components/ui/PasswordInput '; +import { useState } from 'react'; export function SignupForm() { const [state, action] = useFormState(signup, undefined); + const [password, setPassword] = useState(''); return ( @@ -28,7 +31,13 @@ export function SignupForm() { )}
- + setPassword(e.target.value)} + id="password" + name="password" + placeholder="******" + />
{state?.errors?.password && (
@@ -51,7 +60,7 @@ export function SignupButton() { return ( ); } diff --git a/app/dashboard/layout.tsx b/app/dashboard/layout.tsx index 3035b21..fbeb36a 100644 --- a/app/dashboard/layout.tsx +++ b/app/dashboard/layout.tsx @@ -71,31 +71,7 @@ export default async function Layout({ Home

Dashboard

-
- -
- -
- - -
+
Welcome, {user?.name}!
{children}
diff --git a/components/ui/PasswordInput .tsx b/components/ui/PasswordInput .tsx new file mode 100644 index 0000000..f5c4167 --- /dev/null +++ b/components/ui/PasswordInput .tsx @@ -0,0 +1,56 @@ +"use client"; + +import { forwardRef, useState } from "react"; +import { EyeIcon, EyeOffIcon } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Input, InputProps } from "@/components/ui/input"; +import { cn } from "@/lib/utils"; + +const PasswordInput = forwardRef( + ({ className, ...props }, ref) => { + const [showPassword, setShowPassword] = useState(false); + const disabled = + props.value === "" || props.value === undefined || props.disabled; + + return ( +
+ + + + {/* hides browsers password toggles */} + +
+ ); + }, +); +PasswordInput.displayName = "PasswordInput"; + +export { PasswordInput };