Ott 487 registration fields (#183)

* refactor(#487): left only name, lastname, email and password fields in registration (#180)

* refactor(#487): moved all User account feauter components into components folder (#182)

* refactor(#487): moved back global hooks into user account feature (#181)
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent 64966e942e
commit b0bd43aad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      src/features/Register/components/RegistrationStep/hooks/index.tsx
  2. 31
      src/features/Register/components/RegistrationStep/hooks/useSubmitHandler.tsx
  3. 50
      src/features/Register/components/RegistrationStep/hooks/useValidateForm.tsx
  4. 65
      src/features/Register/components/RegistrationStep/index.tsx
  5. 0
      src/features/UserAccount/components/CardNumber/index.tsx
  6. 0
      src/features/UserAccount/components/CardNumber/styled.tsx
  7. 0
      src/features/UserAccount/components/PageTitle/index.tsx
  8. 0
      src/features/UserAccount/components/PageTitle/styled.tsx
  9. 0
      src/features/UserAccount/components/PlusIcon/index.tsx
  10. 0
      src/features/UserAccount/components/PlusIcon/styled.tsx
  11. 0
      src/features/UserAccount/components/TextNoBorder/index.tsx
  12. 2
      src/features/UserAccount/components/TextNoBorder/styled.tsx
  13. 0
      src/features/UserAccount/components/UserAccountButton/index.tsx
  14. 2
      src/features/UserAccount/components/UserAccountButton/styled.tsx
  15. 0
      src/features/UserAccount/components/UserAccountSubscription/index.tsx
  16. 0
      src/features/UserAccount/components/UserAccountSubscription/styled.tsx
  17. 0
      src/features/UserAccount/components/VisaLogo/index.tsx
  18. 0
      src/features/UserAccount/components/VisaLogo/styled.tsx
  19. 7
      src/features/UserAccount/hooks/index.tsx
  20. 0
      src/features/UserAccount/hooks/useCities.tsx
  21. 0
      src/features/UserAccount/hooks/useCountries.tsx
  22. 16
      src/features/UserAccount/hooks/useUserInfoForm.tsx
  23. 0
      src/features/UserAccount/hooks/useValidateForm.tsx
  24. 379
      src/features/UserAccount/index.tsx
  25. 8
      src/helpers/isValidPassword/__tests__/index.tsx
  26. 13
      src/helpers/isValidPassword/index.tsx
  27. 69
      src/hooks/useValidateForm.tsx
  28. 24
      src/requests/register.tsx

@ -0,0 +1,39 @@
import type { FocusEvent } from 'react'
import { useCallback } from 'react'
import trim from 'lodash/trim'
import { isValidEmail } from 'helpers/isValidEmail'
import { formIds } from 'config/form'
import { useForm } from 'features/FormStore'
import { useSubmitHandler } from './useSubmitHandler'
export const useRegistrationForm = () => {
const {
readFormError,
readFormValue,
updateFormError,
updateFormValue,
} = useForm()
const handleSubmit = useSubmitHandler()
const onEmailBlur = useCallback(({ target }: FocusEvent<HTMLInputElement>) => {
const email = trim(target.value)
if (email && !isValidEmail(email)) {
updateFormError(formIds.email, 'error_invalid_email_format')
}
}, [updateFormError])
return {
handleSubmit,
onEmailBlur,
readFormError,
readFormValue,
updateFormError,
updateFormValue,
}
}

@ -2,25 +2,14 @@ import type { FormEvent } from 'react'
import trim from 'lodash/trim'
import type { City } from 'requests'
import { formIds } from 'config/form'
import { useAuthStore } from 'features/AuthStore'
import { useForm } from 'features/FormStore'
import type { SelectedCountry } from 'hooks/useCountries'
import { useValidateForm } from 'hooks/useValidateForm'
type Args = {
selectedCity: City | null,
selectedCountry: SelectedCountry,
}
import { useValidateForm } from './useValidateForm'
export const useSubmitHandler = ({
selectedCity,
selectedCountry,
}: Args) => {
export const useSubmitHandler = () => {
const { register } = useAuthStore()
const { readFormValue } = useForm()
const validateForm = useValidateForm()
@ -30,31 +19,17 @@ export const useSubmitHandler = ({
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
if (validateForm() && selectedCountry) {
if (validateForm()) {
const firstname = readTrimmedValue(formIds.firstname)
const lastname = readTrimmedValue(formIds.lastname)
const phone = readTrimmedValue(formIds.phone)
const email = readTrimmedValue(formIds.email)
const password = readTrimmedValue(formIds.password)
const postalCode = Number(readTrimmedValue(formIds.postalCode))
const region = readTrimmedValue(formIds.region)
const address1 = readTrimmedValue(formIds.address1)
const address2 = readTrimmedValue(formIds.address2)
const city = readTrimmedValue(formIds.city)
register({
address1,
address2,
city,
cityId: selectedCity?.id,
countryId: selectedCountry.id,
email,
firstname,
lastname,
password,
phone,
postalCode,
region,
})
}
}

@ -0,0 +1,50 @@
import trim from 'lodash/trim'
import { formIds } from 'config/form'
import { isValidEmail } from 'helpers/isValidEmail'
import { isValidPassword } from 'helpers/isValidPassword'
import { useForm } from 'features/FormStore'
export const useValidateForm = () => {
const {
readFormValue,
updateFormError,
} = useForm()
const readTrimmedValue = (fieldName: string) => trim(readFormValue(fieldName))
const validateForm = () => {
let hasError = false
const firstname = readTrimmedValue(formIds.firstname)
const lastname = readTrimmedValue(formIds.lastname)
const email = readTrimmedValue(formIds.email)
const password = readTrimmedValue(formIds.password)
if (!firstname) {
updateFormError(formIds.firstname, 'error_fill_out_this_field')
hasError = true
}
if (!lastname) {
updateFormError(formIds.lastname, 'error_fill_out_this_field')
hasError = true
}
if (!email) {
updateFormError(formIds.email, 'error_empty_email')
hasError = true
} else if (!isValidEmail(email)) {
updateFormError(formIds.email, 'error_invalid_email_format')
hasError = true
}
if (!password) {
updateFormError(formIds.password, 'error_empty_password')
hasError = true
} else if (!isValidPassword(password)) {
updateFormError(formIds.password, 'error_simple_password')
hasError = true
}
return !hasError
}
return validateForm
}

@ -3,7 +3,6 @@ import React from 'react'
import { formIds } from 'config/form'
import { T9n } from 'features/T9n'
import { Combobox } from 'features/Combobox'
import { Input, ButtonSolid } from 'features/Common'
import { Error } from 'features/Common/Input/styled'
import {
@ -13,20 +12,14 @@ import {
} from 'features/Login/styled'
import { FormStore } from 'features/FormStore'
import { useRegistrationForm } from 'hooks/useForm'
import { useRegistrationForm } from './hooks'
const labelWidth = 116
const Registration = () => {
const {
cities,
countries,
handleSubmit,
onCitySelect,
onCountrySelect,
onEmailBlur,
onPhoneBlur,
onRegionOrCityChange,
readFormError,
readFormValue,
updateFormValue,
@ -68,62 +61,6 @@ const Registration = () => {
labelWidth={labelWidth}
onChange={updateFormValue(formIds.password)}
/>
<Combobox
withArrow
value={readFormValue(formIds.country)}
error={readFormError(formIds.country)}
labelLexic='form_country'
labelWidth={labelWidth}
options={countries}
onChange={updateFormValue(formIds.country)}
onSelect={onCountrySelect}
/>
<Input
value={readFormValue(formIds.region)}
error={readFormError(formIds.region)}
labelLexic='form_region'
labelWidth={labelWidth}
onChange={onRegionOrCityChange(formIds.region)}
/>
<Combobox
value={readFormValue(formIds.city)}
error={readFormError(formIds.city)}
labelLexic='form_city'
labelWidth={labelWidth}
onChange={onRegionOrCityChange(formIds.city)}
options={cities}
onSelect={onCitySelect}
/>
<Input
value={readFormValue(formIds.postalCode)}
error={readFormError(formIds.postalCode)}
labelLexic='form_postal_code'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.postalCode)}
/>
<Input
value={readFormValue(formIds.address1)}
error={readFormError(formIds.address1)}
labelLexic='form_address1'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.address1)}
/>
<Input
value={readFormValue(formIds.address2)}
error={readFormError(formIds.address2)}
labelLexic='form_address2'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.address2)}
/>
<Input
value={readFormValue(formIds.phone)}
error={readFormError(formIds.phone)}
type='tel'
labelLexic='form_phone'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.phone)}
onBlur={onPhoneBlur}
/>
<ButtonsBlock>
<ButtonSolid type='submit'>
<T9n t='next' />

@ -11,7 +11,7 @@ export const TextNoBorderWrapper = styled.div`
border: none;
margin-top: 20px;
width: 100%;
${PriceWrapper} {
margin-right: 0;
}

@ -12,7 +12,7 @@ export const UserAccountButtonWrapper = styled.div`
border-radius: 2px;
margin-top: 20px;
width: 100%;
&:hover {
cursor: pointer;
}

@ -13,9 +13,8 @@ import type { UserInfo } from 'requests/saveUserInfo'
import { getUserInfo } from 'requests/getUserInfo'
import { saveUserInfo } from 'requests/saveUserInfo'
import type { SelectedCountry } from 'hooks/useCountries'
import { useRegistrationForm } from 'hooks/useForm'
import type { SelectedCountry } from './useCountries'
import { useUserInfoForm } from './useUserInfoForm'
import { useValidateForm } from './useValidateForm'
export const useUserInfo = () => {
@ -37,7 +36,7 @@ export const useUserInfo = () => {
selectedCity,
updateFormError,
updateFormValue,
} = useRegistrationForm()
} = useUserInfoForm()
const readTrimmedValue = useCallback(
(fieldName: string) => trim(readFormValue(fieldName)),

@ -10,19 +10,18 @@ import { isValidEmail } from 'helpers/isValidEmail'
import { isValidPhone } from 'helpers/isValidPhone'
import { formatPhoneCode } from 'helpers/formatPhoneCode'
import type { SelectedCountry } from 'hooks/useCountries'
import { useCountries } from 'hooks/useCountries'
import { useCities } from 'hooks/useCities'
import { formIds } from 'config/form'
import { useForm } from 'features/FormStore'
import { useSubmitHandler } from 'features/Register/components/RegistrationStep/hooks/useSubmitHandler'
import { useLexicsStore } from 'features/LexicsStore'
import type { SelectedCountry } from './useCountries'
import { useCountries } from './useCountries'
import { useCities } from './useCities'
type Name = 'name_rus' | 'name_eng'
export const useRegistrationForm = () => {
export const useUserInfoForm = () => {
const {
readFormError,
readFormValue,
@ -45,10 +44,6 @@ export const useRegistrationForm = () => {
selectedCity,
} = useCities()
const handleSubmit = useSubmitHandler({
selectedCity,
selectedCountry,
})
const { suffix } = useLexicsStore()
const onEmailBlur = useCallback(({ target }: FocusEvent<HTMLInputElement>) => {
@ -121,7 +116,6 @@ export const useRegistrationForm = () => {
cities,
countries,
getCities,
handleSubmit,
onCitySelect,
onCountrySelect,
onEmailBlur,

@ -3,7 +3,6 @@ import React from 'react'
import { userAccountLexics } from 'config/lexics/userAccount'
import { formIds } from 'config/form'
import { Background } from 'features/Background'
import { Combobox } from 'features/Combobox'
import { Input } from 'features/Common'
import { Form } from 'features/Login/styled'
@ -11,11 +10,11 @@ import { T9n } from 'features/T9n'
import { Error } from 'features/Common/Input/styled'
import { useLexicsStore, useLexicsConfig } from 'features/LexicsStore'
import { CardNumber } from './CardNumber'
import { UserAccountButton } from './UserAccountButton'
import { PageTitle } from './PageTitle'
import { UserAccountSubscription } from './UserAccountSubscription'
import { TextNoBorder } from './TextNoBorder'
import { CardNumber } from './components/CardNumber'
import { UserAccountButton } from './components/UserAccountButton'
import { PageTitle } from './components/PageTitle'
import { UserAccountSubscription } from './components/UserAccountSubscription'
import { TextNoBorder } from './components/TextNoBorder'
import { useUserInfo } from './hooks'
import {
@ -51,191 +50,189 @@ export const UserAccount = () => {
return (
<UserAccountComponentWrapper>
<Background>
<UserAccountWrapper>
<PageTitle titleText={translate('user_account')} />
<UserAccountFormWrapper>
<FormWrapper>
<Form>
<UserAccountBlockTitle>
<T9n t='main' />
</UserAccountBlockTitle>
<Input
value={readFormValue(formIds.firstname)}
labelLexic='name'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.firstname)}
error={readFormError(formIds.firstname)}
editIcon
maxLength={500}
/>
<Input
value={readFormValue(formIds.lastname)}
labelLexic='lastname'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.lastname)}
error={readFormError(formIds.lastname)}
editIcon
maxLength={500}
/>
<Input
onBlur={onPhoneBlur}
value={readFormValue(formIds.phone)}
labelLexic='phone'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.phone)}
error={readFormError(formIds.phone)}
editIcon
maxLength={100}
/>
<Input
value={readFormValue(formIds.password)}
error={readFormError(formIds.password)}
type='password'
labelLexic='form_password'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.password)}
editIcon
maxLength={500}
/>
<Combobox
value={readFormValue(formIds.country)}
error={readFormError(formIds.country)}
labelLexic='form_country'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.country)}
options={countries}
onSelect={onCountrySelect}
withArrow
/>
<Input
value={readFormValue(formIds.postalCode)}
error={readFormError(formIds.postalCode)}
labelLexic='form_postal_code'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.postalCode)}
editIcon
/>
<Input
value={readFormValue(formIds.region)}
error={readFormError(formIds.region)}
labelLexic='form_region'
labelWidth={labelWidth}
onChange={onRegionOrCityChange(formIds.region)}
editIcon
maxLength={500}
/>
<Combobox
value={readFormValue(formIds.city)}
error={readFormError(formIds.city)}
labelLexic='form_city'
labelWidth={labelWidth}
onChange={onRegionOrCityChange(formIds.city)}
options={cities}
onSelect={onCitySelect}
maxLength={500}
/>
<Input
value={readFormValue(formIds.address1)}
error={readFormError(formIds.address1)}
labelLexic='form_address1'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.address1)}
editIcon
maxLength={500}
/>
<Input
value={readFormValue(formIds.address2)}
error={readFormError(formIds.address2)}
labelLexic='form_address2'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.address2)}
editIcon
maxLength={500}
/>
<ButtonWrapper>
<OutlinedButton
type='button'
onClick={handleSubmit}
ref={saveButton}
>
<T9n t='save_changes' />
</OutlinedButton>
<Error t={readFormError(formIds.formError) || ''} />
</ButtonWrapper>
</Form>
</FormWrapper>
<FormWrapper>
<Form>
<UserAccountBlockTitle>
<T9n t='payment' />
</UserAccountBlockTitle>
<CardNumber visa label='1234 1234 1234 1234' />
<CardNumber checked label='1234 1234 1234 1234' />
<CardNumber label='1234 1234 1234 1234' />
<UserAccountButton text={translate('add_card')} />
</Form>
</FormWrapper>
<FormWrapper>
<Form>
<UserAccountBlockTitle>
<T9n t='subscriptions' />
</UserAccountBlockTitle>
<UserAccountSubscription
amount={1999}
checked
inputType='radio'
packageName='Базовая'
packageAction={translate('add_card')}
/>
<UserAccountSubscription
noMarginBottom
amount={1999}
checked
inputType='checkbox'
label='Российская Премьер-Лига'
/>
<UserAccountSubscription
noMarginTop
noMarginBottom
amount={499}
checked
inputType='checkbox'
label='Primera División'
/>
<UserAccountSubscription
noMarginTop
noMarginBottom
amount={499}
checked
inputType='checkbox'
label='Primera División'
/>
<UserAccountSubscription
noMarginTop
noMarginBottom
amount={499}
checked
inputType='checkbox'
label='Primera División'
/>
<UserAccountSubscription
noMarginTop
amount={299}
checked
inputType='checkbox'
label='Manchester United'
/>
<UserAccountButton text={translate('select_subscription')} />
<TextNoBorder
text={`${translate('next_debit')} 31.02.2020`}
amount={4796}
/>
</Form>
</FormWrapper>
</UserAccountFormWrapper>
</UserAccountWrapper>
</Background>
<UserAccountWrapper>
<PageTitle titleText={translate('user_account')} />
<UserAccountFormWrapper>
<FormWrapper>
<Form>
<UserAccountBlockTitle>
<T9n t='main' />
</UserAccountBlockTitle>
<Input
value={readFormValue(formIds.firstname)}
labelLexic='name'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.firstname)}
error={readFormError(formIds.firstname)}
editIcon
maxLength={500}
/>
<Input
value={readFormValue(formIds.lastname)}
labelLexic='lastname'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.lastname)}
error={readFormError(formIds.lastname)}
editIcon
maxLength={500}
/>
<Input
onBlur={onPhoneBlur}
value={readFormValue(formIds.phone)}
labelLexic='phone'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.phone)}
error={readFormError(formIds.phone)}
editIcon
maxLength={100}
/>
<Input
value={readFormValue(formIds.password)}
error={readFormError(formIds.password)}
type='password'
labelLexic='form_password'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.password)}
editIcon
maxLength={500}
/>
<Combobox
value={readFormValue(formIds.country)}
error={readFormError(formIds.country)}
labelLexic='form_country'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.country)}
options={countries}
onSelect={onCountrySelect}
withArrow
/>
<Input
value={readFormValue(formIds.postalCode)}
error={readFormError(formIds.postalCode)}
labelLexic='form_postal_code'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.postalCode)}
editIcon
/>
<Input
value={readFormValue(formIds.region)}
error={readFormError(formIds.region)}
labelLexic='form_region'
labelWidth={labelWidth}
onChange={onRegionOrCityChange(formIds.region)}
editIcon
maxLength={500}
/>
<Combobox
value={readFormValue(formIds.city)}
error={readFormError(formIds.city)}
labelLexic='form_city'
labelWidth={labelWidth}
onChange={onRegionOrCityChange(formIds.city)}
options={cities}
onSelect={onCitySelect}
maxLength={500}
/>
<Input
value={readFormValue(formIds.address1)}
error={readFormError(formIds.address1)}
labelLexic='form_address1'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.address1)}
editIcon
maxLength={500}
/>
<Input
value={readFormValue(formIds.address2)}
error={readFormError(formIds.address2)}
labelLexic='form_address2'
labelWidth={labelWidth}
onChange={updateFormValue(formIds.address2)}
editIcon
maxLength={500}
/>
<ButtonWrapper>
<OutlinedButton
type='button'
onClick={handleSubmit}
ref={saveButton}
>
<T9n t='save_changes' />
</OutlinedButton>
<Error t={readFormError(formIds.formError) || ''} />
</ButtonWrapper>
</Form>
</FormWrapper>
<FormWrapper>
<Form>
<UserAccountBlockTitle>
<T9n t='payment' />
</UserAccountBlockTitle>
<CardNumber visa label='1234 1234 1234 1234' />
<CardNumber checked label='1234 1234 1234 1234' />
<CardNumber label='1234 1234 1234 1234' />
<UserAccountButton text={translate('add_card')} />
</Form>
</FormWrapper>
<FormWrapper>
<Form>
<UserAccountBlockTitle>
<T9n t='subscriptions' />
</UserAccountBlockTitle>
<UserAccountSubscription
amount={1999}
checked
inputType='radio'
packageName='Базовая'
packageAction={translate('add_card')}
/>
<UserAccountSubscription
noMarginBottom
amount={1999}
checked
inputType='checkbox'
label='Российская Премьер-Лига'
/>
<UserAccountSubscription
noMarginTop
noMarginBottom
amount={499}
checked
inputType='checkbox'
label='Primera División'
/>
<UserAccountSubscription
noMarginTop
noMarginBottom
amount={499}
checked
inputType='checkbox'
label='Primera División'
/>
<UserAccountSubscription
noMarginTop
noMarginBottom
amount={499}
checked
inputType='checkbox'
label='Primera División'
/>
<UserAccountSubscription
noMarginTop
amount={299}
checked
inputType='checkbox'
label='Manchester United'
/>
<UserAccountButton text={translate('select_subscription')} />
<TextNoBorder
text={`${translate('next_debit')} 31.02.2020`}
amount={4796}
/>
</Form>
</FormWrapper>
</UserAccountFormWrapper>
</UserAccountWrapper>
</UserAccountComponentWrapper>
)
}

