Skip to content

Commit bce6d3f

Browse files
committed
fix: extend button state & add redirect on request submission
1 parent 7adaa4c commit bce6d3f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/pages/TranslationRequest/TranslationRequestForm.jsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useEffect } from 'react';
2+
import { useHistory } from 'react-router-dom';
23
import styled from 'styled-components';
3-
import { LoadingOutlined } from '@ant-design/icons';
4-
import { Form, Row, Steps } from 'antd';
54
import dayjs from 'dayjs';
5+
import { CheckCircleOutlined, LoadingOutlined } from '@ant-design/icons';
6+
import { Form, Row, Steps } from 'antd';
67
import utc from 'dayjs/plugin/utc';
78
import translationQualityTiers from '~/assets/fixtures/translationQualityTiers.json';
89
import { normalizeBaseUnit } from '~/features/tokens';
@@ -21,10 +22,12 @@ import { useLinguoApi } from '~/hooks/useLinguo';
2122
import { getAddressByLanguageAndChain } from '~/utils/getAddressByLanguage';
2223
import { publishMetaEvidence } from '~/utils/task/publishMetaEvidence';
2324
import moment from 'moment';
25+
import * as r from '~/app/routes';
2426

2527
dayjs.extend(utc);
2628

2729
function TranslationRequestForm() {
30+
const history = useHistory();
2831
const { account, chainId } = useWeb3();
2932
const { createTask, setAddress } = useLinguoApi();
3033
const [form] = Form.useForm();
@@ -59,11 +62,14 @@ function TranslationRequestForm() {
5962
try {
6063
const metaEvidence = await publishMetaEvidence(chainId, metadata);
6164
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 });
6369
send('RESET');
6470
}
6571
},
66-
[send, account, chainId, createTask]
72+
[send, account, chainId, createTask, history]
6773
);
6874

6975
const handleFinishFailed = React.useCallback(
@@ -181,6 +187,12 @@ function TranslationRequestForm() {
181187
disabled: true,
182188
children: 'Request the Translation',
183189
}
190+
: state === 'success'
191+
? {
192+
icon: <CheckCircleOutlined />,
193+
disabled: true,
194+
children: 'Request Submitted',
195+
}
184196
: {
185197
children: 'Request the Translation',
186198
})}
@@ -227,6 +239,7 @@ const formStateMachine = {
227239
submitting: {
228240
on: {
229241
RESET: 'idle',
242+
SUCCESS: 'success',
230243
},
231244
},
232245
},

0 commit comments

Comments
 (0)