Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
admin-localhome
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
localhome
admin-localhome
Commits
6044e2fc
Commit
6044e2fc
authored
Feb 22, 2018
by
chencheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
10. Handle user edit
parent
f12e32bb
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
3 deletions
+121
-3
UserModal.js
src/pages/users/components/UserModal.js
+96
-0
Users.js
src/pages/users/components/Users.js
+13
-3
users.js
src/pages/users/models/users.js
+5
-0
users.js
src/pages/users/services/users.js
+7
-0
No files found.
src/pages/users/components/UserModal.js
0 → 100644
View file @
6044e2fc
import
{
Component
}
from
'react'
;
import
{
Modal
,
Form
,
Input
}
from
'antd'
;
const
FormItem
=
Form
.
Item
;
class
UserEditModal
extends
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
visible
:
false
,
};
}
showModelHandler
=
(
e
)
=>
{
if
(
e
)
e
.
stopPropagation
();
this
.
setState
({
visible
:
true
,
});
};
hideModelHandler
=
()
=>
{
this
.
setState
({
visible
:
false
,
});
};
okHandler
=
()
=>
{
const
{
onOk
}
=
this
.
props
;
this
.
props
.
form
.
validateFields
((
err
,
values
)
=>
{
if
(
!
err
)
{
onOk
(
values
);
this
.
hideModelHandler
();
}
});
};
render
()
{
const
{
children
}
=
this
.
props
;
const
{
getFieldDecorator
}
=
this
.
props
.
form
;
const
{
name
,
email
,
website
}
=
this
.
props
.
record
;
const
formItemLayout
=
{
labelCol
:
{
span
:
6
},
wrapperCol
:
{
span
:
14
},
};
return
(
<
span
>
<
span
onClick
=
{
this
.
showModelHandler
}
>
{
children
}
<
/span
>
<
Modal
title
=
"Edit User"
visible
=
{
this
.
state
.
visible
}
onOk
=
{
this
.
okHandler
}
onCancel
=
{
this
.
hideModelHandler
}
>
<
Form
horizontal
onSubmit
=
{
this
.
okHandler
}
>
<
FormItem
{...
formItemLayout
}
label
=
"Name"
>
{
getFieldDecorator
(
'name'
,
{
initialValue
:
name
,
})(
<
Input
/>
)
}
<
/FormItem
>
<
FormItem
{...
formItemLayout
}
label
=
"Email"
>
{
getFieldDecorator
(
'email'
,
{
initialValue
:
email
,
})(
<
Input
/>
)
}
<
/FormItem
>
<
FormItem
{...
formItemLayout
}
label
=
"Website"
>
{
getFieldDecorator
(
'website'
,
{
initialValue
:
website
,
})(
<
Input
/>
)
}
<
/FormItem
>
<
/Form
>
<
/Modal
>
<
/span
>
);
}
}
export
default
Form
.
create
()(
UserEditModal
);
src/pages/users/components/Users.js
View file @
6044e2fc
...
...
@@ -3,6 +3,7 @@ import { Table, Pagination, Popconfirm } from 'antd';
import
{
routerRedux
}
from
'dva/router'
;
import
styles
from
'./Users.css'
;
import
{
PAGE_SIZE
}
from
'../constants'
;
import
UserModal
from
'./UserModal'
;
function
Users
({
dispatch
,
list
:
dataSource
,
loading
,
total
,
page
:
current
})
{
function
deleteHandler
(
id
)
{
...
...
@@ -19,6 +20,13 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
}));
}
function
editHandler
(
id
,
values
)
{
dispatch
({
type
:
'users/patch'
,
payload
:
{
id
,
values
},
});
}
const
columns
=
[
{
title
:
'Name'
,
...
...
@@ -39,10 +47,12 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
{
title
:
'Operation'
,
key
:
'operation'
,
render
:
(
text
,
{
id
}
)
=>
(
render
:
(
text
,
record
)
=>
(
<
span
className
=
{
styles
.
operation
}
>
<
a
href
=
""
>
Edit
<
/a
>
<
Popconfirm
title
=
"Confirm to delete?"
onConfirm
=
{
deleteHandler
.
bind
(
null
,
id
)}
>
<
UserModal
record
=
{
record
}
onOk
=
{
editHandler
.
bind
(
null
,
record
.
id
)}
>
<
a
>
Edit
<
/a
>
<
/UserModal
>
<
Popconfirm
title
=
"Confirm to delete?"
onConfirm
=
{
deleteHandler
.
bind
(
null
,
record
.
id
)}
>
<
a
href
=
""
>
Delete
<
/a
>
<
/Popconfirm
>
<
/span
>
...
...
src/pages/users/models/users.js
View file @
6044e2fc
...
...
@@ -29,6 +29,11 @@ export default {
const
page
=
yield
select
(
state
=>
state
.
users
.
page
);
yield
put
({
type
:
'fetch'
,
payload
:
{
page
}
});
},
*
patch
({
payload
:
{
id
,
values
}
},
{
call
,
put
,
select
})
{
yield
call
(
usersService
.
patch
,
id
,
values
);
const
page
=
yield
select
(
state
=>
state
.
users
.
page
);
yield
put
({
type
:
'fetch'
,
payload
:
{
page
}
});
},
},
subscriptions
:
{
setup
({
dispatch
,
history
})
{
...
...
src/pages/users/services/users.js
View file @
6044e2fc
...
...
@@ -10,3 +10,10 @@ export function remove(id) {
method
:
'DELETE'
,
});
}
export
function
patch
(
id
,
values
)
{
return
request
(
`/api/users/
${
id
}
`
,
{
method
:
'PATCH'
,
body
:
JSON
.
stringify
(
values
),
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment