♻️ Add email pattern and refactor in frontend (#1138)
This commit is contained in:
@@ -18,11 +18,6 @@ repos:
|
|||||||
args:
|
args:
|
||||||
- --fix
|
- --fix
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
- repo: https://github.com/biomejs/pre-commit
|
|
||||||
rev: v0.1.0
|
|
||||||
hooks:
|
|
||||||
- id: biome-check
|
|
||||||
additional_dependencies: ["@biomejs/biome@1.4.1"]
|
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
|
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
|
||||||
|
@@ -21,6 +21,7 @@ import { useMutation, useQueryClient } from "react-query"
|
|||||||
import { type UserCreate, UsersService } from "../../client"
|
import { type UserCreate, UsersService } from "../../client"
|
||||||
import type { ApiError } from "../../client/core/ApiError"
|
import type { ApiError } from "../../client/core/ApiError"
|
||||||
import useCustomToast from "../../hooks/useCustomToast"
|
import useCustomToast from "../../hooks/useCustomToast"
|
||||||
|
import { emailPattern } from "../../utils"
|
||||||
|
|
||||||
interface AddUserProps {
|
interface AddUserProps {
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
@@ -95,10 +96,7 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
|
|||||||
id="email"
|
id="email"
|
||||||
{...register("email", {
|
{...register("email", {
|
||||||
required: "Email is required",
|
required: "Email is required",
|
||||||
pattern: {
|
pattern: emailPattern,
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
|
||||||
message: "Invalid email address",
|
|
||||||
},
|
|
||||||
})}
|
})}
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
type="email"
|
type="email"
|
||||||
|
@@ -25,6 +25,7 @@ import {
|
|||||||
UsersService,
|
UsersService,
|
||||||
} from "../../client"
|
} from "../../client"
|
||||||
import useCustomToast from "../../hooks/useCustomToast"
|
import useCustomToast from "../../hooks/useCustomToast"
|
||||||
|
import { emailPattern } from "../../utils"
|
||||||
|
|
||||||
interface EditUserProps {
|
interface EditUserProps {
|
||||||
user: UserOut
|
user: UserOut
|
||||||
@@ -101,10 +102,7 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
|
|||||||
id="email"
|
id="email"
|
||||||
{...register("email", {
|
{...register("email", {
|
||||||
required: "Email is required",
|
required: "Email is required",
|
||||||
pattern: {
|
pattern: emailPattern,
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
|
||||||
message: "Invalid email address",
|
|
||||||
},
|
|
||||||
})}
|
})}
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
type="email"
|
type="email"
|
||||||
|
@@ -24,6 +24,7 @@ import {
|
|||||||
} from "../../client"
|
} from "../../client"
|
||||||
import useAuth from "../../hooks/useAuth"
|
import useAuth from "../../hooks/useAuth"
|
||||||
import useCustomToast from "../../hooks/useCustomToast"
|
import useCustomToast from "../../hooks/useCustomToast"
|
||||||
|
import { emailPattern } from "../../utils"
|
||||||
|
|
||||||
const UserInformation: React.FC = () => {
|
const UserInformation: React.FC = () => {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
@@ -114,10 +115,7 @@ const UserInformation: React.FC = () => {
|
|||||||
id="email"
|
id="email"
|
||||||
{...register("email", {
|
{...register("email", {
|
||||||
required: "Email is required",
|
required: "Email is required",
|
||||||
pattern: {
|
pattern: emailPattern,
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
|
||||||
message: "Invalid email address",
|
|
||||||
},
|
|
||||||
})}
|
})}
|
||||||
type="email"
|
type="email"
|
||||||
size="md"
|
size="md"
|
||||||
|
@@ -25,6 +25,7 @@ import Logo from "../assets/images/fastapi-logo.svg"
|
|||||||
import type { ApiError } from "../client"
|
import type { ApiError } from "../client"
|
||||||
import type { Body_login_login_access_token as AccessToken } from "../client/models/Body_login_login_access_token"
|
import type { Body_login_login_access_token as AccessToken } from "../client/models/Body_login_login_access_token"
|
||||||
import useAuth, { isLoggedIn } from "../hooks/useAuth"
|
import useAuth, { isLoggedIn } from "../hooks/useAuth"
|
||||||
|
import { emailPattern } from "../utils"
|
||||||
|
|
||||||
export const Route = createFileRoute("/login")({
|
export const Route = createFileRoute("/login")({
|
||||||
component: Login,
|
component: Login,
|
||||||
@@ -87,10 +88,7 @@ function Login() {
|
|||||||
<Input
|
<Input
|
||||||
id="username"
|
id="username"
|
||||||
{...register("username", {
|
{...register("username", {
|
||||||
pattern: {
|
pattern: emailPattern,
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
|
||||||
message: "Invalid email address",
|
|
||||||
},
|
|
||||||
})}
|
})}
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
type="email"
|
type="email"
|
||||||
|
@@ -13,6 +13,7 @@ import { type SubmitHandler, useForm } from "react-hook-form"
|
|||||||
import { LoginService } from "../client"
|
import { LoginService } from "../client"
|
||||||
import { isLoggedIn } from "../hooks/useAuth"
|
import { isLoggedIn } from "../hooks/useAuth"
|
||||||
import useCustomToast from "../hooks/useCustomToast"
|
import useCustomToast from "../hooks/useCustomToast"
|
||||||
|
import { emailPattern } from "../utils"
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
email: string
|
email: string
|
||||||
@@ -70,10 +71,7 @@ function RecoverPassword() {
|
|||||||
id="email"
|
id="email"
|
||||||
{...register("email", {
|
{...register("email", {
|
||||||
required: "Email is required",
|
required: "Email is required",
|
||||||
pattern: {
|
pattern: emailPattern,
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
|
||||||
message: "Invalid email address",
|
|
||||||
},
|
|
||||||
})}
|
})}
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
type="email"
|
type="email"
|
||||||
|
4
frontend/src/utils.ts
Normal file
4
frontend/src/utils.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const emailPattern = {
|
||||||
|
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
||||||
|
message: "Invalid email address",
|
||||||
|
}
|
Reference in New Issue
Block a user