@ -2,15 +2,11 @@ import { isValidPassword } from '..'
it('invalid passwords', () => {
expect(isValidPassword('')).toBeFalsy()
expect(isValidPassword('a')).toBeFalsy()
expect(isValidPassword('1')).toBeFalsy()
expect(isValidPassword('abcdef')).toBeFalsy()
expect(isValidPassword('abcdef@')).toBeFalsy()
expect(isValidPassword('abcdef@123')).toBeFalsy()
expect(isValidPassword('ABcd12$')).toBeFalsy()
})
it('valid passwords', () => {
expect(isValidPassword('a')).toBeTruthy()
expect(isValidPassword('1')).toBeTruthy()
expect(isValidPassword('aASbc!def123$')).toBeTruthy()
expect(isValidPassword('Abcdef@123$')).toBeTruthy()
expect(isValidPassword('Abcd1234')).toBeTruthy()

@ -1,13 +1,6 @@
export const passwordRegex = '^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,500}$'
import trim from 'lodash/trim'
import isEmpty from 'lodash/isEmpty'
const passwordRegExp = new RegExp(passwordRegex)
/**
* At least one upper case English letter, (?=.*?[A-Z])
* At least one lower case English letter, (?=.*?[a-z])
* At least one digit, (?=.*?[0-9])
* Minimum eight in length .{8,} (with the anchors)
*/
export const isValidPassword = (password: string) => (
passwordRegExp.test(password)
!isEmpty(trim(password))
)

@ -1,69 +0,0 @@
import trim from 'lodash/trim'
import reduce from 'lodash/reduce'
import { useForm } from 'features/FormStore'
import { isValidEmail } from 'helpers/isValidEmail'
import { isValidPassword } from 'helpers/isValidPassword'
import { isValidPhone } from 'helpers/isValidPhone'
import {
formIds,
requiredFields,
simpleValidationFields,
} from 'config/form'
export const useValidateForm = () => {
const {
allFieldsEmpty,
isFieldEmpty,
readFormValue,
updateFormError,
} = useForm()
const readTrimmedValue = (fieldName: string) => trim(readFormValue(fieldName))
const setErrorOnEmptyFields = (fieldNames: Array<string>, message: string) => (
reduce(
fieldNames,
(acc, fieldName) => {
if (isFieldEmpty(fieldName)) {
updateFormError(fieldName, message)
return true
}
return acc
},
false,
)
)
const validateForm = () => {
let hasError = false
const email = readTrimmedValue(formIds.email)
const password = readTrimmedValue(formIds.password)
const phone = readTrimmedValue(formIds.phone)
if (allFieldsEmpty(requiredFields)) {
updateFormError(formIds.formError, 'error_fill_out_required_fields')
setErrorOnEmptyFields(requiredFields, '')
return false
}
hasError = setErrorOnEmptyFields(simpleValidationFields, 'error_fill_out_this_field')
if (isFieldEmpty(formIds.email)) {
updateFormError(formIds.email, 'error_empty_email')
hasError = true
} else if (!isValidEmail(email)) {
updateFormError(formIds.email, 'error_invalid_email_format')
hasError = true
}
if (!isValidPassword(password)) {
updateFormError(formIds.password, 'error_simple_password')
hasError = true
}
if (!isValidPhone(phone)) {
updateFormError(formIds.phone, 'error_invalid_phone_format')
hasError = true
}
return !hasError
}
return validateForm
}

@ -14,49 +14,25 @@ type Response = {
}
type Args = {
address1: string,
address2?: string,
city?: string,
cityId?: number,
countryId: number,
email: string,
firstname: string,
lastname: string,
password: string,
phone: string,
postalCode: number,
region: string,
}
export const register = async ({
address1,
address2,
city,
cityId,
countryId,
email,
firstname,
lastname,
password,
phone,
postalCode,
region,
}: Args) => {
const config = {
body: {
params: {
_p_address_line1: address1,
_p_address_line2: address2,
_p_city: city,
_p_city_id: cityId,
_p_country_id: countryId,
_p_email: email,
_p_firstname: firstname,
_p_lastname: lastname,
_p_password: password,
_p_phone: phone,
_p_postal_code: postalCode,
_p_region: region,
},
proc,
},

Loading…
Cancel
Save