feat(SW-360): Refactored NewPassword input

This commit is contained in:
Tobias Johansson
2024-09-10 10:33:34 +02:00
committed by Chuma McPhoy
parent 9caa560b8d
commit 9435059097
13 changed files with 222 additions and 83 deletions

View File

@@ -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",