refactor: unify password hook usage across forms and update related imports
This commit is contained in:
parent
d9fdfabf00
commit
71036954c9
7 changed files with 19 additions and 13 deletions
|
|
@ -12,7 +12,7 @@ import {
|
||||||
} from "~/components/custom_ui/form";
|
} from "~/components/custom_ui/form";
|
||||||
import { Button } from "~/components/ui/button";
|
import { Button } from "~/components/ui/button";
|
||||||
import Input from "~/components/ui/input";
|
import Input from "~/components/ui/input";
|
||||||
import { useMildPassword } from "~/hooks/usePassword";
|
import { usePassword } from "~/hooks/usePassword";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
import { useZodForm } from "~/lib/zodForm";
|
import { useZodForm } from "~/lib/zodForm";
|
||||||
import { useTranslation } from "~/providers/I18nProvider";
|
import { useTranslation } from "~/providers/I18nProvider";
|
||||||
|
|
@ -27,7 +27,7 @@ export const ChangePasswordForm = () => {
|
||||||
strengthScore,
|
strengthScore,
|
||||||
maxStrength,
|
maxStrength,
|
||||||
toggleVisibility,
|
toggleVisibility,
|
||||||
} = useMildPassword();
|
} = usePassword();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const ChangePasswordFormSchema = z
|
const ChangePasswordFormSchema = z
|
||||||
|
|
@ -173,7 +173,9 @@ export const ChangePasswordForm = () => {
|
||||||
"h-full transition-all duration-500 ease-out",
|
"h-full transition-all duration-500 ease-out",
|
||||||
getStrengthColor(strengthScore),
|
getStrengthColor(strengthScore),
|
||||||
)}
|
)}
|
||||||
style={{ width: `${(strengthScore / maxStrength) * 100}%` }}
|
style={{
|
||||||
|
width: `${(strengthScore / maxStrength) * 100}%`,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
import { Button } from "~/components/ui/button";
|
import { Button } from "~/components/ui/button";
|
||||||
import Input from "~/components/ui/input";
|
import Input from "~/components/ui/input";
|
||||||
import { PhoneInput } from "~/components/ui/phone-input";
|
import { PhoneInput } from "~/components/ui/phone-input";
|
||||||
import { useMildPassword } from "~/hooks/usePassword";
|
import { usePassword } from "~/hooks/usePassword";
|
||||||
import { generatePassword } from "~/lib/basicPwGenerator";
|
import { generatePassword } from "~/lib/basicPwGenerator";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
import { useZodForm } from "~/lib/zodForm";
|
import { useZodForm } from "~/lib/zodForm";
|
||||||
|
|
@ -32,7 +32,7 @@ export const FormNewUser = ({
|
||||||
strengthScore,
|
strengthScore,
|
||||||
toggleVisibility,
|
toggleVisibility,
|
||||||
maxStrength,
|
maxStrength,
|
||||||
} = useMildPassword();
|
} = usePassword();
|
||||||
|
|
||||||
const NewUserSchema = z
|
const NewUserSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import {
|
||||||
import Input from "~/components/ui/input";
|
import Input from "~/components/ui/input";
|
||||||
import { Label } from "~/components/ui/label";
|
import { Label } from "~/components/ui/label";
|
||||||
import { Separator } from "~/components/ui/separator";
|
import { Separator } from "~/components/ui/separator";
|
||||||
import { useMildPassword } from "~/hooks/usePassword";
|
import { usePassword } from "~/hooks/usePassword";
|
||||||
import { generatePassword } from "~/lib/basicPwGenerator";
|
import { generatePassword } from "~/lib/basicPwGenerator";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
import { useZodForm } from "~/lib/zodForm";
|
import { useZodForm } from "~/lib/zodForm";
|
||||||
|
|
@ -39,7 +39,7 @@ export const OverridePasswordForm = ({ id }: { id: UsersId }) => {
|
||||||
strengthScore,
|
strengthScore,
|
||||||
toggleVisibility,
|
toggleVisibility,
|
||||||
maxStrength,
|
maxStrength,
|
||||||
} = useMildPassword();
|
} = usePassword();
|
||||||
|
|
||||||
const OverridePasswordFormSchema = z
|
const OverridePasswordFormSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from "~/components/custom_ui/form";
|
} from "~/components/custom_ui/form";
|
||||||
import Input from "~/components/ui/input";
|
import Input from "~/components/ui/input";
|
||||||
import { useMildPassword } from "~/hooks/usePassword";
|
import { usePassword } from "~/hooks/usePassword";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
import { useZodForm } from "~/lib/zodForm";
|
import { useZodForm } from "~/lib/zodForm";
|
||||||
import { useTranslation } from "~/providers/I18nProvider";
|
import { useTranslation } from "~/providers/I18nProvider";
|
||||||
|
|
@ -29,7 +29,7 @@ export const FormRstPwFromToken = (props: { token: string }) => {
|
||||||
strengthScore,
|
strengthScore,
|
||||||
toggleVisibility,
|
toggleVisibility,
|
||||||
maxStrength,
|
maxStrength,
|
||||||
} = useMildPassword();
|
} = usePassword();
|
||||||
|
|
||||||
const ResetFormSchema = z
|
const ResetFormSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|
|
||||||
|
|
@ -188,3 +188,7 @@ export const useMildPassword = (): PasswordManager => {
|
||||||
maxStrength: 3,
|
maxStrength: 3,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const zPassword = zMildPassword;
|
||||||
|
|
||||||
|
export const usePassword = useMildPassword;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import {
|
||||||
} from "~/components/ui/alert-dialog";
|
} from "~/components/ui/alert-dialog";
|
||||||
import { Button } from "~/components/ui/button";
|
import { Button } from "~/components/ui/button";
|
||||||
import Input from "~/components/ui/input";
|
import Input from "~/components/ui/input";
|
||||||
import { useMildPassword } from "~/hooks/usePassword";
|
import { usePassword } from "~/hooks/usePassword";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
import { useZodForm } from "~/lib/zodForm";
|
import { useZodForm } from "~/lib/zodForm";
|
||||||
import type { NextPageWithLayout } from "~/pages/_app";
|
import type { NextPageWithLayout } from "~/pages/_app";
|
||||||
|
|
@ -65,7 +65,7 @@ const AcceptInvitePage: NextPageWithLayout<InviteTokenProps> = ({
|
||||||
strengthScore,
|
strengthScore,
|
||||||
toggleVisibility,
|
toggleVisibility,
|
||||||
maxStrength,
|
maxStrength,
|
||||||
} = useMildPassword();
|
} = usePassword();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const schema = z
|
const schema = z
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
import { zMildPassword } from "~/hooks/usePassword";
|
import { zPassword } from "~/hooks/usePassword";
|
||||||
import {
|
import {
|
||||||
adminProcedure,
|
adminProcedure,
|
||||||
createTRPCRouter,
|
createTRPCRouter,
|
||||||
|
|
@ -38,7 +38,7 @@ export const authRouter = createTRPCRouter({
|
||||||
cognome: z.string().nonempty("Inserisci un cognome valido"),
|
cognome: z.string().nonempty("Inserisci un cognome valido"),
|
||||||
email: z.email(),
|
email: z.email(),
|
||||||
nome: z.string().nonempty("Inserisci un nome valido"),
|
nome: z.string().nonempty("Inserisci un nome valido"),
|
||||||
password: zMildPassword,
|
password: zPassword,
|
||||||
telefono: z.string().nonempty("Inserisci un numero di telefono"),
|
telefono: z.string().nonempty("Inserisci un numero di telefono"),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue