Skip to content

Commit 84bc7e2

Browse files
authored
♻️ Add email pattern and refactor in frontend (#1138)
1 parent c8e57bb commit 84bc7e2

File tree

7 files changed

+14
-25
lines changed

7 files changed

+14
-25
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ repos:
1818
args:
1919
- --fix
2020
- id: ruff-format
21-
- repo: https://github.com/biomejs/pre-commit
22-
rev: v0.1.0
23-
hooks:
24-
- id: biome-check
25-
additional_dependencies: ["@biomejs/[email protected]"]
2621

2722
ci:
2823
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

frontend/src/components/Admin/AddUser.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useMutation, useQueryClient } from "react-query"
2121
import { type UserCreate, UsersService } from "../../client"
2222
import type { ApiError } from "../../client/core/ApiError"
2323
import useCustomToast from "../../hooks/useCustomToast"
24+
import { emailPattern } from "../../utils"
2425

2526
interface AddUserProps {
2627
isOpen: boolean
@@ -95,10 +96,7 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
9596
id="email"
9697
{...register("email", {
9798
required: "Email is required",
98-
pattern: {
99-
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
100-
message: "Invalid email address",
101-
},
99+
pattern: emailPattern,
102100
})}
103101
placeholder="Email"
104102
type="email"

frontend/src/components/Admin/EditUser.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
UsersService,
2626
} from "../../client"
2727
import useCustomToast from "../../hooks/useCustomToast"
28+
import { emailPattern } from "../../utils"
2829

2930
interface EditUserProps {
3031
user: UserOut
@@ -101,10 +102,7 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
101102
id="email"
102103
{...register("email", {
103104
required: "Email is required",
104-
pattern: {
105-
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
106-
message: "Invalid email address",
107-
},
105+
pattern: emailPattern,
108106
})}
109107
placeholder="Email"
110108
type="email"

frontend/src/components/UserSettings/UserInformation.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from "../../client"
2525
import useAuth from "../../hooks/useAuth"
2626
import useCustomToast from "../../hooks/useCustomToast"
27+
import { emailPattern } from "../../utils"
2728

2829
const UserInformation: React.FC = () => {
2930
const queryClient = useQueryClient()
@@ -114,10 +115,7 @@ const UserInformation: React.FC = () => {
114115
id="email"
115116
{...register("email", {
116117
required: "Email is required",
117-
pattern: {
118-
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
119-
message: "Invalid email address",
120-
},
118+
pattern: emailPattern,
121119
})}
122120
type="email"
123121
size="md"

frontend/src/routes/login.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Logo from "../assets/images/fastapi-logo.svg"
2525
import type { ApiError } from "../client"
2626
import type { Body_login_login_access_token as AccessToken } from "../client/models/Body_login_login_access_token"
2727
import useAuth, { isLoggedIn } from "../hooks/useAuth"
28+
import { emailPattern } from "../utils"
2829

2930
export const Route = createFileRoute("/login")({
3031
component: Login,
@@ -87,10 +88,7 @@ function Login() {
8788
<Input
8889
id="username"
8990
{...register("username", {
90-
pattern: {
91-
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
92-
message: "Invalid email address",
93-
},
91+
pattern: emailPattern,
9492
})}
9593
placeholder="Email"
9694
type="email"

frontend/src/routes/recover-password.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { type SubmitHandler, useForm } from "react-hook-form"
1313
import { LoginService } from "../client"
1414
import { isLoggedIn } from "../hooks/useAuth"
1515
import useCustomToast from "../hooks/useCustomToast"
16+
import { emailPattern } from "../utils"
1617

1718
interface FormData {
1819
email: string
@@ -70,10 +71,7 @@ function RecoverPassword() {
7071
id="email"
7172
{...register("email", {
7273
required: "Email is required",
73-
pattern: {
74-
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
75-
message: "Invalid email address",
76-
},
74+
pattern: emailPattern,
7775
})}
7876
placeholder="Email"
7977
type="email"

frontend/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const emailPattern = {
2+
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
3+
message: "Invalid email address",
4+
}

0 commit comments

Comments
 (0)