refactor: unify password hook usage across forms and update related imports

This commit is contained in:
Marco Pedone 2026-04-14 16:36:10 +02:00
parent d9fdfabf00
commit 71036954c9
7 changed files with 19 additions and 13 deletions

View file

@ -12,7 +12,7 @@ import {
} from "~/components/custom_ui/form";
import { Button } from "~/components/ui/button";
import Input from "~/components/ui/input";
import { useMildPassword } from "~/hooks/usePassword";
import { usePassword } from "~/hooks/usePassword";
import { cn } from "~/lib/utils";
import { useZodForm } from "~/lib/zodForm";
import { useTranslation } from "~/providers/I18nProvider";
@ -27,7 +27,7 @@ export const ChangePasswordForm = () => {
strengthScore,
maxStrength,
toggleVisibility,
} = useMildPassword();
} = usePassword();
const router = useRouter();
const ChangePasswordFormSchema = z
@ -173,7 +173,9 @@ export const ChangePasswordForm = () => {
"h-full transition-all duration-500 ease-out",
getStrengthColor(strengthScore),
)}
style={{ width: `${(strengthScore / maxStrength) * 100}%` }}
style={{
width: `${(strengthScore / maxStrength) * 100}%`,
}}
/>
</div>
</div>

View file

@ -12,7 +12,7 @@ import {
import { Button } from "~/components/ui/button";
import Input from "~/components/ui/input";
import { PhoneInput } from "~/components/ui/phone-input";
import { useMildPassword } from "~/hooks/usePassword";
import { usePassword } from "~/hooks/usePassword";
import { generatePassword } from "~/lib/basicPwGenerator";
import { cn } from "~/lib/utils";
import { useZodForm } from "~/lib/zodForm";
@ -32,7 +32,7 @@ export const FormNewUser = ({
strengthScore,
toggleVisibility,
maxStrength,
} = useMildPassword();
} = usePassword();
const NewUserSchema = z
.object({

View file

@ -22,7 +22,7 @@ import {
import Input from "~/components/ui/input";
import { Label } from "~/components/ui/label";
import { Separator } from "~/components/ui/separator";
import { useMildPassword } from "~/hooks/usePassword";
import { usePassword } from "~/hooks/usePassword";
import { generatePassword } from "~/lib/basicPwGenerator";
import { cn } from "~/lib/utils";
import { useZodForm } from "~/lib/zodForm";
@ -39,7 +39,7 @@ export const OverridePasswordForm = ({ id }: { id: UsersId }) => {
strengthScore,
toggleVisibility,
maxStrength,
} = useMildPassword();
} = usePassword();
const OverridePasswordFormSchema = z
.object({

View file

@ -11,7 +11,7 @@ import {
FormMessage,
} from "~/components/custom_ui/form";
import Input from "~/components/ui/input";
import { useMildPassword } from "~/hooks/usePassword";
import { usePassword } from "~/hooks/usePassword";
import { cn } from "~/lib/utils";
import { useZodForm } from "~/lib/zodForm";
import { useTranslation } from "~/providers/I18nProvider";
@ -29,7 +29,7 @@ export const FormRstPwFromToken = (props: { token: string }) => {
strengthScore,
toggleVisibility,
maxStrength,
} = useMildPassword();
} = usePassword();
const ResetFormSchema = z
.object({

View file

@ -188,3 +188,7 @@ export const useMildPassword = (): PasswordManager => {
maxStrength: 3,
};
};
export const zPassword = zMildPassword;
export const usePassword = useMildPassword;

View file

@ -30,7 +30,7 @@ import {
} from "~/components/ui/alert-dialog";
import { Button } from "~/components/ui/button";
import Input from "~/components/ui/input";
import { useMildPassword } from "~/hooks/usePassword";
import { usePassword } from "~/hooks/usePassword";
import { cn } from "~/lib/utils";
import { useZodForm } from "~/lib/zodForm";
import type { NextPageWithLayout } from "~/pages/_app";
@ -65,7 +65,7 @@ const AcceptInvitePage: NextPageWithLayout<InviteTokenProps> = ({
strengthScore,
toggleVisibility,
maxStrength,
} = useMildPassword();
} = usePassword();
const router = useRouter();
const schema = z

View file

@ -1,5 +1,5 @@
import { z } from "zod/v4";
import { zMildPassword } from "~/hooks/usePassword";
import { zPassword } from "~/hooks/usePassword";
import {
adminProcedure,
createTRPCRouter,
@ -38,7 +38,7 @@ export const authRouter = createTRPCRouter({
cognome: z.string().nonempty("Inserisci un cognome valido"),
email: z.email(),
nome: z.string().nonempty("Inserisci un nome valido"),
password: zMildPassword,
password: zPassword,
telefono: z.string().nonempty("Inserisci un numero di telefono"),
}),
)