From 0f185833296e8bb391d9df6f7c08df494aaf9173 Mon Sep 17 00:00:00 2001 From: Collin Preston Date: Mon, 3 Jun 2024 15:15:34 -0400 Subject: [PATCH] Flow and format --- .../components/forms/AddlProfileFieldsForm.js | 38 +++++++++++-------- .../src/components/forms/EditProfileForm.js | 26 +++++++------ frontend/public/src/lib/validation.js | 2 +- frontend/public/src/lib/validation_test.js | 30 +-------------- 4 files changed, 40 insertions(+), 56 deletions(-) diff --git a/frontend/public/src/components/forms/AddlProfileFieldsForm.js b/frontend/public/src/components/forms/AddlProfileFieldsForm.js index ab64b0f3e9..46e9b4a77b 100644 --- a/frontend/public/src/components/forms/AddlProfileFieldsForm.js +++ b/frontend/public/src/components/forms/AddlProfileFieldsForm.js @@ -24,21 +24,29 @@ const getInitialValues = (user: User) => ({ email: user.email, legal_address: user.legal_address, user_profile: { - gender: user.user_profile.gender || "", - addl_field_flag: user.user_profile.addl_field_flag, - company: user.user_profile.company || "", - company_size: user.user_profile.company_size || null, - highest_education: user.user_profile.highest_education || null, - industry: user.user_profile.industry || null, - job_function: user.user_profile.job_function || null, - job_title: user.user_profile.job_title || null, - leadership_level: user.user_profile.leadership_level || null, - year_of_birth: user.user_profile.year_of_birth || null, - years_experience: user.user_profile.years_experience || null, - type_is_professional: user.user_profile.type_is_professional || false, - type_is_student: user.user_profile.type_is_student || false, - type_is_educator: user.user_profile.type_is_educator || false, - type_is_other: user.user_profile.type_is_other || false + gender: (user.user_profile && user.user_profile.gender) || "", + addl_field_flag: user.user_profile && user.user_profile.addl_field_flag, + company: (user.user_profile && user.user_profile.company) || "", + company_size: (user.user_profile && user.user_profile.company_size) || null, + highest_education: + (user.user_profile && user.user_profile.highest_education) || null, + industry: (user.user_profile && user.user_profile.industry) || null, + job_function: (user.user_profile && user.user_profile.job_function) || null, + job_title: (user.user_profile && user.user_profile.job_title) || null, + leadership_level: + (user.user_profile && user.user_profile.leadership_level) || null, + year_of_birth: + (user.user_profile && user.user_profile.year_of_birth) || null, + years_experience: + (user.user_profile && user.user_profile.years_experience) || null, + type_is_professional: + (user.user_profile && user.user_profile.type_is_professional) || false, + type_is_student: + (user.user_profile && user.user_profile.type_is_student) || false, + type_is_educator: + (user.user_profile && user.user_profile.type_is_educator) || false, + type_is_other: + (user.user_profile && user.user_profile.type_is_other) || false } }) diff --git a/frontend/public/src/components/forms/EditProfileForm.js b/frontend/public/src/components/forms/EditProfileForm.js index d1832876b6..c5f91050e4 100644 --- a/frontend/public/src/components/forms/EditProfileForm.js +++ b/frontend/public/src/components/forms/EditProfileForm.js @@ -24,17 +24,21 @@ const getInitialValues = (user: User) => ({ email: user.email, legal_address: user.legal_address, user_profile: { - gender: user.user_profile.gender || null, - addl_field_flag: user.user_profile.addl_field_flag, - company: user.user_profile.company || "", - company_size: user.user_profile.company_size || null, - highest_education: user.user_profile.highest_education || null, - industry: user.user_profile.industry || null, - job_function: user.user_profile.job_function || null, - job_title: user.user_profile.job_title || null, - leadership_level: user.user_profile.leadership_level || null, - year_of_birth: user.user_profile.year_of_birth || null, - years_experience: user.user_profile.years_experience || null + gender: (user.user_profile && user.user_profile.gender) || null, + addl_field_flag: user.user_profile && user.user_profile.addl_field_flag, + company: (user.user_profile && user.user_profile.company) || "", + company_size: (user.user_profile && user.user_profile.company_size) || null, + highest_education: + (user.user_profile && user.user_profile.highest_education) || null, + industry: (user.user_profile && user.user_profile.industry) || null, + job_function: (user.user_profile && user.user_profile.job_function) || null, + job_title: (user.user_profile && user.user_profile.job_title) || null, + leadership_level: + (user.user_profile && user.user_profile.leadership_level) || null, + year_of_birth: + (user.user_profile && user.user_profile.year_of_birth) || null, + years_experience: + (user.user_profile && user.user_profile.years_experience) || null } }) diff --git a/frontend/public/src/lib/validation.js b/frontend/public/src/lib/validation.js index a9cd3d7e93..c4769da76f 100644 --- a/frontend/public/src/lib/validation.js +++ b/frontend/public/src/lib/validation.js @@ -23,7 +23,7 @@ export const passwordField = yup .required() .label("Password") -export const changeEmailFormValidation = currentEmail => +export const changeEmailFormValidation = (currentEmail: EmailFormValues) => yup.object().shape({ email: yup .string() diff --git a/frontend/public/src/lib/validation_test.js b/frontend/public/src/lib/validation_test.js index d51f30931f..9ffd5aa436 100644 --- a/frontend/public/src/lib/validation_test.js +++ b/frontend/public/src/lib/validation_test.js @@ -5,8 +5,7 @@ import { ValidationError } from "yup" import { changePasswordFormValidation, resetPasswordFormValidation, - passwordFieldRegex, - usernameFieldRegex + passwordFieldRegex } from "./validation" describe("validation utils", () => { @@ -74,31 +73,4 @@ describe("validation utils", () => { }) }) }) - - describe("Validation Regex", () => { - const passwordRegex = new RegExp(passwordFieldRegex) - const usernameRegex = new RegExp(usernameFieldRegex) - ;[ - ["", false], - ["pass", false], - ["passwor", false], - ["password123", true], - ["password", false] - ].forEach(([value, regexMatch]) => { - it("password regex pattern matching.", () => { - assert.equal(passwordRegex.test(value), regexMatch) - }) - }) - ;[ - ["", false], - [" ", false], - ["ab", false], - ["0123456789012345678901234567890", false], - ["ábc-dèf-123", true] - ].forEach(([value, regexMatch]) => { - it("username regex pattern matching.", () => { - assert.equal(usernameRegex.test(value), regexMatch) - }) - }) - }) })