Skip to content

Commit f4c15ec

Browse files
committed
feat(alias): add update alias function to project cards
1 parent 6ad54c8 commit f4c15ec

5 files changed

Lines changed: 133 additions & 35 deletions

File tree

src/pages/dashboard/components/Projects.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ import _get from 'lodash/get'
55
import moment from 'moment'
66
import makeBlockie from 'ethereum-blockies-base64'
77
import PropTypes from 'prop-types'
8-
import { Card, Button, Modal, Col, Tag, Avatar, InputNumber } from 'antd'
8+
import {
9+
Card,
10+
Button,
11+
Modal,
12+
Col,
13+
Tag,
14+
Avatar,
15+
Input,
16+
InputNumber,
17+
Icon,
18+
} from 'antd'
919
import { addLangPrefix, toPTC, fromPTC } from 'utils'
1020
import { Trans, withI18n } from '@lingui/react'
21+
import UpdateAliasModal from './UpdateAliasModal'
1122
import styles from './Projects.less'
1223

1324
@withI18n()
1425
@connect(({ loading, dashboard, app }) => ({ loading, dashboard, app }))
1526
class Projects extends PureComponent {
1627
state = {
1728
amount: 0.1,
29+
alias: '',
30+
updateAlias: false,
1831
}
1932
confirmAmount = db => {
2033
const { i18n } = this.props
@@ -50,6 +63,17 @@ class Projects extends PureComponent {
5063
},
5164
})
5265
}
66+
confirmEditAlias = (project, e) => {
67+
e.preventDefault()
68+
e.stopPropagation()
69+
70+
this.setState({
71+
alias: project.alias,
72+
db: project.project,
73+
updateAlias: true,
74+
})
75+
}
76+
closeUpdateAliasModal = () => this.setState({ alias: '', updateAlias: false })
5377
topup = async db => {
5478
const { dispatch, i18n } = this.props
5579
const { amount } = this.state
@@ -118,6 +142,13 @@ class Projects extends PureComponent {
118142
/>
119143
)}
120144
<div className={styles.alias}>{p.alias}</div>
145+
<Button
146+
onClick={e => this.confirmEditAlias(p, e)}
147+
className={styles.editBtn}
148+
size="small"
149+
>
150+
<Icon type="edit" theme="twoTone" />
151+
</Button>
121152
</div>
122153
</Link>
123154
</div>
@@ -136,6 +167,13 @@ class Projects extends PureComponent {
136167
{this._renderProjectCard(p)}
137168
</Col>
138169
))}
170+
{this.state.updateAlias && (
171+
<UpdateAliasModal
172+
db={this.state.db}
173+
alias={this.state.alias}
174+
close={this.closeUpdateAliasModal}
175+
/>
176+
)}
139177
</>
140178
)
141179
}

