Skip to content

Commit 6559d03

Browse files
AbigailDengAbigailDeng
authored andcommitted
feat: switchVote
1 parent 86c4258 commit 6559d03

File tree

2 files changed

+112
-13
lines changed

2 files changed

+112
-13
lines changed

src/pages/Vote/Vote.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,15 @@ class VoteContainer extends Component {
567567
.unix(voteTimestamp.seconds)
568568
.format("YYYY-MM-DD HH:mm:ss");
569569
});
570+
571+
const switchVoteSelectedRowKeys = switchableVoteRecords.map(
572+
(ele) => ele.key
573+
);
570574
this.setState({
571575
expiredVotesAmount,
572576
activeVotingRecords,
573577
switchableVoteRecords,
578+
switchVoteSelectedRowKeys,
574579
withdrawnableVoteRecords: withdrawableVoteRecords,
575580
});
576581
}
@@ -605,8 +610,10 @@ class VoteContainer extends Component {
605610
}
606611

607612
handleClick(e) {
608-
const ele = JSON.stringify(e.target.dataset) !== '{}'
609-
? e.target : e.target.parentNode;
613+
const ele =
614+
JSON.stringify(e.target.dataset) !== "{}"
615+
? e.target
616+
: e.target.parentNode;
610617
const {
611618
role = "default",
612619
shoulddetectlock: shouldDetectLock,
@@ -1082,8 +1089,8 @@ class VoteContainer extends Component {
10821089
let { value = {} } = result || {};
10831090
value = !value
10841091
? {
1085-
ELF: 0,
1086-
}
1092+
ELF: 0,
1093+
}
10871094
: value;
10881095
value = Object.keys(value).reduce((acc, key) => {
10891096
return {

src/pages/Vote/VoteModal/index.js

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import React, { Component } from "react";
22
import { Link } from "react-router-dom";
3-
import { Tabs, Modal, Form, Input, DatePicker, Button, Tooltip } from "antd";
3+
import {
4+
Table,
5+
Tabs,
6+
Modal,
7+
Form,
8+
Input,
9+
DatePicker,
10+
Button,
11+
Tooltip,
12+
} from "antd";
413
import { SearchOutlined, InfoCircleFilled } from "@ant-design/icons";
514
import DatePickerReact from "react-datepicker";
615
import moment from "moment";
@@ -64,7 +73,7 @@ const validateMessages = {
6473
const formItemsNeedToValidateMap = {
6574
fromWallet: ["lockTime", "voteAmountInput"],
6675
fromExpiredVotes: [],
67-
fromActiveVotes: ["switchVoteRowSelection"],
76+
fromActiveVotes: ["lockTime", "switchVoteRowSelection"],
6877
};
6978

7079
function disabledDate(current) {
@@ -168,7 +177,7 @@ class VoteModal extends Component {
168177
withdrawnableVoteRecords,
169178
estimatedProfit,
170179
switchVoteSelectedRowKeys,
171-
handleSwithVoteSelectedRowChange,
180+
handleSwitchVoteSelectedRowChange,
172181
voteFromExpiredVoteAmount,
173182
voteFromExpiredSelectedRowKeys,
174183
handleVoteFromExpiredSelectedRowChange,
@@ -185,16 +194,23 @@ class VoteModal extends Component {
185194
hideDefaultSelections: true,
186195
type: "checkbox",
187196
};
188-
189197
const switchVoteRowSelection = {
190-
selectedRowKeys: switchVoteSelectedRowKeys,
198+
selectedRowKeys: [
199+
switchVoteSelectedRowKeys.length > 0
200+
? switchVoteSelectedRowKeys[0]
201+
: "",
202+
],
191203
onChange: (...params) => {
192-
handleSwithVoteSelectedRowChange(...params);
204+
handleSwitchVoteSelectedRowChange(...params);
193205
this.setState({
194206
formattedLockTime: params[1][0].formatedLockTime,
195207
});
208+
// set `Select Vote` value manully, cannot set it automatically
209+
// as formItem's child is not radio but table
210+
this.formRef.current.setFieldsValue({
211+
switchVoteRowSelection: params[0],
212+
});
196213
},
197-
hideDefaultSelections: true,
198214
type: "radio",
199215
};
200216

@@ -296,7 +312,6 @@ class VoteModal extends Component {
296312
showYearDropdown
297313
selected={datePickerTime}
298314
onChange={(date) => {
299-
console.log("setFieldsValue", date);
300315
this.setState({
301316
datePickerTime: date,
302317
});
@@ -338,6 +353,81 @@ class VoteModal extends Component {
338353
},
339354
],
340355
},
356+
{
357+
type: FROM_ACTIVE_VOTES,
358+
label: "From Not Expired Votes",
359+
index: 2,
360+
formItems: [
361+
{
362+
label: "Node Name",
363+
render: <span className='form-item-value'>{nodeName}</span>,
364+
},
365+
{
366+
label: "Node Address",
367+
render: <span className='form-item-value'>{nodeAddress}</span>,
368+
},
369+
{
370+
label: "Select Vote",
371+
render: (
372+
<Form.Item
373+
name='switchVoteRowSelection'
374+
initialValue={[
375+
switchVoteSelectedRowKeys.length > 0
376+
? switchVoteSelectedRowKeys[0]
377+
: "",
378+
]}
379+
rules={[
380+
{
381+
required: true,
382+
message: SELECT_SOMETHING_TIP,
383+
},
384+
]}
385+
>
386+
<Table
387+
size='middle'
388+
dataSource={switchableVoteRecords}
389+
columns={columns}
390+
rowSelection={switchVoteRowSelection}
391+
pagination={switchVotePagination}
392+
scroll={{ x: 798 }}
393+
/>
394+
</Form.Item>
395+
),
396+
},
397+
{
398+
label: "Lock Time",
399+
render: (
400+
<Form.Item
401+
name='lockTime'
402+
validateTrigger={["onChange", "onBlur"]}
403+
rules={[
404+
// todo: add the validator rule
405+
{
406+
required: true,
407+
message: "Please select your lock time!",
408+
},
409+
]}
410+
>
411+
<div>
412+
<DatePicker
413+
disabledDate={disabledDate}
414+
onChange={(value) => {
415+
handleLockTimeChange(value);
416+
this.formRef.current.setFieldsValue({
417+
lockTime: value,
418+
});
419+
}}
420+
/>
421+
<span className='tip-color' style={{ marginLeft: 10 }}>
422+
Withdrawal and transfer are not supported during the lock-up
423+
period
424+
</span>
425+
</div>
426+
</Form.Item>
427+
),
428+
},
429+
],
430+
},
341431
];
342432
}
343433

@@ -536,7 +626,9 @@ class VoteModal extends Component {
536626

537627
<Form.Item
538628
required={
539-
item.label === "Vote Amount" || item.label === "Lock Time"
629+
item.label === "Vote Amount" ||
630+
item.label === "Lock Time" ||
631+
item.label === "Select Vote"
540632
}
541633
label={item.label}
542634
key={item.label}

0 commit comments

Comments
 (0)