From 6b733ab739ca84077580983f1efca4ecc6344ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczyk?= Date: Fri, 25 Mar 2022 10:52:28 +0100 Subject: [PATCH] style(dashboard-v2): unify password schemas --- .../src/components/forms/ResetPasswordForm.js | 9 ++------ .../src/components/forms/SignUpForm.js | 22 +++++++++---------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/dashboard-v2/src/components/forms/ResetPasswordForm.js b/packages/dashboard-v2/src/components/forms/ResetPasswordForm.js index 5f3fbf0b..68e8480f 100644 --- a/packages/dashboard-v2/src/components/forms/ResetPasswordForm.js +++ b/packages/dashboard-v2/src/components/forms/ResetPasswordForm.js @@ -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 }) => ( { try { await accountsService.post("user/recover", { diff --git a/packages/dashboard-v2/src/components/forms/SignUpForm.js b/packages/dashboard-v2/src/components/forms/SignUpForm.js index 7ff7ba87..976c0c74 100644 --- a/packages/dashboard-v2/src/components/forms/SignUpForm.js +++ b/packages/dashboard-v2/src/components/forms/SignUpForm.js @@ -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} /> -
-
    -
  • At least 6 characters long
  • -
  • Significantly different from the email
  • -
-