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