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 { Formik, Form } from "formik";
import * as Yup from "yup";
import { TextField } from "../Form/TextField";
import { Button } from "../Button";
import { passwordSchema } from "./SignUpForm";
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 }) => (
<Formik
initialValues={{
password: "",
confirmPassword: "",
}}
validationSchema={resetPasswordSchema}
validationSchema={passwordSchema}
onSubmit={async ({ password, confirmPassword }) => {
try {
await accountsService.post("user/recover", {

View File

@ -7,13 +7,19 @@ import { Button } from "../Button";
import accountsService from "../../services/accountsService";
// TODO: better password strength validation
const registrationSchema = Yup.object().shape({
email: Yup.string().required("Email is required").email("Please provide a valid email address"),
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 passwordSchema = Yup.object().shape({
password: Yup.string().required("Password is required"),
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";
export const SignUpForm = ({ onSuccess, onFailure }) => (
@ -77,12 +83,6 @@ export const SignUpForm = ({ onSuccess, onFailure }) => (
error={errors.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
type="password"