@@ -3,54 +3,61 @@ import * as Yup from 'yup';
3
3
import { address_permitted_special_characters_message , getLocation , toMoment } from '@deriv/shared' ;
4
4
import { GetSettings , ResidenceList , StatesList } from '@deriv/api-types' ;
5
5
6
- const BaseSchema = Yup . object ( ) . shape ( {
7
- first_name : Yup . string ( )
8
- . required ( localize ( 'First name is required.' ) )
9
- . min ( 2 , localize ( 'You should enter 2-50 characters.' ) )
10
- . max ( 50 , localize ( 'You should enter 2-50 characters.' ) )
11
- . matches ( / ^ (? ! .* \s { 2 , } ) [ \p{ L} \s ' . - ] { 2 , 50 } $ / u, localize ( 'Letters, spaces, periods, hyphens, apostrophes only.' ) ) ,
12
- last_name : Yup . string ( )
13
- . required ( localize ( 'Last name is required.' ) )
14
- . min ( 2 , localize ( 'You should enter 2-50 characters.' ) )
15
- . max ( 50 , localize ( 'You should enter 2-50 characters.' ) )
16
- . matches ( / ^ (? ! .* \s { 2 , } ) [ \p{ L} \s ' . - ] { 2 , 50 } $ / u, localize ( 'Letters, spaces, periods, hyphens, apostrophes only.' ) ) ,
17
- phone : Yup . string ( )
18
- . required ( localize ( 'Phone is required.' ) )
19
- . min ( 9 , localize ( 'You should enter 9-35 numbers.' ) )
20
- . max ( 35 , localize ( 'You should enter 9-35 characters.' ) )
21
- . matches ( / ^ \+ ? ( [ 0 - 9 - ] + \s ) * [ 0 - 9 - ] + $ / , localize ( 'Please enter a valid phone number (e.g. +15417541234).' ) ) ,
22
- address_line_1 : Yup . string ( )
23
- . trim ( )
24
- . required ( localize ( 'First line of address is required.' ) )
25
- . max ( 70 , localize ( 'Should be less than 70.' ) )
26
- . matches (
27
- / ^ [ \p{ L} \p{ Nd} \s ' . , : ; ( ) \u00b0 @ # / - ] { 0 , 70 } $ / u,
28
- localize ( 'Use only the following special characters: {{permitted_characters}}' , {
29
- permitted_characters : address_permitted_special_characters_message ,
30
- interpolation : { escapeValue : false } ,
31
- } )
32
- ) ,
33
- address_line_2 : Yup . string ( )
34
- . trim ( )
35
- . max ( 70 , localize ( 'Should be less than 70.' ) )
36
- . matches (
37
- / ^ [ \p{ L} \p{ Nd} \s ' . , : ; ( ) \u00b0 @ # / - ] { 0 , 70 } $ / u,
38
- localize ( 'Use only the following special characters: {{permitted_characters}}' , {
39
- permitted_characters : address_permitted_special_characters_message ,
40
- interpolation : { escapeValue : false } ,
41
- } )
42
- ) ,
43
- address_city : Yup . string ( )
44
- . required ( localize ( 'Town/City is required.' ) )
45
- . max ( 70 , localize ( 'Should be less than 70.' ) )
46
- . matches (
47
- / ^ [ A - Z a - z ] + (?: [ . ' - ] * [ A - Z a - z ] + ) { 1 , 70 } $ / ,
48
- localize ( 'Only letters, space, hyphen, period, and apostrophe are allowed.' )
49
- ) ,
50
- address_postcode : Yup . string ( )
51
- . max ( 20 , localize ( 'Please enter a Postal/ZIP code under 20 chatacters.' ) )
52
- . matches ( / ^ [ A - Z a - z 0 - 9 ] [ A - Z a - z 0 - 9 \s - ] * $ / , localize ( 'Only letters, numbers, space, and hyphen are allowed.' ) ) ,
53
- } ) ;
6
+ const getBaseSchema = ( ) =>
7
+ Yup . object ( ) . shape ( {
8
+ first_name : Yup . string ( )
9
+ . required ( localize ( 'First name is required.' ) )
10
+ . min ( 2 , localize ( 'You should enter 2-50 characters.' ) )
11
+ . max ( 50 , localize ( 'You should enter 2-50 characters.' ) )
12
+ . matches (
13
+ / ^ (? ! .* \s { 2 , } ) [ \p{ L} \s ' . - ] { 2 , 50 } $ / u,
14
+ localize ( 'Letters, spaces, periods, hyphens, apostrophes only.' )
15
+ ) ,
16
+ last_name : Yup . string ( )
17
+ . required ( localize ( 'Last name is required.' ) )
18
+ . min ( 2 , localize ( 'You should enter 2-50 characters.' ) )
19
+ . max ( 50 , localize ( 'You should enter 2-50 characters.' ) )
20
+ . matches (
21
+ / ^ (? ! .* \s { 2 , } ) [ \p{ L} \s ' . - ] { 2 , 50 } $ / u,
22
+ localize ( 'Letters, spaces, periods, hyphens, apostrophes only.' )
23
+ ) ,
24
+ phone : Yup . string ( )
25
+ . required ( localize ( 'Phone is required.' ) )
26
+ . min ( 9 , localize ( 'You should enter 9-35 numbers.' ) )
27
+ . max ( 35 , localize ( 'You should enter 9-35 characters.' ) )
28
+ . matches ( / ^ \+ ? ( [ 0 - 9 - ] + \s ) * [ 0 - 9 - ] + $ / , localize ( 'Please enter a valid phone number (e.g. +15417541234).' ) ) ,
29
+ address_line_1 : Yup . string ( )
30
+ . trim ( )
31
+ . required ( localize ( 'First line of address is required.' ) )
32
+ . max ( 70 , localize ( 'Should be less than 70.' ) )
33
+ . matches (
34
+ / ^ [ \p{ L} \p{ Nd} \s ' . , : ; ( ) \u00b0 @ # / - ] { 0 , 70 } $ / u,
35
+ localize ( 'Use only the following special characters: {{permitted_characters}}' , {
36
+ permitted_characters : address_permitted_special_characters_message ,
37
+ interpolation : { escapeValue : false } ,
38
+ } )
39
+ ) ,
40
+ address_line_2 : Yup . string ( )
41
+ . trim ( )
42
+ . max ( 70 , localize ( 'Should be less than 70.' ) )
43
+ . matches (
44
+ / ^ [ \p{ L} \p{ Nd} \s ' . , : ; ( ) \u00b0 @ # / - ] { 0 , 70 } $ / u,
45
+ localize ( 'Use only the following special characters: {{permitted_characters}}' , {
46
+ permitted_characters : address_permitted_special_characters_message ,
47
+ interpolation : { escapeValue : false } ,
48
+ } )
49
+ ) ,
50
+ address_city : Yup . string ( )
51
+ . required ( localize ( 'Town/City is required.' ) )
52
+ . max ( 70 , localize ( 'Should be less than 70.' ) )
53
+ . matches (
54
+ / ^ [ A - Z a - z ] + (?: [ . ' - ] * [ A - Z a - z ] + ) { 1 , 70 } $ / ,
55
+ localize ( 'Only letters, space, hyphen, period, and apostrophe are allowed.' )
56
+ ) ,
57
+ address_postcode : Yup . string ( )
58
+ . max ( 20 , localize ( 'Please enter a Postal/ZIP code under 20 chatacters.' ) )
59
+ . matches ( / ^ [ A - Z a - z 0 - 9 ] [ A - Z a - z 0 - 9 \s - ] * $ / , localize ( 'Only letters, numbers, space, and hyphen are allowed.' ) ) ,
60
+ } ) ;
54
61
55
62
export const getPersonalDetailsInitialValues = (
56
63
account_settings : GetSettings ,
@@ -151,8 +158,8 @@ export const makeSettingsRequest = (
151
158
} ;
152
159
153
160
export const getPersonalDetailsValidationSchema = ( is_eu : boolean ) => {
154
- if ( ! is_eu ) return BaseSchema ;
155
- return BaseSchema . concat (
161
+ if ( ! is_eu ) return getBaseSchema ( ) ;
162
+ return getBaseSchema ( ) . concat (
156
163
Yup . object ( ) . shape ( {
157
164
tax_identification_number : Yup . string ( )
158
165
. required ( localize ( 'TIN is required.' ) )
0 commit comments