Skip to content

Commit

Permalink
Fixed username validation in LoginForm & RegisterForm
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaakher committed Oct 23, 2023
1 parent 44876c4 commit 4cd4584
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions components/blocks/auth/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type RegisterFormTypes = {
emailInvalidText: string;
usernameLabel: string;
usernamePlaceholder: string;
usernameInvalid: string;
usernameRequired: string;
passwordLabel: string;
passwordPlaceholder: string;
Expand Down Expand Up @@ -138,9 +139,14 @@ export const RegisterForm: FC<RegisterFormTypes> = ({ texts, ...props }) => {
case "username":
fieldSchemas["username"] = z
.string({ required_error: texts?.usernameRequired })
.refine((value) => value !== "", {
message: texts?.usernameRequired,
});
.min(1, { message: texts?.usernameRequired })
.refine(
(value) => {
const isValid = /^[a-zA-Z][a-zA-Z0-9_-]{2,14}$/.test(value);
return isValid;
},
{ message: texts?.usernameInvalid }
);
break;
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sikka/hawa",
"version": "0.10.16",
"version": "0.10.17",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion stories/BlocksStories/AuthStories/Login.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const MagicLink: Story = {
usernameLabel: t("usernameLabel"),
usernamePlaceholder: t("usernamePlaceholder"),
usernameRequired: t("usernameRequired"),
usernameInvalid: "tet",
usernameInvalid: t("usernameInvalid"),
phoneRequiredText: t("phoneRequiredText"),
passwordLabel: t("passwordLabel"),
passwordPlaceholder: t("passwordPlaceholder"),
Expand Down
1 change: 1 addition & 0 deletions stories/BlocksStories/AuthStories/Register.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const Template = (args: any, globals: any) => {
usernameLabel: t("usernameLabel"),
usernamePlaceholder: t("usernamePlaceholder"),
usernameRequired: t("usernameRequired"),
usernameInvalid: t("usernameInvalid"),
passwordLabel: t("passwordLabel"),
passwordPlaceholder: t("passwordPlaceholder"),
passwordRequiredText: t("passwordRequiredText"),
Expand Down
1 change: 1 addition & 0 deletions stories/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"usernameLabel": "اسم المستخدم",
"usernamePlaceholder": "ادخل المستخدم",
"usernameRequired": " اسم المستخدم مطلوب",
"usernameInvalid": "صيغة إسم المستخدم غير صحيحة",
"phoneRequiredText": "رقم الجوال مطلوب",
"phoneInvalid": "صيغة رقم الجوال غير صحيحة",
"phoneLabel": "رقم الجوال",
Expand Down
1 change: 1 addition & 0 deletions stories/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"usernameLabel": "Username",
"usernamePlaceholder": "Enter your username",
"usernameRequired": "Username is required",
"usernameInvalid": "Username format is invalid",
"phoneRequiredText": "Phone is required",
"phoneInvalid": "Phone is invalid",
"phoneLabel": "Phone number",
Expand Down

0 comments on commit 4cd4584

Please sign in to comment.