1
1
import entries from 'lodash/entries' ;
2
2
import Error from 'next/error' ;
3
- import Image from 'next/image' ;
4
3
import Link from 'next/link' ;
5
4
import { useRouter } from 'next/router' ;
6
5
import { useState } from 'react' ;
7
- import { useIMask } from 'react-imask' ;
8
6
9
7
import { AppLayout } from 'components/app-layout' ;
10
8
import { FormField } from 'components/form-field' ;
@@ -15,6 +13,7 @@ import { Button } from 'components/ui/button2';
15
13
import { FileInput } from 'components/ui/file-input' ;
16
14
import Form from 'components/ui/form' ;
17
15
import { Icon } from 'components/ui/icon' ;
16
+ import { PhoneNumberInput } from 'components/ui/phone-number-input' ;
18
17
import TextInput from 'components/ui/text-input' ;
19
18
import { usePersistentData } from 'providers/persistent-data-provider' ;
20
19
import { postParticipation } from 'services/api/participation' ;
@@ -45,31 +44,6 @@ const initialFormValues: ParticipationFormFields = {
45
44
file : null ,
46
45
} ;
47
46
48
- const phoneMaskOptions = {
49
- mask : [
50
- {
51
- mask : '+0 000 000-00-00' ,
52
- startsWith : '7' ,
53
- } ,
54
- {
55
- mask : '+0DD' ,
56
- blocks : {
57
- DD : {
58
- mask : / ^ [ \d - ( ) ] { 0 , 15 } $ /
59
- } ,
60
- } ,
61
- startsWith : '' ,
62
- } ,
63
- ] ,
64
- dispatch : function ( appended : string , dynamicMasked : { value : string ; compiledMasks : { startsWith : string } [ ] } ) {
65
- const number = ( dynamicMasked . value + appended ) . replace ( / \D / g, '' ) ;
66
-
67
- return dynamicMasked . compiledMasks . find ( function ( m ) {
68
- return number . indexOf ( m . startsWith ) === 0 ;
69
- } ) ;
70
- }
71
- } ;
72
-
73
47
const validate = ( values : ParticipationFormFields ) => {
74
48
const errors = { } as Record < keyof ParticipationFormFields , string > ;
75
49
@@ -94,7 +68,7 @@ const validate = (values: ParticipationFormFields) => {
94
68
} else if ( ! validYearRegexp . test ( values . birthYear ) ) {
95
69
errors . birthYear = 'Убедитесь, что это значение больше либо равно 1900' ;
96
70
} else if ( values . birthYear > CURRENT_YEAR ) {
97
- errors . birthYear = `Убедитесь, что это значение больше либо равно ${ CURRENT_YEAR } ` ;
71
+ errors . birthYear = `Убедитесь, что это значение меньше либо равно ${ CURRENT_YEAR } ` ;
98
72
}
99
73
100
74
if ( ! values . city . length ) {
@@ -128,7 +102,7 @@ const validate = (values: ParticipationFormFields) => {
128
102
} else if ( ! validYearRegexp . test ( values . year ) ) {
129
103
errors . year = 'Убедитесь, что это значение больше либо равно 1900' ;
130
104
} else if ( values . year > CURRENT_YEAR ) {
131
- errors . year = `Убедитесь, что это значение больше либо равно ${ CURRENT_YEAR } ` ;
105
+ errors . year = `Убедитесь, что это значение меньше либо равно ${ CURRENT_YEAR } ` ;
132
106
}
133
107
134
108
if ( ! values . file ) {
@@ -146,15 +120,6 @@ const Participation = () => {
146
120
} ) ;
147
121
const { settings } = usePersistentData ( ) ;
148
122
149
- const { ref : phoneNumberInputRef } = useIMask < typeof phoneMaskOptions > ( phoneMaskOptions , {
150
- onAccept : ( value ) => {
151
- if ( form . values . phoneNumber === value ) {
152
- return ;
153
- }
154
- form . setFieldValue ( 'phoneNumber' , value ) ;
155
- } ,
156
- } ) ;
157
-
158
123
const router = useRouter ( ) ;
159
124
160
125
const handleSubmitError = ( error : unknown ) => {
@@ -215,14 +180,6 @@ const Participation = () => {
215
180
title = "Подать пьесу"
216
181
/>
217
182
< PlayProposalLayout >
218
- < PlayProposalLayout . Image >
219
- < Image
220
- src = "/images/form/play-script.jpg"
221
- alt = "Напечатанная читка в руках человека"
222
- layout = "fill"
223
- objectFit = "cover"
224
- />
225
- </ PlayProposalLayout . Image >
226
183
< PlayProposalLayout . Column >
227
184
< PlayProposalTitle />
228
185
< PlayProposalLayout . Form >
@@ -262,6 +219,7 @@ const Participation = () => {
262
219
< TextInput
263
220
value = { form . values . birthYear }
264
221
placeholder = "Год рождения"
222
+ mask = "9999"
265
223
errorText = { form . touched . birthYear ? form . errors . birthYear : '' }
266
224
onChange = { ( value ) => form . setFieldValue ( 'birthYear' , value ) }
267
225
/>
@@ -285,10 +243,8 @@ const Participation = () => {
285
243
caption = "Номер телефона"
286
244
hiddenCaption
287
245
>
288
- < TextInput
289
- inputRef = { phoneNumberInputRef }
290
- type = "tel"
291
- placeholder = "Номер телефона"
246
+ < PhoneNumberInput
247
+ value = { form . values . phoneNumber }
292
248
errorText = { form . touched . phoneNumber ? form . errors . phoneNumber : '' }
293
249
/>
294
250
</ FormField >
@@ -299,6 +255,7 @@ const Participation = () => {
299
255
hiddenCaption
300
256
>
301
257
< TextInput
258
+ type = "email"
302
259
value = { form . values . email }
303
260
placeholder = "E-mail"
304
261
errorText = { form . touched . email ? form . errors . email : '' }
@@ -329,6 +286,7 @@ const Participation = () => {
329
286
< TextInput
330
287
value = { form . values . year }
331
288
placeholder = "Год написания"
289
+ mask = "9999"
332
290
errorText = { form . touched . year ? form . errors . year : '' }
333
291
onChange = { ( value ) => form . setFieldValue ( 'year' , value ) }
334
292
/>
0 commit comments