add form validations
This commit is contained in:
@@ -6,49 +6,54 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
TextField,
|
TextField,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { useState } from "react";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { useAuth } from "../hooks/useAuth";
|
import { useAuth } from "../hooks/useAuth";
|
||||||
|
|
||||||
|
type LoginForm = {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const LoginDialog = () => {
|
export const LoginDialog = () => {
|
||||||
const { isLoginDialogOpen, setIsLoginDialogOpen, login } = useAuth();
|
const { isLoginDialogOpen, setIsLoginDialogOpen, login } = useAuth();
|
||||||
|
const { register, handleSubmit } = useForm<LoginForm>();
|
||||||
|
|
||||||
const [email, setEmail] = useState("");
|
const onSubmit: SubmitHandler<LoginForm> = (data) => {
|
||||||
const [password, setPassword] = useState("");
|
login(data.email, data.password);
|
||||||
|
|
||||||
const handleSubmit = () => {
|
|
||||||
login(email, password);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setIsLoginDialogOpen(false);
|
setIsLoginDialogOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isLoginDialogOpen} onClose={handleClose}>
|
<Dialog open={isLoginDialogOpen} onClose={handleClose}>
|
||||||
<DialogTitle>Login</DialogTitle>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<DialogContent>
|
<DialogTitle>Login</DialogTitle>
|
||||||
<TextField
|
<DialogContent>
|
||||||
autoFocus
|
<TextField
|
||||||
margin="dense"
|
required
|
||||||
label="Email Address"
|
{...register("email")}
|
||||||
type="email"
|
autoFocus
|
||||||
fullWidth
|
margin="dense"
|
||||||
variant="standard"
|
label="Email"
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
type="email"
|
||||||
/>
|
fullWidth
|
||||||
<TextField
|
variant="standard"
|
||||||
margin="dense"
|
/>
|
||||||
label="Password"
|
<TextField
|
||||||
type="password"
|
required
|
||||||
fullWidth
|
{...register("password")}
|
||||||
variant="standard"
|
margin="dense"
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
label="Password"
|
||||||
/>
|
type="password"
|
||||||
</DialogContent>
|
fullWidth
|
||||||
<DialogActions>
|
variant="standard"
|
||||||
<Button onClick={handleClose}>Cancel</Button>
|
/>
|
||||||
<Button onClick={handleSubmit}>Confirm</Button>
|
</DialogContent>
|
||||||
</DialogActions>
|
<DialogActions>
|
||||||
|
<Button onClick={handleClose}>Cancel</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</form>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ export const NewAccount = () => {
|
|||||||
label="Email Address"
|
label="Email Address"
|
||||||
type="email"
|
type="email"
|
||||||
variant="standard"
|
variant="standard"
|
||||||
|
required
|
||||||
{...register("email", {
|
{...register("email", {
|
||||||
required: true,
|
|
||||||
pattern: {
|
pattern: {
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||||
message: "Invalid email address",
|
message: "Invalid email address",
|
||||||
@@ -71,7 +71,8 @@ export const NewAccount = () => {
|
|||||||
label="Password"
|
label="Password"
|
||||||
type="password"
|
type="password"
|
||||||
variant="standard"
|
variant="standard"
|
||||||
{...register("password", { required: true, minLength: 8 })}
|
required
|
||||||
|
{...register("password", { minLength: 8 })}
|
||||||
/>
|
/>
|
||||||
<Stack direction="row-reverse" spacing={3}>
|
<Stack direction="row-reverse" spacing={3}>
|
||||||
<LoadingButton type="submit" loading={loading} variant="contained">
|
<LoadingButton type="submit" loading={loading} variant="contained">
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export const NewProjectAction = ({ mutate }: NewProjectActionProps) => {
|
|||||||
<DialogTitle>New project</DialogTitle>
|
<DialogTitle>New project</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<TextField
|
<TextField
|
||||||
|
required
|
||||||
{...register("name")}
|
{...register("name")}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
autoFocus
|
autoFocus
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const AddTask = () => {
|
|||||||
<Box onSubmit={handleSubmit(onSubmit)} component={"form"}>
|
<Box onSubmit={handleSubmit(onSubmit)} component={"form"}>
|
||||||
<Toolbar sx={{ display: "flex", justifyContent: "center" }}>
|
<Toolbar sx={{ display: "flex", justifyContent: "center" }}>
|
||||||
<TextField
|
<TextField
|
||||||
|
required
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
placeholder="New task description "
|
placeholder="New task description "
|
||||||
variant="standard"
|
variant="standard"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
TextField,
|
TextField,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { SetStateAction, useState } from "react";
|
import { SetStateAction, useEffect, useState } from "react";
|
||||||
import { SubmitHandler, useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { useAuth } from "../../../../hooks/useAuth";
|
import { useAuth } from "../../../../hooks/useAuth";
|
||||||
import { useProject } from "../../../../hooks/useProject";
|
import { useProject } from "../../../../hooks/useProject";
|
||||||
@@ -27,14 +27,14 @@ export const RenameProjectDialog = ({
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const { apiClient } = useAuth();
|
const { apiClient } = useAuth();
|
||||||
const { projectMutate, project } = useProject();
|
const { projectMutate, project } = useProject();
|
||||||
const { register, handleSubmit, reset } = useForm<RenameProjectForm>({
|
const { register, handleSubmit, setValue } = useForm<RenameProjectForm>();
|
||||||
defaultValues: {
|
|
||||||
name: project.name,
|
useEffect(() => {
|
||||||
},
|
setValue("name", project.name);
|
||||||
});
|
}, [setValue, project.name]);
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
reset();
|
setValue("name", project.name);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,6 +59,7 @@ export const RenameProjectDialog = ({
|
|||||||
<DialogTitle>Rename project</DialogTitle>
|
<DialogTitle>Rename project</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<TextField
|
<TextField
|
||||||
|
required
|
||||||
{...register("name")}
|
{...register("name")}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
autoFocus
|
autoFocus
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
TextField,
|
TextField,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { SetStateAction, useState } from "react";
|
import { SetStateAction, useEffect, useState } from "react";
|
||||||
import { SubmitHandler, useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { useAuth } from "../../../../../hooks/useAuth";
|
import { useAuth } from "../../../../../hooks/useAuth";
|
||||||
import { useProject } from "../../../../../hooks/useProject";
|
import { useProject } from "../../../../../hooks/useProject";
|
||||||
@@ -30,12 +30,14 @@ export const EditTaskDialog = ({
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const { apiClient } = useAuth();
|
const { apiClient } = useAuth();
|
||||||
const { tasksMutate, project } = useProject();
|
const { tasksMutate, project } = useProject();
|
||||||
const { register, handleSubmit, reset } = useForm<EditProjectForm>({
|
const { register, handleSubmit, setValue } = useForm<EditProjectForm>();
|
||||||
defaultValues: task,
|
|
||||||
});
|
useEffect(() => {
|
||||||
|
setValue("description", task.description);
|
||||||
|
}, [setValue, task.description]);
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
reset();
|
setValue("description", task.description);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ export const EditTaskDialog = ({
|
|||||||
<DialogTitle>Rename task</DialogTitle>
|
<DialogTitle>Rename task</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<TextField
|
<TextField
|
||||||
|
required
|
||||||
{...register("description")}
|
{...register("description")}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
autoFocus
|
autoFocus
|
||||||
|
|||||||
Reference in New Issue
Block a user