src/pages/dashboard/components/Projects.less

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
}
3535
}
3636
.name {
37-
padding: 20px 10px 10px;
37+
margin-top: 10px;
38+
padding: 10px;
3839
display: flex;
3940
align-content: center;
41+
position: relative;
4042

4143
.avatar {
4244
border: solid 2px #fcfcfc;
@@ -46,9 +48,16 @@
4648
margin-left: 15px;
4749
font-size: 1rem;
4850
font-weight: 600;
49-
padding: 12px 0;
51+
padding: 12px 20px 12px 0;
5052
text-overflow: ellipsis;
5153
overflow: hidden;
5254
}
55+
.editBtn {
56+
height: 16px;
57+
font-size: 10px;
58+
position: absolute;
59+
right: 0;
60+
top: calc(50% - 8px);
61+
}
5362
}
5463
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React, { PureComponent } from 'react'
2+
import { connect } from 'dva'
3+
import moment from 'moment'
4+
import PropTypes from 'prop-types'
5+
import { Form, Input, Button, Modal, Icon, message } from 'antd'
6+
import { Trans, withI18n } from '@lingui/react'
7+
8+
@withI18n()
9+
@Form.create()
10+
@connect(({ loading, dashboard }) => ({ loading, dashboard }))
11+
class UpdateAliasModal extends PureComponent {
12+
submitAlias = () => {
13+
const { db, alias, dispatch, form, close } = this.props
14+
15+
form.validateFields(async (err, values) => {
16+
if (err) {
17+
return
18+
}
19+
console.log('Received values of form: ', values)
20+
21+
const { alias } = values
22+
const { data, success } = await dispatch({
23+
type: 'dashboard/updateProjectMisc',
24+
payload: { db, alias },
25+
})
26+
27+
if (success) {
28+
dispatch({ type: 'app/getProjectList' })
29+
message.success('Update project alias success')
30+
close()
31+
}
32+
})
33+
}
34+
render() {
35+
const { close, form } = this.props
36+
const { getFieldDecorator } = form
37+
38+
return (
39+
<Modal
40+
visible={true}
41+
title={'请输入希望修改的别名:'}
42+
onCancel={close}
43+
footer={[
44+
<Button type="primary" onClick={this.submitAlias}>
45+
<Trans>OK</Trans>
46+
</Button>,
47+
]}
48+
>
49+
<Form>
50+
<Form.Item label="alias">
51+
{getFieldDecorator('alias', {
52+
rules: [
53+
{
54+
required: true,
55+
message: 'Please input the new alias',
56+
},
57+
{
58+
max: 16,
59+
message: 'Max length of alias is 16 characters',
60+
},
61+
],
62+
initialValue: this.props.alias,
63+
})(<Input placeholder="Please input the new alias" />)}
64+
</Form.Item>
65+
</Form>
66+
</Modal>
67+
)
68+
}
69+
}
70+
71+
UpdateAliasModal.propTypes = {
72+
alias: PropTypes.string.isRequired,
73+
close: PropTypes.func,
74+
}
75+
UpdateAliasModal.defaultProps = {}
76+
export default UpdateAliasModal

src/pages/dashboard/components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import TaskList from './taskList'
33
import CreateProject from './createProject'
44
import Projects from './Projects'
55
import User from './user'
6+
import UpdateAliasModal from './UpdateAliasModal'
67

7-
export { GetPTC, TaskList, CreateProject, Projects, User }
8+
export { GetPTC, TaskList, CreateProject, Projects, User, UpdateAliasModal }

src/pages/dashboard/model.js

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import { pathMatchRegexp } from 'utils'
55
import { model } from 'utils/model'
66

77
const {
8-
// queryDashboard,
9-
// queryWeather,
108
getPTC,
119
queryTasks,
1210
queryTask,
1311
createProject,
1412
queryProject,
1513
topupProject,
14+
updateProjectMiscConfig,
1615
} = api
1716

1817
export default modelExtend(model, {
@@ -34,41 +33,12 @@ export default modelExtend(model, {
3433

3534
dispatch({ type: 'app/getProjectList' })
3635
// query dashboard related
37-
// dispatch({ type: 'query' })
38-
// dispatch({ type: 'queryWeather' })
3936
dispatch({ type: 'getTaskList', payload: { all: true } })
4037
}
4138
})
4239
},
4340
},
4441
effects: {
45-
// *query({ payload }, { call, put }) {
46-
// const data = yield call(queryDashboard, parse(payload))
47-
// yield put({
48-
// type: 'updateState',
49-
// payload: data,
50-
// })
51-
// },
52-
// *queryWeather({ payload = {} }, { call, put }) {
53-
// payload.location = 'shenzhen'
54-
// const result = yield call(queryWeather, payload)
55-
// const { success } = result
56-
// if (success) {
57-
// const data = result.results[0]
58-
// const weather = {
59-
// city: data.location.name,
60-
// temperature: data.now.temperature,
61-
// name: data.now.text,
62-
// icon: `//s5.sencdn.com/web/icons/3d_50/${data.now.code}.png`,
63-
// }
64-
// yield put({
65-
// type: 'updateState',
66-
// payload: {
67-
// weather,
68-
// },
69-
// })
70-
// }
71-
// },
7242
*getPTC({ payload }, { call, put }) {
7343
const { data, success } = yield call(getPTC)
7444
yield put({ type: 'app/checkMainWallet' })
@@ -101,5 +71,9 @@ export default modelExtend(model, {
10171
const { data, success } = yield call(topupProject, payload)
10272
return { data, success }
10373
},
74+
*updateProjectMisc({ payload }, { call, put }) {
75+
const { data, success } = yield call(updateProjectMiscConfig, payload)
76+
return { data, success }
77+
},
10478
},
10579
})

0 commit comments

Comments
 (0)