From ec571b26d9676ec1a490b7ffa2aea465ec0f899d Mon Sep 17 00:00:00 2001 From: deriv Date: Wed, 27 Sep 2023 12:28:09 +0300 Subject: [PATCH] refactor: ts errors and some fixes --- crowdin/messages.json | 16 ++-- package.json | 1 - src/components/elements/dropdown-search.tsx | 4 + src/features/hooks/use-states-list/index.tsx | 32 +++++++ src/pages/signup-affiliates/_types.ts | 10 +- .../components/_account-details.tsx | 25 ++--- .../components/_account-personal-details.tsx | 95 +++++++++---------- .../components/_account-terms.tsx | 7 +- .../components/_account-type.tsx | 4 +- .../components/_phone_number.tsx | 12 +-- .../components/_signup-status.tsx | 8 ++ .../signup-affiliates/components/_wizard.tsx | 14 +-- src/pages/signup-affiliates/index.tsx | 16 ++-- .../utils/_affiliate-input.tsx | 8 +- .../signup-affiliates/utils/_birth-form.tsx | 21 +--- .../signup-affiliates/utils/_birth-picker.tsx | 8 +- .../validations/_affilaite_validation.tsx | 87 +++++------------ 17 files changed, 184 insertions(+), 184 deletions(-) create mode 100644 src/features/hooks/use-states-list/index.tsx diff --git a/crowdin/messages.json b/crowdin/messages.json index a4269734c8c..0d6049f0189 100644 --- a/crowdin/messages.json +++ b/crowdin/messages.json @@ -179,7 +179,6 @@ "176773798": "0.5%", "176823932": "We may decline your verification documents if they are insufficiently clear, invalid, expired, or have cropped edges.", "176972763": "<0>GLD.US The SPDR Gold Shares ETF tracks the price of gold bullion in the over-the-counter (OTC) market.", - "179083332": "Date", "179737767": "Our legacy options trading platform.", "180412186": "Predict whether the exit spot will be strictly higher or lower than the entry spot at the end of the contract period.", "181754600": "How can I identify emails from impersonators of Deriv customer support?", @@ -637,6 +636,7 @@ "617759430": "Earn commissions when your referral deposits 100 USD – whether it's a single deposit or accumulated over time.", "618453683": "On Deriv, you can trade CFDs with high leverage, enabling you to pay just a fraction of the contract’s value. It will amplify your potential gain and also increase your potential loss.", "619354706": "Max(6.83, -10) ", + "619481945": "Mobile number is required", "619610610": "Close your account at any time you want.", "621291584": "0.75", "622253642": "Save time – no need to open, monitor, and close trades.", @@ -933,7 +933,6 @@ "896028940": "Got more questions?", "896455617": "BAT/USD", "897072394": "deriv.app platform video", - "897219665": "Please enter a valid {{field_name}}", "897325464": "Instruments available for CFD trading", "897732167": "Deriv MT5 logo", "898646134": "To see your account’s trading limits, go to Settings > Security and safety > <0>Account limits.", @@ -984,6 +983,7 @@ "943716510": "Introduction to cryptocurrencies", "944896800": "How does it transform our partnership?", "947541466": "Trade 24/7 on our proprietary synthetics that simulate real-world market movements. These indices are unaffected by regular
market hours, global events, or market and liquidity risks. Manage your exposure by selecting the volatility level to suit your risk appetite.", + "947758334": "City is required", "948545552": "150+", "949617971": "Your Deriv X password is linked to the standalone Deriv X trading platform while your Deriv password gives you access to platforms hosted on our website such as DTrader and DBot.", "949859957": "Submit", @@ -1120,7 +1120,6 @@ "1084407062": "These indices correspond to simulated markets with <0>constant volatilities of 10%, 25%, 50%, 75%, and 100%. There is an equal probability of an up or down jump <0>every 20 minutes, on average. The jump size is <0>around 30 times the normal price movement, on average.", "1084960586": "Disclose the terms of all contracts", "1088428939": "These indices correspond to financial markets with volatilities of 10% and 20%. One tick is generated for every tick of the corresponding forex pair.", - "1089085289": "Mobile number", "1089110190": "You accidentally gave us another email address (usually a work or a personal one instead of the one you meant).", "1089165018": "Get in touch", "1090964405": "Monthly volume requirement", @@ -1969,6 +1968,7 @@ "1872384056": "Light and dark mode features for a more enjoyable experience", "1872568231": "GBP/TRY", "1872607463": "banner", + "1873174451": "Postcode is required", "1873188024": "A deal for 1 lot of the Volatility Index 75 for a price of USD 500,000 per USD 100,000 turnover will pay out a commission of USD 5. The minimum volume required to receive the minimum commission of USD 0.01 is determined using this formula:", "1874424045": "I lost my phone. How can I disable two-factor authentication (2FA)?", "1875123330": "24.88", @@ -2218,6 +2218,7 @@ "2088836522": "1. CVV failure. Please contact your bank to check.", "2089257874": "internal audit department", "2092654058": "To onboard with Deriv Prime’s liquidity solution and trading services, you will need to follow a streamlined process:", + "2094921906": "Street is required", "2095230169": "Reliable", "2097023111": "A low-cost way to trade diverse asset groups", "2097310605": "Why trade synthetics on Deriv", @@ -2235,6 +2236,7 @@ "2109279238": "derived", "2109387636": "How many trading platforms do you offer?", "2109391373": "Fund your account.", + "2109960759": "Company name is required", "2112006652": "FIL/USD", "2112510770": "Check if your browser and device are updated. If they're not, compatibility issues may prevent the email from reaching you.", "2113590447": "To promote Deriv.com, you will need a Deriv.com affiliate link.", @@ -4208,6 +4210,7 @@ "-498923246": "Want to sign up as a trader?", "-1760596315": "Create a Deriv account", "-1986150937": "Thank you for signing up", + "-2017825013": "Got it", "-881644591": "We've having trouble signing you up right now. Please try again in 2 minutes", "-1830091000": "Username already exists. Please enter another:", "-260364285": "Change username", @@ -4217,14 +4220,15 @@ "-1541554430": "Next", "-26610045": "Add an affiliate account", "-435672026": "Wrong email", - "-1267880283": "{{field_name}} is required", "-1787546919": "You should enter ${min_digit}-${max_digit} characters.", "-840841662": "Only Latin characters", + "-1430656728": "Password is required", "-1049534775": "Please enter a valid postcode with Latin characters.", + "-420140433": "Company registration number is required", + "-2146980219": "Please enter a valid state", "-1857429287": "Last Name", - "-1706047929": "Postcode", + "-378415317": "State is required", "-1478320346": "Currency is required", - "-1831906031": "Company registeration number", "-706927392": "Important Guidelines", "-2086585870": "Partners Guide", "-776458472": "General terms of use", diff --git a/package.json b/package.json index 9fab4f761b4..aa8f33f930e 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "prop-types": "^15.8.1", "react": "^18.2.0", "react-date-picker": "8.4.0", - "react": "^18.2.0", "react-device-detect": "^2.2.2", "react-dom": "^18.2.0", "react-hook-form": "^7.43.9", diff --git a/src/components/elements/dropdown-search.tsx b/src/components/elements/dropdown-search.tsx index ae672a8a6d9..2fd3ed7d693 100644 --- a/src/components/elements/dropdown-search.tsx +++ b/src/components/elements/dropdown-search.tsx @@ -92,6 +92,10 @@ const DropdownSearch = ({ } }, [selected_item]) + useEffect(() => { + setDropdownItems([...items]) + }, [items]) + const handleInputChange = (e) => { setInputValue(e.target.value) toggleListVisibility(e) diff --git a/src/features/hooks/use-states-list/index.tsx b/src/features/hooks/use-states-list/index.tsx new file mode 100644 index 00000000000..4e51087e79a --- /dev/null +++ b/src/features/hooks/use-states-list/index.tsx @@ -0,0 +1,32 @@ +import { useEffect, useMemo } from 'react' +import useWS from '../../../components/hooks/useWS' + +export type ResidenceType = { + text: string + value: string +} + +const formatStatesList = (states) => { + if (!states.length) { + return [] + } + + return states?.map( + ({ text }) => + typeof text !== undefined && { + name: text, + display_name: text, + }, + ) +} + +export const useStatesList = (country_code) => { + const { send, data } = useWS('states_list') + + useEffect(() => { + send({ states_list: country_code }) + }, [country_code]) + + const states_list = useMemo(() => formatStatesList(data || []), [data]) + return [states_list] +} diff --git a/src/pages/signup-affiliates/_types.ts b/src/pages/signup-affiliates/_types.ts index ecc2186435e..e3a7a03f5d6 100644 --- a/src/pages/signup-affiliates/_types.ts +++ b/src/pages/signup-affiliates/_types.ts @@ -7,7 +7,7 @@ type AffiliateAccountTypes = { account: { type: number; plan: number } address_details: { country: CountryType - state: string + state: { name?: string; display_name?: string } city: string street: string postal_code: string @@ -17,7 +17,7 @@ type AffiliateAccountTypes = { username: string first_name: string last_name: string - date_birth: string + date_birth: Date website_url: string social_media_url: string password: string @@ -26,9 +26,9 @@ type AffiliateAccountTypes = { currency: string } terms_of_use: { - non_pep_declaration: boolean + non_pep_declaration_accepted: boolean tnc_accepted: boolean - general_terms: boolean + general_terms_accepted: boolean is_eu_checked: boolean is_partner_checked: boolean } @@ -113,7 +113,7 @@ type WizardComponentsProps = WizardComponentTypes & WizardProps type AffiliateData = keyof AffiliateAccountTypes type WizardStepProps = { - affiliate_data: AffiliateAccountTypes[AffiliateData] + affiliate_account: AffiliateAccountTypes updateData: (value: AffiliateAccountTypes[AffiliateData]) => void onValidate: (value: boolean) => void residence_list?: CountryType[] diff --git a/src/pages/signup-affiliates/components/_account-details.tsx b/src/pages/signup-affiliates/components/_account-details.tsx index ebbc45b948d..f6140ca6a8b 100644 --- a/src/pages/signup-affiliates/components/_account-details.tsx +++ b/src/pages/signup-affiliates/components/_account-details.tsx @@ -3,6 +3,7 @@ import styled from 'styled-components' import { WizardStepProps } from '../_types' import AffiliateInput from '../utils/_affiliate-input' import affiliate_validation from '../validations/_affilaite_validation' +import { useStatesList } from 'features/hooks/use-states-list' import { DropdownSearch } from 'components/elements' import { localize } from 'components/localization' import device from 'themes/device' @@ -27,11 +28,12 @@ const InputWrapper = styled.div` ` const AccountDetails = ({ - affiliate_data, + affiliate_account, updateData, onValidate, residence_list, }: WizardStepProps) => { + const affiliate_data = affiliate_account.address_details const [country, setCountry] = useState(affiliate_data.country) const [state, setState] = useState(affiliate_data.state) const [city, setCity] = useState(affiliate_data.city) @@ -43,6 +45,8 @@ const AccountDetails = ({ const [street_error_msg, setStreetErrorMsg] = useState('') const [postcode_error_msg, setPostCodeErrorMsg] = useState('') + const [states_list] = useStatesList(affiliate_data.country?.symbol) + useEffect(() => { updateData({ ...affiliate_data, @@ -56,7 +60,7 @@ const AccountDetails = ({ const validate = country?.name && - state && + state?.name && city && street && postal_code && @@ -85,15 +89,14 @@ const AccountDetails = ({ { id: 'dm-state', name: 'state', - type: 'text', - error: state_error_msg, + type: 'select', label: localize('_t_State/province_t_'), placeholder: 'State/province', - extra_info: ' ', required: true, + error: state_error_msg, value: state, + list: states_list, value_set: setState, - error_set: setStateErrorMsg, }, { id: 'dm-town', @@ -165,16 +168,16 @@ const AccountDetails = ({ {form_inputs.map((item) => { - if (item.name === 'country') { + if (item.name === 'country' || item.name === 'state') { return ( item.value_set(country)} - error={item.error} + label={item.label} items={item.list} - label={localize('_t_Country of residence_t_')} + error={item.error} + selected_item={item.value} + onChange={(value) => item.value_set(value)} /> ) } else { diff --git a/src/pages/signup-affiliates/components/_account-personal-details.tsx b/src/pages/signup-affiliates/components/_account-personal-details.tsx index b3b4552cae2..56e766d2b90 100644 --- a/src/pages/signup-affiliates/components/_account-personal-details.tsx +++ b/src/pages/signup-affiliates/components/_account-personal-details.tsx @@ -31,10 +31,11 @@ const InputWrapper = styled.div` const PersonalDetails = ({ is_individual, - affiliate_data, + affiliate_account, updateData, onValidate, }: WizardStepProps) => { + const affiliate_data = affiliate_account.personal_details const [username, setUsername] = useState(affiliate_data.username) const [first_name, setFirstName] = useState(affiliate_data.first_name) const [last_name, setLastName] = useState(affiliate_data.last_name) @@ -47,14 +48,14 @@ const PersonalDetails = ({ const [social_media_url, setSocialMedia] = useState(affiliate_data.social_media_url) const [password, setPassword] = useState(affiliate_data.password) - const [user_name_error_msg, setUserNameErrorMsg] = useState() - const [first_name_error_msg, setFirstNameErrorMsg] = useState() - const [last_name_error_msg, setLastNameErrorMsg] = useState() - const [company_name_error_msg, setCompanyNameErrorMsg] = useState() - const [company_registration_error_msg, setCompanyRegistrationErrorMsg] = useState() - const [website_url_error_msg, setWebsiteUrlErrorMsg] = useState() - const [social_media_url_error_msg, setSocialMediaErrorMsg] = useState() - const [password_error_msg, setPasswordErrorMsg] = useState() + const [user_name_error_msg, setUserNameErrorMsg] = useState() + const [first_name_error_msg, setFirstNameErrorMsg] = useState() + const [last_name_error_msg, setLastNameErrorMsg] = useState() + const [company_name_error_msg, setCompanyNameErrorMsg] = useState() + const [company_registration_error_msg, setCompanyRegistrationErrorMsg] = useState() + const [website_url_error_msg, setWebsiteUrlErrorMsg] = useState() + const [social_media_url_error_msg, setSocialMediaErrorMsg] = useState() + const [password_error_msg, setPasswordErrorMsg] = useState() const form_inputs = [ { @@ -287,45 +288,43 @@ const PersonalDetails = ({ return ( -
- {getFormFields().map((item) => { - if (item.name === 'date_birth') { - return ( - - ) - } else { - return ( - { - item?.value_set('') - item?.error_set('') - }} - /> - ) - } - })} - + {getFormFields().map((item) => { + if (item.name === 'date_birth') { + return ( + + ) + } else { + return ( + { + item?.value_set('') + item?.error_set('') + }} + /> + ) + } + })}
) diff --git a/src/pages/signup-affiliates/components/_account-terms.tsx b/src/pages/signup-affiliates/components/_account-terms.tsx index 4d07e78623a..941bc60072a 100644 --- a/src/pages/signup-affiliates/components/_account-terms.tsx +++ b/src/pages/signup-affiliates/components/_account-terms.tsx @@ -37,7 +37,8 @@ const CheckBox = styled.input` margin-inline-end: 8px; ` -const AccountTerms = ({ affiliate_data, updateData, onValidate }: WizardStepProps) => { +const AccountTerms = ({ affiliate_account, updateData, onValidate }: WizardStepProps) => { + const affiliate_data = affiliate_account.terms_of_use const [terms_of_use, setTermsOfUse] = useState(affiliate_data) const AgreementData: AgreementDataType[] = [ @@ -67,9 +68,9 @@ const AccountTerms = ({ affiliate_data, updateData, onValidate }: WizardStepProp ] const validate = - terms_of_use['non_pep_declaration'] && + terms_of_use['non_pep_declaration_accepted'] && terms_of_use['tnc_accepted'] && - terms_of_use['general_terms'] && + terms_of_use['general_terms_accepted'] && terms_of_use['is_partner_checked'] useEffect(() => { diff --git a/src/pages/signup-affiliates/components/_account-type.tsx b/src/pages/signup-affiliates/components/_account-type.tsx index 7a9bfe1e13a..e10f728c915 100644 --- a/src/pages/signup-affiliates/components/_account-type.tsx +++ b/src/pages/signup-affiliates/components/_account-type.tsx @@ -157,8 +157,8 @@ const plans: CardProps[] = [ description: '_t_Earn based on each successful referral. <0>Learn more_t_', }, ] -const AccountType = ({ updateData, affiliate_data, onValidate }: WizardStepProps) => { - const [selected_items, setSelectedItems] = useState(affiliate_data) +const AccountType = ({ updateData, affiliate_account, onValidate }: WizardStepProps) => { + const [selected_items, setSelectedItems] = useState(affiliate_account.account) const validate = !!(selected_items.type && selected_items.plan) diff --git a/src/pages/signup-affiliates/components/_phone_number.tsx b/src/pages/signup-affiliates/components/_phone_number.tsx index 6c9c3fbdc50..198cc0e666b 100644 --- a/src/pages/signup-affiliates/components/_phone_number.tsx +++ b/src/pages/signup-affiliates/components/_phone_number.tsx @@ -43,17 +43,13 @@ const PhoneNumberInput = styled(AffiliateInput)` border-radius: 0; ` -const PhoneNumber = ({ - updateData, - onValidate, - affiliate_data: affiliate_number, -}: WizardStepProps) => { - const [phone, setPhone] = useState(affiliate_number.phone) +const PhoneNumber = ({ updateData, onValidate, affiliate_account }: WizardStepProps) => { + const [phone, setPhone] = useState(affiliate_account.phone_number.phone) const [phone_error_msg, setPhoneErrorMsg] = useState('') useEffect(() => { updateData({ - ...affiliate_number, + ...affiliate_account.phone_number, phone, }) }, [phone]) @@ -80,7 +76,7 @@ const PhoneNumber = ({ - {`+${affiliate_number.prefix}`} + {`+${affiliate_account.phone_number.prefix}`} + { + setSignupStatus('') + }} + > + + diff --git a/src/pages/signup-affiliates/components/_wizard.tsx b/src/pages/signup-affiliates/components/_wizard.tsx index 19fcd023042..1b5633c0de2 100644 --- a/src/pages/signup-affiliates/components/_wizard.tsx +++ b/src/pages/signup-affiliates/components/_wizard.tsx @@ -91,9 +91,9 @@ const Wizard = ({ setAffiliateAccount({ ...affiliate_account, terms_of_use: { - non_pep_declaration: value.non_pep_declaration, + non_pep_declaration_accepted: value.non_pep_declaration, tnc_accepted: value.tnc_accepted, - general_terms: value.general_terms, + general_terms_accepted: value.general_terms, is_eu_checked: value.is_eu_checked, is_partner_checked: value.is_partner_checked, }, @@ -113,7 +113,7 @@ const Wizard = ({ onSubmit={onSubmit} > { updateAffiliateValues(value, 'account-type') }} @@ -122,7 +122,7 @@ const Wizard = ({ }} /> { updateAffiliateValues(value, 'account-details') }} @@ -132,7 +132,7 @@ const Wizard = ({ residence_list={residence_list} /> { updateAffiliateValues(value, 'phone-number') }} @@ -141,7 +141,7 @@ const Wizard = ({ }} /> { updateAffiliateValues(value, 'personal-details') @@ -151,7 +151,7 @@ const Wizard = ({ }} /> { updateAffiliateValues(value, 'terms-of-use') }} diff --git a/src/pages/signup-affiliates/index.tsx b/src/pages/signup-affiliates/index.tsx index b2749464736..9aae248203f 100644 --- a/src/pages/signup-affiliates/index.tsx +++ b/src/pages/signup-affiliates/index.tsx @@ -23,7 +23,7 @@ const Submit = ({ is_online, affiliate_account, setSignupStatus, affiliateSend } affiliateSend({ address_city: affiliate_account.address_details.city, address_postcode: affiliate_account.address_details.postal_code, - address_state: affiliate_account.address_details.state, + address_state: affiliate_account.address_details.state.name, address_street: affiliate_account.address_details.street, commission_plan: affiliate_account.account.plan, country: affiliate_account.address_details.country.symbol, @@ -33,7 +33,7 @@ const Submit = ({ is_online, affiliate_account, setSignupStatus, affiliateSend } email: affiliate_account.email, first_name: affiliate_account.personal_details.first_name, last_name: affiliate_account.personal_details.last_name, - non_pep_declaration: affiliate_account.terms_of_use.non_pep_declaration && 1, + non_pep_declaration: affiliate_account.terms_of_use.non_pep_declaration_accepted && 1, over_18_declaration: 1, phone: `+${ affiliate_account.phone_number.prefix + affiliate_account.phone_number.phone @@ -87,7 +87,7 @@ const AffiliateSignup = () => { }, address_details: { country: {}, - state: '', + state: {}, city: '', street: '', postal_code: '', @@ -100,7 +100,7 @@ const AffiliateSignup = () => { username: '', first_name: '', last_name: '', - date_birth: '', + date_birth: null, website_url: 'www.', social_media_url: '', password: '', @@ -109,9 +109,9 @@ const AffiliateSignup = () => { currency: '', }, terms_of_use: { - non_pep_declaration: false, + non_pep_declaration_accepted: false, tnc_accepted: false, - general_terms: false, + general_terms_accepted: false, is_eu_checked: false, is_partner_checked: false, }, @@ -139,7 +139,9 @@ const AffiliateSignup = () => { setSignupStatus(affiliate_api_error?.error.message) } else if ( affiliate_api_error?.error.message == 'Your website is not a valid entry' || - affiliate_api_error?.error.message == "String does not match '^[0-9A-Za-z.-]{5,250}$'" + affiliate_api_error?.error.message == + "String does not match '^[0-9A-Za-z.-]{5,250}$'" || + affiliate_api_error?.error.message == 'Input validation failed: website_url' ) { setSignupStatus('Your website is not a valid entry') } diff --git a/src/pages/signup-affiliates/utils/_affiliate-input.tsx b/src/pages/signup-affiliates/utils/_affiliate-input.tsx index e5100cc39e4..f5861474ce4 100644 --- a/src/pages/signup-affiliates/utils/_affiliate-input.tsx +++ b/src/pages/signup-affiliates/utils/_affiliate-input.tsx @@ -77,14 +77,14 @@ const AffiliateInput = ({ current_input} + {...props} id={id} - background={'white'} + width={500} error={error} showLabel={label} - width={500} + background={'white'} + ref={() => current_input} type={is_password_visible ? 'text' : props.type} - {...props} /> {label && ( diff --git a/src/pages/signup-affiliates/utils/_birth-form.tsx b/src/pages/signup-affiliates/utils/_birth-form.tsx index 85af9d8753c..8deba81ff68 100644 --- a/src/pages/signup-affiliates/utils/_birth-form.tsx +++ b/src/pages/signup-affiliates/utils/_birth-form.tsx @@ -1,24 +1,13 @@ import React from 'react' -import BirthPicker, { SetStateDate } from './_birth-picker' +import BirthPicker from './_birth-picker' import { ExtraInfo, StyledInputWrapper } from './_affiliate-input' -import { InputProps, RelativeWrapper } from 'components/form/input' +import { RelativeWrapper } from 'components/form/input' -type BirthFormProps = { - setFieldValue: SetStateDate - value: Date | [Date, Date] -} & InputProps - -const BirthForm = ({ label, id, error, value, setFieldValue }: BirthFormProps) => { +const BirthForm = (props) => { return ( - - + + diff --git a/src/pages/signup-affiliates/utils/_birth-picker.tsx b/src/pages/signup-affiliates/utils/_birth-picker.tsx index a431db3bdd4..ba09db0ca49 100644 --- a/src/pages/signup-affiliates/utils/_birth-picker.tsx +++ b/src/pages/signup-affiliates/utils/_birth-picker.tsx @@ -1,24 +1,22 @@ import React, { useState } from 'react' import styled, { css } from 'styled-components' import DatePicker from 'react-date-picker' -import { TCertificate } from '../components/_account-personal-details' import { AffiliateLabel } from './_affiliate-input' import Calendar from 'images/svg/signup-affiliates/calendar.svg' export type SetStateDate = | React.Dispatch> - | React.Dispatch> - | React.Dispatch> + | React.Dispatch> type BirthPickerWrapperProps = { is_date_field: boolean - value: Date | [Date, Date] + value: Date error: string } type BirthPickerProps = { id: string error: string - value: Date | [Date, Date] + value: Date setFieldValue: SetStateDate label?: string label_color?: string diff --git a/src/pages/signup-affiliates/validations/_affilaite_validation.tsx b/src/pages/signup-affiliates/validations/_affilaite_validation.tsx index 3a763e25d8d..56e72cc7db0 100644 --- a/src/pages/signup-affiliates/validations/_affilaite_validation.tsx +++ b/src/pages/signup-affiliates/validations/_affilaite_validation.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { localize, Localize } from 'components/localization' +import { localize } from 'components/localization' /* eslint-disable */ export const affiliate_validation_regex = { @@ -23,14 +23,14 @@ const validation_is_lack_number = (input, min_digit) => input.length + 1 > min_d const emailValidation = (input) => { if (!input) { - return + return localize('_t_Email is required_t_') } else if (!affiliate_validation_regex.email.test(input)) { return localize('_t_Wrong email_t_') } } const userNameValidation = (input) => { if (!input) { - return + return localize('_t_User name is required_t_') } else if ( affiliate_validation_regex.latin.test(input) || !affiliate_validation_regex.alphabet.test(input) @@ -38,11 +38,9 @@ const userNameValidation = (input) => { return localize('_t_Only Latin and Alphabet characters_t_') } } -const nameValidation = (input, field_name, min_digit, max_digit) => { +const nameValidation = (input, text, min_digit, max_digit) => { if (!input) { - return ( - - ) + return text } else if ( !validation_is_exceed_number(input, max_digit) || !validation_is_lack_number(input, min_digit) @@ -55,20 +53,10 @@ const nameValidation = (input, field_name, min_digit, max_digit) => { return localize('_t_Only Latin and Alphabet characters_t_') } } - -const dateValidation = (input, field_name) => { - if (!input) { - return ( - - ) - } -} -const textValidation = (input, field_name, min_digit, max_digit) => { +const companyNameValidation = (input, min_digit, max_digit) => { const length_error = localize(`_t_You should enter ${min_digit}-${max_digit} characters._t_`) if (!input) { - return ( - - ) + return localize('_t_Company name is required_t_') } else if (!validation_is_exceed_number(input, max_digit)) { return length_error } else if (!validation_is_lack_number(input, min_digit)) { @@ -77,20 +65,16 @@ const textValidation = (input, field_name, min_digit, max_digit) => { return localize('_t_Only Latin characters_t_') } } -const phoneValidation = (input, field_name) => { +const phoneValidation = (input) => { if (!input) { - return ( - - ) + return localize('_t_Mobile number is required_t_') } else if (!validation_is_exceed_number(input, 11) || !validation_is_lack_number(input, 7)) { return localize(`_t_You should enter 7-11 numbers._t_`) } } -const passwordValidation = (input, field_name, min_digit, max_digit) => { +const passwordValidation = (input, min_digit, max_digit) => { if (!input) { - return ( - - ) + return localize('_t_Password is required_t_') } else if ( !validation_is_exceed_number(input, max_digit) || !validation_is_lack_number(input, min_digit) @@ -103,11 +87,9 @@ const passwordValidation = (input, field_name, min_digit, max_digit) => { } return null } -const postcodeValidation = (input, field_name, min_digit, max_digit) => { +const postcodeValidation = (input, min_digit, max_digit) => { if (!input) { - return ( - - ) + return localize('_t_Postcode is required_t_') } else if ( !validation_is_exceed_number(input, max_digit) || !validation_is_lack_number(input, min_digit) @@ -117,11 +99,9 @@ const postcodeValidation = (input, field_name, min_digit, max_digit) => { return localize(`_t_Please enter a valid postcode with Latin characters._t_`) } } -const registrationNumberValidation = (input, field_name, min_digit, max_digit) => { +const registrationNumberValidation = (input, min_digit, max_digit) => { if (!input) { - return ( - - ) + return localize('_t_Company registration number is required_t_') } else if ( !validation_is_exceed_number(input, max_digit) || !validation_is_lack_number(input, min_digit) @@ -131,11 +111,9 @@ const registrationNumberValidation = (input, field_name, min_digit, max_digit) = return localize(`_t_Please enter a valid company registration number._t_`) } } -const addressValidation = (input, field_name, min_digit, max_digit) => { +const addressValidation = (input, text, min_digit, max_digit) => { if (!input) { - return ( - - ) + return text } if (affiliate_validation_regex.latin.test(input)) { return localize('_t_Only Latin characters_t_') @@ -145,12 +123,7 @@ const addressValidation = (input, field_name, min_digit, max_digit) => { ) { return localize(`_t_You should enter ${min_digit}-${max_digit} characters._t_`) } else if (!affiliate_validation_regex.address.test(input)) { - return ( - - ) + return localize('_t_Please enter a valid state_t_') } } const urlValidation = (input) => { @@ -172,9 +145,6 @@ const affiliate_validation = { last_name: (input) => { return nameValidation(input, localize('_t_Last Name_t_'), 2, 50) }, - date: (input) => { - return dateValidation(input, localize('_t_Date_t_')) - }, country: (input) => { if (!input || input.display_name === '') { return localize('_t_Country is required_t_') @@ -182,34 +152,29 @@ const affiliate_validation = { return null }, address_city: (input) => { - return addressValidation(input, 'City', 2, 256) + return addressValidation(input, localize('_t_City is required_t_'), 2, 256) }, address_state: (input) => { - return addressValidation(input, 'State', 2, 256) + return addressValidation(input, localize('_t_State is required_t_'), 2, 256) }, address_street: (input) => { - return addressValidation(input, 'Street', 2, 256) + return addressValidation(input, localize('_t_Street is required_t_'), 2, 256) }, address_postal_code: (input) => { - return postcodeValidation(input, localize('_t_Postcode_t_'), 5, 10) + return postcodeValidation(input, 5, 10) }, phone: (input) => { - return phoneValidation(input, localize('_t_Mobile number_t_')) + return phoneValidation(input) }, password: (input) => { - return passwordValidation(input, localize('_t_Password_t_'), 6, 50) + return passwordValidation(input, 6, 50) }, currency: (input) => (input ? null : localize('_t_Currency is required_t_')), company_name: (input) => { - return textValidation(input, localize('_t_Company name_t_'), 2, 70) + return companyNameValidation(input, 2, 70) }, company_registration_number: (input) => { - return registrationNumberValidation( - input, - localize('_t_Company registeration number_t_'), - 2, - 20, - ) + return registrationNumberValidation(input, 2, 20) }, website_url: (input) => { return urlValidation(input)