import React from 'react' import { connect } from 'react-redux' import { Link } from 'react-router-dom' import { Icon, Col, Row, Input, Form, Tooltip, Breadcrumb } from 'antd' const FormItem = Form.Item const styles = require('./profile.less') import Box from 'components/Box' import Avatar from 'components/Avatar' import { createStructuredSelector } from 'reselect' import { makeSelectLoading, makeSelectUserProfile } from './selectors' import { compose } from 'redux' import injectReducer from 'utils/injectReducer' import { getUserProfile } from './actions' import injectSaga from 'utils/injectSaga' import reducer from './reducer' import saga from './sagas' import { RouteComponentWithParams } from 'utils/types' const utilStyles = require('assets/less/util.less') interface IProfileProps { form: any loading: boolean userProfile: any onGetUserProfile: (id: number) => any } export class UserProfile extends React.PureComponent { public componentDidMount () { const { match, onGetUserProfile } = this.props const userId = +match.params.userId onGetUserProfile(userId) } public componentWillReceiveProps (nextProps) { if (nextProps && nextProps.userProfile !== this.props.userProfile) { const { name, description, department } = nextProps.userProfile this.props.form.setFieldsValue({name, description, department}) } } public render () { const { userProfile } = this.props const commonFormItemStyle = { labelCol: { span: 20 }, wrapperCol: { span: 20 } } let organizations = void 0 if (userProfile) { organizations = userProfile.organizations.map((org, index) => (
) ) } const name = userProfile.name ? userProfile.name : '他' const { getFieldDecorator } = this.props.form return ( {`${name}的信息`}
{getFieldDecorator('name', {})( )} {getFieldDecorator('description', {})( )} {getFieldDecorator('department', {})( )} {getFieldDecorator('org', {})(
{organizations}
)}
) } } export function mapDispatchToProps (dispatch) { return { onGetUserProfile: (id) => dispatch(getUserProfile(id)) } } const mapStateToProps = createStructuredSelector({ loading: makeSelectLoading(), userProfile: makeSelectUserProfile() }) const withConnect = connect(mapStateToProps, mapDispatchToProps) const withReducerProfile = injectReducer({key: 'profile', reducer}) const withSagaProfile = injectSaga({key: 'profile', saga}) export default compose( withReducerProfile, withSagaProfile, withConnect )(Form.create()(UserProfile))