Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
fix: validation for password
Browse files Browse the repository at this point in the history
  • Loading branch information
aswathy-deriv committed Feb 21, 2024
1 parent 3f73ee4 commit f50bdfe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
17 changes: 12 additions & 5 deletions src/features/pages/signup-academy-complete/password-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { navigate } from 'gatsby'
import { trading_btn, signup_form_line } from './signup-academy.module.scss'
import AcademyPasswordInput from './academy-input'
import { academy_validation } from './password-validation'
Expand All @@ -17,8 +16,10 @@ type AcademyPasswordFormProps = {

const AcademyPasswordForm = ({ residence }: AcademyPasswordFormProps) => {
const [password, setPassword] = useState('')
const [form_errors, setFormErrors] = useState('')
// const [form_errors, setFormErrors] = useState('')
const [submit_status, setSubmitStatus] = useState('')
const [form_errors, setFormErrors] = useState({ text: '', is_warning: false })

const GoTrading = styled(Button)`
border-radius: 4px;
`
Expand All @@ -35,7 +36,7 @@ const AcademyPasswordForm = ({ residence }: AcademyPasswordFormProps) => {
}

const handleError = () => {
setFormErrors('')
setFormErrors({ text: '', is_warning: false })
}

const params = new URLSearchParams(isBrowser() && location.search)
Expand All @@ -62,6 +63,7 @@ const AcademyPasswordForm = ({ residence }: AcademyPasswordFormProps) => {
setSubmitErrorMsg(response.error.message)
} else {
setSubmitStatus('success')
//setting the session token
handleNavigation()
}
})
Expand All @@ -80,7 +82,7 @@ const AcademyPasswordForm = ({ residence }: AcademyPasswordFormProps) => {
type="password"
label="Create a password"
value={password}
error={form_errors}
error={form_errors?.text}
placeholder="Create a password"
password_icon={true}
onChange={handleInput}
Expand All @@ -97,7 +99,12 @@ const AcademyPasswordForm = ({ residence }: AcademyPasswordFormProps) => {

<Flex.Item className={signup_form_line} />
<div className={trading_btn} onClick={GetDerivAcademy}>
<GoTrading secondary disabled={form_errors || !password}>
<GoTrading
secondary
disabled={
form_errors?.text === '' || form_errors?.is_warning === false || !password
}
>
<Localize translate_text="_t_Go to Deriv Academy_t_" />
</GoTrading>
</div>
Expand Down
20 changes: 13 additions & 7 deletions src/features/pages/signup-academy-complete/password-validation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ export const validation_is_lack_number = (input, min_digit) => input.length + 1

export const passwordValidation = (input) => {
if (!input) {
return localize('_t_You should enter 8-25 characters._t_')
return { text: localize('_t_You should enter 8-25 characters._t_'), is_warning: false }
} else if (password_regex_validate.common_password.test(input)) {
return localize(
`_t_Repeats like “abcabcabc” are only slightly harder to guess than “abc”._t_`,
)
return {
text: localize(
`_t_Repeats like “abcabcabc” are only slightly harder to guess than “abc”._t_`,
),
is_warning: true,
}
} else if (!password_regex_validate.password.test(input)) {
return localize(
`_t_Password should have lower and uppercase English letters with numbers._t_`,
)
return {
text: localize(
`_t_Password should have lower and uppercase English letters with numbers._t_`,
),
is_warning: false,
}
}
}

Expand Down

0 comments on commit f50bdfe

Please sign in to comment.