1
1
import React , { useEffect } from 'react' ;
2
+ import { useHistory } from 'react-router-dom' ;
2
3
import styled from 'styled-components' ;
3
- import { LoadingOutlined } from '@ant-design/icons' ;
4
- import { Form , Row , Steps } from 'antd' ;
5
4
import dayjs from 'dayjs' ;
5
+ import { CheckCircleOutlined , LoadingOutlined } from '@ant-design/icons' ;
6
+ import { Form , Row , Steps } from 'antd' ;
6
7
import utc from 'dayjs/plugin/utc' ;
7
8
import translationQualityTiers from '~/assets/fixtures/translationQualityTiers.json' ;
8
9
import { normalizeBaseUnit } from '~/features/tokens' ;
@@ -21,10 +22,12 @@ import { useLinguoApi } from '~/hooks/useLinguo';
21
22
import { getAddressByLanguageAndChain } from '~/utils/getAddressByLanguage' ;
22
23
import { publishMetaEvidence } from '~/utils/task/publishMetaEvidence' ;
23
24
import moment from 'moment' ;
25
+ import * as r from '~/app/routes' ;
24
26
25
27
dayjs . extend ( utc ) ;
26
28
27
29
function TranslationRequestForm ( ) {
30
+ const history = useHistory ( ) ;
28
31
const { account, chainId } = useWeb3 ( ) ;
29
32
const { createTask, setAddress } = useLinguoApi ( ) ;
30
33
const [ form ] = Form . useForm ( ) ;
@@ -59,11 +62,14 @@ function TranslationRequestForm() {
59
62
try {
60
63
const metaEvidence = await publishMetaEvidence ( chainId , metadata ) ;
61
64
await createTask ( moment ( formattedDeadline ) . unix ( ) , metadata . minPrice , metaEvidence , metadata . maxPrice ) ;
62
- } finally {
65
+ send ( 'SUCCESS' ) ;
66
+ setTimeout ( ( ) => history . push ( r . REQUESTER_DASHBOARD ) , 3000 ) ;
67
+ } catch ( error ) {
68
+ console . log ( { error } ) ;
63
69
send ( 'RESET' ) ;
64
70
}
65
71
} ,
66
- [ send , account , chainId , createTask ]
72
+ [ send , account , chainId , createTask , history ]
67
73
) ;
68
74
69
75
const handleFinishFailed = React . useCallback (
@@ -181,6 +187,12 @@ function TranslationRequestForm() {
181
187
disabled : true ,
182
188
children : 'Request the Translation' ,
183
189
}
190
+ : state === 'success'
191
+ ? {
192
+ icon : < CheckCircleOutlined /> ,
193
+ disabled : true ,
194
+ children : 'Request Submitted' ,
195
+ }
184
196
: {
185
197
children : 'Request the Translation' ,
186
198
} ) }
@@ -227,6 +239,7 @@ const formStateMachine = {
227
239
submitting : {
228
240
on : {
229
241
RESET : 'idle' ,
242
+ SUCCESS : 'success' ,
230
243
} ,
231
244
} ,
232
245
} ,
0 commit comments