style(dashboard-v2): unify password schemas

This commit is contained in:
Michał Leszczyk 2022-03-25 10:52:28 +01:00
parent 2664a3c4c4
commit 6b733ab739
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
2 changed files with 13 additions and 18 deletions

View File

@ -1,24 +1,19 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Formik, Form } from "formik"; import { Formik, Form } from "formik";
import * as Yup from "yup";
import { TextField } from "../Form/TextField"; import { TextField } from "../Form/TextField";
import { Button } from "../Button"; import { Button } from "../Button";
import { passwordSchema } from "./SignUpForm";
import accountsService from "../../services/accountsService"; import accountsService from "../../services/accountsService";
const resetPasswordSchema = Yup.object().shape({
password: Yup.string().required("Password is required").min(6, "Password has to be at least 6 characters long"),
confirmPassword: Yup.string().oneOf([Yup.ref("password"), null], "Passwords must match"),
});
export const ResetPasswordForm = ({ token, onSuccess, onFailure }) => ( export const ResetPasswordForm = ({ token, onSuccess, onFailure }) => (
<Formik <Formik
initialValues={{ initialValues={{
password: "", password: "",
confirmPassword: "", confirmPassword: "",
}} }}
validationSchema={resetPasswordSchema} validationSchema={passwordSchema}
onSubmit={async ({ password, confirmPassword }) => { onSubmit={async ({ password, confirmPassword }) => {
try { try {
await accountsService.post("user/recover", { await accountsService.post("user/recover", {

View File

@ -7,13 +7,19 @@ import { Button } from "../Button";
import accountsService from "../../services/accountsService"; import accountsService from "../../services/accountsService";
// TODO: better password strength validation export const passwordSchema = Yup.object().shape({
const registrationSchema = Yup.object().shape({ password: Yup.string().required("Password is required"),
email: Yup.string().required("Email is required").email("Please provide a valid email address"), confirmPassword: Yup.string()
password: Yup.string().required("Password is required").min(6, "Password has to be at least 6 characters long"), .oneOf([Yup.ref("password"), null], "Passwords must match")
confirmPassword: Yup.string().oneOf([Yup.ref("password"), null], "Passwords must match"), .required("Please re-type your password"),
}); });
const registrationSchema = Yup.object()
.shape({
email: Yup.string().required("Email is required").email("Please provide a valid email address"),
})
.concat(passwordSchema);
const USER_EXISTS_ERROR = "identity already belongs to an existing user"; const USER_EXISTS_ERROR = "identity already belongs to an existing user";
export const SignUpForm = ({ onSuccess, onFailure }) => ( export const SignUpForm = ({ onSuccess, onFailure }) => (
@ -77,12 +83,6 @@ export const SignUpForm = ({ onSuccess, onFailure }) => (
error={errors.password} error={errors.password}
touched={touched.password} touched={touched.password}
/> />
<div className="text-xs text-palette-400">
<ul>
<li>At least 6 characters long</li>
<li>Significantly different from the email</li>
</ul>
</div>
<TextField <TextField
type="password" type="password"