feat(SW-360): Refactored NewPassword input
This commit is contained in:
committed by
Pontus Dreij
parent
a4483b7d71
commit
c5c4f8e7e7
@@ -69,6 +69,7 @@ export default function Form({ user }: EditFormProps) {
|
||||
retypeNewPassword: "",
|
||||
},
|
||||
mode: "all",
|
||||
criteriaMode: "all",
|
||||
resolver: zodResolver(editProfileSchema),
|
||||
reValidateMode: "onChange",
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { Key } from "@/components/TempDesignSystem/Form/NewPassword/newPassword"
|
||||
import { passwordValidator } from "@/utils/passwordValidator"
|
||||
import { phoneValidator } from "@/utils/phoneValidator"
|
||||
|
||||
const countryRequiredMsg = "Country is required"
|
||||
@@ -26,7 +26,7 @@ export const editProfileSchema = z
|
||||
),
|
||||
|
||||
password: z.string().optional(),
|
||||
newPassword: z.string().optional(),
|
||||
newPassword: passwordValidator(),
|
||||
retypeNewPassword: z.string().optional(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
@@ -55,29 +55,6 @@ export const editProfileSchema = z
|
||||
}
|
||||
}
|
||||
|
||||
if (data.newPassword) {
|
||||
const msgs = []
|
||||
if (data.newPassword.length < 10 || data.newPassword.length > 40) {
|
||||
msgs.push(Key.CHAR_LENGTH)
|
||||
}
|
||||
if (!data.newPassword.match(/[A-Z]/g)) {
|
||||
msgs.push(Key.UPPERCASE)
|
||||
}
|
||||
if (!data.newPassword.match(/[0-9]/g)) {
|
||||
msgs.push(Key.NUM)
|
||||
}
|
||||
if (!data.newPassword.match(/[^A-Za-z0-9]/g)) {
|
||||
msgs.push(Key.SPECIAL_CHAR)
|
||||
}
|
||||
if (msgs.length) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
message: msgs.join(","),
|
||||
path: ["newPassword"],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (data.newPassword && !data.retypeNewPassword) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
|
||||
Reference in New Issue
Block a user