Formatted the code of components
This commit is contained in:
parent
de07c92579
commit
61d31fa3c4
@ -2,27 +2,35 @@ import React, { MouseEvent } from "react";
|
|||||||
import { Card, Button, TextField } from "@mui/material";
|
import { Card, Button, TextField } from "@mui/material";
|
||||||
import "@scss/forgot_password.scss";
|
import "@scss/forgot_password.scss";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
type Inputs = {
|
type Inputs = {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const schema = yup.object().shape({
|
const schema = yup
|
||||||
email: yup.string().email("Please provide a valid email").required("No email was provided")
|
.object()
|
||||||
}).required();
|
.shape({
|
||||||
|
email: yup
|
||||||
|
.string()
|
||||||
|
.email("Please provide a valid email")
|
||||||
|
.required("No email was provided"),
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export default function ForgotPassword() {
|
export default function ForgotPassword() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { register, formState: { errors }, handleSubmit } = useForm<Inputs>({
|
const {
|
||||||
resolver: yupResolver(schema), // yup, joi and even your own.
|
register,
|
||||||
|
formState: { errors },
|
||||||
|
handleSubmit,
|
||||||
|
} = useForm<Inputs>({
|
||||||
|
resolver: yupResolver(schema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const { ref: emailRef, ...emailRegisterProps } = register("email");
|
const { ref: emailRef, ...emailRegisterProps } = register("email");
|
||||||
const emailProps = {
|
const emailProps = {
|
||||||
...emailRegisterProps,
|
...emailRegisterProps,
|
||||||
@ -32,17 +40,19 @@ export default function ForgotPassword() {
|
|||||||
label: "Email",
|
label: "Email",
|
||||||
error: !!errors.email,
|
error: !!errors.email,
|
||||||
helperText: errors?.email?.message,
|
helperText: errors?.email?.message,
|
||||||
}
|
};
|
||||||
|
|
||||||
function buttonCancel(e: MouseEvent<HTMLButtonElement>) {
|
function buttonCancel(e: MouseEvent<HTMLButtonElement>) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
navigate("/login")
|
navigate("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSubmit(data: Inputs) {
|
function onSubmit(data: Inputs) {
|
||||||
console.log("There will be an API call now with the following data");
|
console.log("There will be an API call now with the following data");
|
||||||
console.table(data);
|
console.table(data);
|
||||||
console.log("You can now go to http://localhost:8080/reset to acces the reset form")
|
console.log(
|
||||||
|
"You can now go to http://localhost:8080/reset to acces the reset form"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -51,8 +61,8 @@ export default function ForgotPassword() {
|
|||||||
<Card className="card">
|
<Card className="card">
|
||||||
<h3>Forgot Passowrd</h3>
|
<h3>Forgot Passowrd</h3>
|
||||||
<p>
|
<p>
|
||||||
If you have forgot your password, we can send you an email
|
If you have forgot your password, we can send you an
|
||||||
with a link to reset it.
|
email with a link to reset it.
|
||||||
</p>
|
</p>
|
||||||
<TextField {...emailProps} />
|
<TextField {...emailProps} />
|
||||||
<div className="buttons">
|
<div className="buttons">
|
||||||
@ -63,11 +73,7 @@ export default function ForgotPassword() {
|
|||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button type="submit" id="submit" variant="contained">
|
||||||
type="submit"
|
|
||||||
id="submit"
|
|
||||||
variant="contained"
|
|
||||||
>
|
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,25 +1,35 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Card, Button, TextField } from "@mui/material"
|
import { Card, Button, TextField } from "@mui/material";
|
||||||
import "@scss/login.scss"
|
import "@scss/login.scss";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
type Inputs = {
|
type Inputs = {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const schema = yup.object().shape({
|
const schema = yup
|
||||||
email: yup.string().email("Please provide a valid email").required("No email was provided"),
|
.object()
|
||||||
|
.shape({
|
||||||
|
email: yup
|
||||||
|
.string()
|
||||||
|
.email("Please provide a valid email")
|
||||||
|
.required("No email was provided"),
|
||||||
password: yup.string().required("No password was provided"),
|
password: yup.string().required("No password was provided"),
|
||||||
}).required();
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { register, formState: { errors }, handleSubmit } = useForm<Inputs>({
|
const {
|
||||||
resolver: yupResolver(schema), // yup, joi and even your own.
|
register,
|
||||||
|
formState: { errors },
|
||||||
|
handleSubmit,
|
||||||
|
} = useForm<Inputs>({
|
||||||
|
resolver: yupResolver(schema),
|
||||||
});
|
});
|
||||||
|
|
||||||
function hash(s: string) {
|
function hash(s: string) {
|
||||||
@ -37,7 +47,7 @@ export default function Login() {
|
|||||||
label: "Email",
|
label: "Email",
|
||||||
error: !!errors.email,
|
error: !!errors.email,
|
||||||
helperText: errors?.email?.message,
|
helperText: errors?.email?.message,
|
||||||
}
|
};
|
||||||
|
|
||||||
const { ref: passRef, ...passRegisterProps } = register("password");
|
const { ref: passRef, ...passRegisterProps } = register("password");
|
||||||
|
|
||||||
@ -50,16 +60,15 @@ export default function Login() {
|
|||||||
label: "Password",
|
label: "Password",
|
||||||
error: !!errors.password,
|
error: !!errors.password,
|
||||||
helperText: errors?.password?.message,
|
helperText: errors?.password?.message,
|
||||||
}
|
};
|
||||||
|
|
||||||
function onSubmit(data: Inputs) {
|
function onSubmit(data: Inputs) {
|
||||||
console.log("There will be an API call now with the following data");
|
console.log("There will be an API call now with the following data");
|
||||||
data = { ...data, password: hash(data.password) }
|
data = { ...data, password: hash(data.password) };
|
||||||
console.table(data);
|
console.table(data);
|
||||||
setTimeout(() => navigate("/?logged"), 3000)
|
setTimeout(() => navigate("/?logged"), 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="cardContainer">
|
<main className="cardContainer">
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
@ -67,10 +76,14 @@ export default function Login() {
|
|||||||
<h3>Login</h3>
|
<h3>Login</h3>
|
||||||
<TextField {...emailProps} />
|
<TextField {...emailProps} />
|
||||||
<TextField {...passProps} />
|
<TextField {...passProps} />
|
||||||
<Button type="submit" id="submit" variant="contained">Login</Button>
|
<Button type="submit" id="submit" variant="contained">
|
||||||
<p>Forgot your <Link to="/forgot">password</Link>?</p>
|
Login
|
||||||
|
</Button>
|
||||||
|
<p>
|
||||||
|
Forgot your <Link to="/forgot">password</Link>?
|
||||||
|
</p>
|
||||||
</Card>
|
</Card>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,35 @@
|
|||||||
import React, { ChangeEvent, MouseEvent } from "react";
|
import React, { ChangeEvent, MouseEvent } from "react";
|
||||||
import { Card, Button, TextField } from "@mui/material"
|
import { Card, Button, TextField } from "@mui/material";
|
||||||
import "@scss/reset.scss"
|
import "@scss/reset.scss";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
type Inputs = {
|
type Inputs = {
|
||||||
password: string;
|
password: string;
|
||||||
confirm_password: string;
|
confirm_password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const schema = yup.object().shape({
|
const schema = yup
|
||||||
|
.object()
|
||||||
|
.shape({
|
||||||
password: yup.string().required("No password was provided"),
|
password: yup.string().required("No password was provided"),
|
||||||
confirm_password: yup.string().oneOf([yup.ref('password'), null], 'Passwords must match')
|
confirm_password: yup
|
||||||
}).required();
|
.string()
|
||||||
|
.oneOf([yup.ref("password"), null], "Passwords must match"),
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export default function Reset() {
|
export default function Reset() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { register, formState: { errors }, handleSubmit } = useForm<Inputs>({
|
const {
|
||||||
resolver: yupResolver(schema), // yup, joi and even your own.
|
register,
|
||||||
|
formState: { errors },
|
||||||
|
handleSubmit,
|
||||||
|
} = useForm<Inputs>({
|
||||||
|
resolver: yupResolver(schema),
|
||||||
});
|
});
|
||||||
|
|
||||||
function hash(s: string) {
|
function hash(s: string) {
|
||||||
@ -38,9 +47,10 @@ export default function Reset() {
|
|||||||
label: "Password",
|
label: "Password",
|
||||||
error: !!errors.password,
|
error: !!errors.password,
|
||||||
helperText: errors?.password?.message,
|
helperText: errors?.password?.message,
|
||||||
}
|
};
|
||||||
|
|
||||||
const {ref: confirmPassRef, ...confirmPassRegisterProps} = register("confirm_password");
|
const { ref: confirmPassRef, ...confirmPassRegisterProps } =
|
||||||
|
register("confirm_password");
|
||||||
|
|
||||||
const confirmPassProps = {
|
const confirmPassProps = {
|
||||||
...confirmPassRegisterProps,
|
...confirmPassRegisterProps,
|
||||||
@ -51,13 +61,15 @@ export default function Reset() {
|
|||||||
label: "Confirm Password",
|
label: "Confirm Password",
|
||||||
error: !!errors.confirm_password,
|
error: !!errors.confirm_password,
|
||||||
helperText: errors?.confirm_password?.message,
|
helperText: errors?.confirm_password?.message,
|
||||||
}
|
};
|
||||||
|
|
||||||
function onSubmit(data: Inputs) {
|
function onSubmit(data: Inputs) {
|
||||||
console.log("There will be an API call now with the following data");
|
console.log("There will be an API call now with the following data");
|
||||||
data = {password: hash(data.password), confirm_password: hash(data.confirm_password)}
|
data = {
|
||||||
|
password: hash(data.password),
|
||||||
|
confirm_password: hash(data.confirm_password),
|
||||||
|
};
|
||||||
console.table(data);
|
console.table(data);
|
||||||
// setTimeout(() => navigate("/?logged"), 3000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -67,10 +79,11 @@ export default function Reset() {
|
|||||||
<h3>Reset Password</h3>
|
<h3>Reset Password</h3>
|
||||||
<TextField {...passProps} />
|
<TextField {...passProps} />
|
||||||
<TextField {...confirmPassProps} />
|
<TextField {...confirmPassProps} />
|
||||||
<Button type="submit" id="submit" variant="contained">Reset Password</Button>
|
<Button type="submit" id="submit" variant="contained">
|
||||||
|
Reset Password
|
||||||
|
</Button>
|
||||||
</Card>
|
</Card>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user