Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Nuri/fix : Side subscription banner field validation #2123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pages/academy/components/_side-subscription-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ const ArticleEmailBanner = () => {
const handleValidation = (param, type) => {
const message = typeof param === 'object' ? param.target.value : param

if (type == 'email') {
setEmailErrorMsg(validateEmail(message.replace(/\s/g, '')))
if (type === 'email') {
setEmailErrorMsg(validateEmail(message))
}

if (type == 'name') {
if (type === 'name') {
setNameErrorMsg(validateName(message.replace(/\s/g, '')))
}
}
Expand Down Expand Up @@ -294,6 +294,7 @@ const ArticleEmailBanner = () => {
type="text"
value={name}
error={name_error_msg}
maxLength="70"
required
onChange={handleInputNameChange}
/>
Expand Down Expand Up @@ -322,6 +323,7 @@ const ArticleEmailBanner = () => {
id="email"
name="email"
type="text"
maxLength="254"
value={email}
required
onChange={handleInputChange}
Expand Down
32 changes: 19 additions & 13 deletions src/pages/academy/components/_subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,30 @@ const Subscribe = () => {
const { value } = e.target

setName(value)
handleValidation(value)
handleValidation(value, 'name')
}

const handleInputChange = (e) => {
const { value } = e.target

setEmail(value)
handleValidation(value)
handleValidation(value, 'email')
}

const handleValidation = (param) => {
const handleValidation = (param, type) => {
const message = typeof param === 'object' ? param.target.value : param
setNameErrorMsg(validateName(message.replace(/\s/g, '')))
setEmailErrorMsg(validateEmail(message.replace(/\s/g, '')))

if (type === 'email') {
setEmailErrorMsg(validateEmail(message))
}

if (type === 'name') {
setNameErrorMsg(validateName(message.replace(/\s/g, '')))
}
}

const validateEmail = (email) => {
const error_message = validation.email(email) || submit_error_msg
const validateEmail = (email_str) => {
const error_message = validation.email(email_str) || submit_error_msg

if (submit_error_msg) {
setSubmitErrorMsg('')
Expand All @@ -258,8 +264,8 @@ const Subscribe = () => {
return error_message
}

const validateName = (name) => {
const error_message = validation.name(name) || submit_error_msg
const validateName = (name_str) => {
const error_message = validation.name(name_str) || submit_error_msg

if (submit_error_msg) {
setSubmitErrorMsg('')
Expand Down Expand Up @@ -292,8 +298,8 @@ const Subscribe = () => {
e.preventDefault()
setIsSubmitting(true)
const formattedEmail = email.replace(/\s/g, '')
handleValidation(email)
handleValidation(name)
handleValidation(email, 'email')
handleValidation(name, 'name')
const has_error_email = validateEmail(formattedEmail)
const has_error_name = validateName(formattedEmail)

Expand Down Expand Up @@ -350,9 +356,9 @@ const Subscribe = () => {
placeholder={'Your name'}
handleError={clearName}
onChange={handleInputNameChange}
onBlur={handleValidation}
autoComplete="off"
border="unset"
maxLength="70"
height="40px"
focusBorder="var(--color-grey-7)"
/>
Expand All @@ -372,11 +378,11 @@ const Subscribe = () => {
placeholder={'Your email address'}
handleError={clearEmail}
onChange={handleInputChange}
onBlur={handleValidation}
autoComplete="off"
required
border="unset"
height="40px"
maxLength="254"
focusBorder="var(--color-grey-7)"
/>
</InputWrapper>
Expand Down