Skip to content

Commit

Permalink
fix profile validation and regex error
Browse files Browse the repository at this point in the history
  • Loading branch information
rachellougee committed Aug 31, 2023
1 parent 27f3f5a commit 8ebcbfe
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cms/templates/home_page.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base.html" %}
{% block bodyclass %}{% if show_new_design_hero or show_new_featured_carousel or show_home_page_video_component %}new-design{% endif %}{% endblock %}

{% load static wagtail_img_src feature_img_src %}
{% load wagtailcore_tags wagtailembeds_tags %}
Expand Down Expand Up @@ -171,4 +172,4 @@ <h3>{{ page.video_component_title }}</h3>
}
})
</script>
{% endblock %}
{% endblock %}
1 change: 1 addition & 0 deletions cms/templates/product_page.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base.html" %}
{% block bodyclass %}{% if new_design %}new-design{% endif %}{% endblock %}

{% load static wagtail_img_src feature_img_src %}
{% load wagtailcore_tags wagtailembeds_tags %}
Expand Down
3 changes: 3 additions & 0 deletions frontend/public/scss/home-page/home-page-hero.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
body.new-design {
background: white;
}
.home-page-hero-row {
width: 100%;
height: 600px;
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/scss/meta-product-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
@import "product-page/product-details";
@import "product-page/product-faculty-members";

body {
body.new-design {
background: white;
}
43 changes: 25 additions & 18 deletions frontend/public/src/components/forms/ProfileFormFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,38 @@ import {
usernameFieldErrorMessage
} from "../../lib/validation"

export const NAME_REGEX = "^(?![~!@&)(+:'.?,-]+)([^/\\^$#*=[\\]`%_;<>{}\"|]+)$"
export const NAME_REGEX = /^(?![~!@&)(+:'.?/,`-]+)([^/^$#*=[\]`%_;<>{}"|]+)$/

const seedYear = moment().year()

// Field Error messages
export const NAME_REGEX_FAIL_MESSAGE =
"Name cannot start with a special character ~!@&)(+:'.?,-, and cannot contain any of /^$#*=[]`%_;\\<>{}\"|"
"Name cannot start with a special character (~!@&)(+:'.?/,`-), and cannot contain any of (/^$#*=[]`%_;\\<>{}\"|)"

export const fullNameRegex = "^.{2,255}$"
const fullNameErrorMessage = "Full name must be between 2 and 254 characters."

const countryRegex = "^\\S{2,}$"

export const legalAddressValidation = yup.object().shape({
name: yup.string().label("Full Name"),
name: yup
.string()
.label("Full Name")
.matches(fullNameRegex, fullNameErrorMessage)
.required(),
legal_address: yup.object().shape({
first_name: yup.string().label("First Name"),
last_name: yup.string().label("Last Name"),
country: yup.string().label("Country"),
state: yup
first_name: yup
.string()
.label("First Name")
.matches(NAME_REGEX, NAME_REGEX_FAIL_MESSAGE)
.required(),
last_name: yup
.string()
.label("First Name")
.matches(NAME_REGEX, NAME_REGEX_FAIL_MESSAGE)
.required(),
country: yup.string().label("Country"),
state: yup
.string()
.label("State")
.when("country", {
Expand Down Expand Up @@ -172,7 +184,6 @@ const renderYearOfBirthField = () => {
className="form-control"
autoComplete="bday-year"
aria-describedby="user_profile.year_of_birth_error"
required
>
<option value="">-----</option>
{reverse(range(seedYear - 120, seedYear - 13)).map((year, i) => (
Expand All @@ -181,6 +192,7 @@ const renderYearOfBirthField = () => {
</option>
))}
</Field>
<ErrorMessage name="user_profile.year_of_birth" component={FormError} />
</div>
)
}
Expand Down Expand Up @@ -208,10 +220,8 @@ export const LegalAddressFields = ({
autoComplete="given-name"
aria-describedby="first-name-subtitle"
aria-label="First Name"
required
pattern={NAME_REGEX}
title={NAME_REGEX_FAIL_MESSAGE}
/>
<ErrorMessage name="legal_address.first_name" component={FormError} />
</div>
<div className="form-group">
<label htmlFor="legal_address.last_name" className="fw-bold">
Expand All @@ -224,10 +234,8 @@ export const LegalAddressFields = ({
id="legal_address.last_name"
className="form-control"
autoComplete="family-name"
required
pattern={NAME_REGEX}
title={NAME_REGEX_FAIL_MESSAGE}
/>
<ErrorMessage name="legal_address.last_name" component={FormError} />
</div>
<div className="form-group">
<label htmlFor="name" className="row">
Expand All @@ -246,10 +254,8 @@ export const LegalAddressFields = ({
autoComplete="name"
aria-describedby="full-name-subtitle"
aria-label="Full Name"
required
pattern={fullNameRegex}
title={fullNameErrorMessage}
/>
<ErrorMessage name="name" component={FormError} />
</div>
{isNewAccount ? (
<React.Fragment>
Expand Down Expand Up @@ -335,7 +341,7 @@ export const LegalAddressFields = ({
id="legal_address.state"
className="form-control"
autoComplete="state"
required
aria-describedby="legal_address.state_error"
>
<option value="">-----</option>
{findStates(values.legal_address.country, countries)
Expand All @@ -348,6 +354,7 @@ export const LegalAddressFields = ({
)
: null}
</Field>
<ErrorMessage name="legal_address.state" component={FormError} />
</div>
) : null}
{isNewAccount ? (
Expand Down
4 changes: 2 additions & 2 deletions frontend/public/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = function (env, argv) {
output: {
path: path.resolve(__dirname, "build"),
...(isProduction ? {
filename: "[name]-[chunkhash].js",
chunkFilename: "[id]-[chunkhash].js",
filename: "[name]-[contenthash].js",
chunkFilename: "[id]-[contenthash].js",
crossOriginLoading: "anonymous",
hashFunction: "xxhash64"
} : {
Expand Down

0 comments on commit 8ebcbfe

Please sign in to comment.