-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from linkernetworks/phstsai/profile
[Task] User profile page, and password changing function
- Loading branch information
Showing
13 changed files
with
323 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { compose } from 'recompose'; | ||
import { Form, Modal, Input } from 'antd'; | ||
import { FormComponentProps } from 'antd/lib/form'; | ||
|
||
const FormItem = Form.Item; | ||
|
||
const formItemLayout = { | ||
labelCol: { span: 8 }, | ||
wrapperCol: { span: 14 } | ||
}; | ||
|
||
type PasswordFormProps = OwnProps & FormComponentProps; | ||
|
||
interface OwnProps { | ||
visible: boolean; | ||
username: string; | ||
onCancel: () => void; | ||
onSubmit: (data: any) => void; | ||
} | ||
|
||
class PasswordForm extends React.PureComponent<PasswordFormProps, object> { | ||
protected handleSubmit = () => { | ||
this.props.form.validateFields((err, values) => { | ||
if (!err) { | ||
this.props.onSubmit({ | ||
username: this.props.username, | ||
password: values.password | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
protected handleClose = () => { | ||
this.props.form.resetFields(); | ||
this.props.onCancel(); | ||
}; | ||
|
||
public compareToFirstPassword = (_: any, value: string, callback: any) => { | ||
const form = this.props.form; | ||
if (value && value !== form.getFieldValue('password')) { | ||
callback('Two passwords that you enter is inconsistent!'); | ||
} else { | ||
callback(); | ||
} | ||
}; | ||
|
||
public render() { | ||
const { getFieldDecorator } = this.props.form; | ||
|
||
return ( | ||
<Modal | ||
visible={this.props.visible} | ||
title={<FormattedMessage id="user.changePassword" />} | ||
onOk={this.handleSubmit} | ||
onCancel={this.handleClose} | ||
> | ||
<Form> | ||
<FormItem {...formItemLayout} label="Password"> | ||
{getFieldDecorator('password', { | ||
rules: [ | ||
{ | ||
required: true, | ||
message: 'Please input your password!' | ||
} | ||
] | ||
})(<Input type="password" />)} | ||
</FormItem> | ||
<FormItem {...formItemLayout} label="Confirm Password"> | ||
{getFieldDecorator('confirm', { | ||
rules: [ | ||
{ | ||
required: true, | ||
message: 'Please confirm your password!' | ||
}, | ||
{ | ||
validator: this.compareToFirstPassword | ||
} | ||
] | ||
})(<Input type="password" />)} | ||
</FormItem> | ||
</Form> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default compose<PasswordFormProps, OwnProps>(Form.create())( | ||
PasswordForm | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import * as React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Card, Table, Icon, Avatar } from 'antd'; | ||
import { InjectedIntlProps } from 'react-intl'; | ||
import { ColumnProps } from 'antd/lib/table'; | ||
import { Dispatch } from 'redux'; | ||
import { InjectedAuthRouterProps } from 'redux-auth-wrapper/history4/redirect'; | ||
import { userOperations } from '@/store/ducks/user'; | ||
import * as styles from './styles.module.scss'; | ||
import PasswordForm from '@/components/PasswordForm'; | ||
import user from '@/assets/user.svg'; | ||
|
||
import { RootState, RootAction, RTDispatch } from '@/store/ducks'; | ||
import { FlattenUser, User } from '@/models/User'; | ||
import { userModels } from '@/store/ducks/user'; | ||
|
||
type UsersProps = OwnProps & InjectedAuthRouterProps & InjectedIntlProps; | ||
|
||
interface OwnProps extends ColumnProps<FlattenUser> { | ||
user: User; | ||
changePassword: (data: userModels.LoginCredential) => any; | ||
} | ||
|
||
interface UserState { | ||
visibleModal: boolean; | ||
} | ||
|
||
class Profile extends React.PureComponent<UsersProps, UserState> { | ||
constructor(props: UsersProps) { | ||
super(props); | ||
this.state = { | ||
visibleModal: false | ||
}; | ||
} | ||
|
||
private columns = [ | ||
{ | ||
dataIndex: 'key' | ||
}, | ||
{ | ||
dataIndex: 'value' | ||
} | ||
]; | ||
private data = [ | ||
{ | ||
key: 'User Name', | ||
value: this.props.user.loginCredential.username | ||
}, | ||
{ | ||
key: 'Role', | ||
value: this.props.user.role | ||
}, | ||
{ | ||
key: 'First Name', | ||
value: this.props.user.firstName | ||
}, | ||
{ | ||
key: 'Last Name', | ||
value: this.props.user.lastName | ||
}, | ||
{ | ||
key: 'Phone Number', | ||
value: this.props.user.phoneNumber | ||
} | ||
]; | ||
|
||
protected showCreate = () => { | ||
this.setState({ visibleModal: true }); | ||
}; | ||
|
||
protected hideCreate = () => { | ||
this.setState({ visibleModal: false }); | ||
}; | ||
|
||
protected handleSubmit = (data: userModels.LoginCredential) => { | ||
this.props.changePassword(data); | ||
this.setState({ visibleModal: false }); | ||
}; | ||
|
||
public render() { | ||
const { Meta } = Card; | ||
|
||
return ( | ||
<div className={styles.test}> | ||
<Card | ||
style={{ width: 500 }} | ||
actions={[<Icon key="edit" type="edit" onClick={this.showCreate} />]} | ||
> | ||
<Meta | ||
avatar={<Avatar src={user} />} | ||
title={this.props.user.displayName} | ||
description={ | ||
<Table | ||
rowKey="name" | ||
columns={this.columns} | ||
dataSource={this.data} | ||
pagination={false} | ||
showHeader={false} | ||
/> | ||
} | ||
/> | ||
</Card> | ||
<PasswordForm | ||
username={this.props.user.loginCredential.username} | ||
visible={this.state.visibleModal} | ||
onCancel={this.hideCreate} | ||
onSubmit={this.handleSubmit} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state: RootState) => { | ||
return { | ||
user: state.user.auth.user as User | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch: RTDispatch & Dispatch<RootAction>) => ({ | ||
changePassword: (data: userModels.LoginCredential) => { | ||
dispatch(userOperations.changePassword(data)); | ||
} | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(Profile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.test{ | ||
transform: translateY(-50%); | ||
top: 35%; | ||
position: relative; | ||
display: flex; | ||
justify-content: center | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.