-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate User Pages to React #3506
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c855cbf
Create React version for the EmailSettingsWarning
gabrieldutra 91e3132
Migrate the Create User Page
gabrieldutra 96a8136
Migrate UserProfile to React
gabrieldutra 3dfc5a8
Add /users/me to the routes (Percy ftw)
gabrieldutra af90f05
Fix UserShow test spec
gabrieldutra e7db5ca
Remove Error Messages component
gabrieldutra e9603f5
Show invitation link if email server not setup (#3519)
54098ea
Merge remote-tracking branch 'master' into react-users
gabrieldutra 74e794b
Use CreateUserDialog instead of Page
gabrieldutra 1e7e97f
Render invite link on Resend Invitation click
gabrieldutra 8345bcf
Add email validation to DynamicForm
gabrieldutra 13bf8b8
Fix EmailWarning position + update user list with user creation success
gabrieldutra 97868a5
Fix console error on UserProfile
gabrieldutra 3f48a9e
Redirect from /users/new + rename createUser -> showCreateUserDialog
gabrieldutra a5f7979
Use alert instead of toastr for user creation errors
gabrieldutra 93e1d09
Remove logic from CreateUserDialog
gabrieldutra 8d45632
CR
gabrieldutra 4df5d79
Use Promise.reject instead of throw to avoid console error
gabrieldutra 5d33f04
Merge branch 'master' into react-users
kravets-levko a1ff419
Merge branch 'master' into react-users
gabrieldutra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { react2angular } from 'react2angular'; | ||
import { currentUser, clientConfig } from '@/services/auth'; | ||
|
||
export function EmailSettingsWarning({ featureName }) { | ||
return (clientConfig.mailSettingsMissing && currentUser.isAdmin) ? ( | ||
<p className="alert alert-danger"> | ||
{`It looks like your mail server isn't configured. Make sure to configure it for the ${featureName} to work.`} | ||
</p> | ||
) : null; | ||
} | ||
|
||
EmailSettingsWarning.propTypes = { | ||
featureName: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default function init(ngModule) { | ||
ngModule.component('emailSettingsWarning', react2angular(EmailSettingsWarning)); | ||
} | ||
|
||
init.init = true; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Modal from 'antd/lib/modal'; | ||
import Alert from 'antd/lib/alert'; | ||
import { DynamicForm } from '@/components/dynamic-form/DynamicForm'; | ||
import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; | ||
import recordEvent from '@/services/recordEvent'; | ||
|
||
class CreateUserDialog extends React.Component { | ||
static propTypes = { | ||
dialog: DialogPropType.isRequired, | ||
onCreate: PropTypes.func.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { savingUser: false, errorMessage: null }; | ||
this.form = React.createRef(); | ||
} | ||
|
||
componentDidMount() { | ||
recordEvent('view', 'page', 'users/new'); | ||
} | ||
|
||
createUser = () => { | ||
this.form.current.validateFieldsAndScroll((err, values) => { | ||
if (!err) { | ||
this.setState({ savingUser: true }); | ||
this.props.onCreate(values).then(() => { | ||
this.props.dialog.close(); | ||
}).catch((error) => { | ||
this.setState({ savingUser: false, errorMessage: error.message }); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
render() { | ||
const { savingUser, errorMessage } = this.state; | ||
const formFields = [ | ||
{ name: 'name', title: 'Name', type: 'text' }, | ||
{ name: 'email', title: 'Email', type: 'email' }, | ||
].map(field => ({ required: true, props: { onPressEnter: this.createUser }, ...field })); | ||
|
||
return ( | ||
<Modal | ||
{...this.props.dialog.props} | ||
title="Create a New User" | ||
okText="Create" | ||
okButtonProps={{ loading: savingUser }} | ||
onOk={() => this.createUser()} | ||
> | ||
<DynamicForm fields={formFields} ref={this.form} hideSubmitButton /> | ||
{errorMessage && <Alert message={errorMessage} type="error" showIcon />} | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default wrapDialog(CreateUserDialog); |
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 |
---|---|---|
@@ -1,35 +1,30 @@ | ||
import React from 'react'; | ||
import { react2angular } from 'react2angular'; | ||
import { UserProfile } from '../proptypes'; | ||
|
||
export const UserShow = ({ user: { name, email, profileImageUrl } }) => ( | ||
<div className="col-md-4 col-md-offset-4 profile__container"> | ||
<img | ||
alt="profile" | ||
src={profileImageUrl} | ||
className="profile__image" | ||
width="40" | ||
/> | ||
export default function UserShow({ user: { name, email, profileImageUrl } }) { | ||
return ( | ||
<div className="col-md-4 col-md-offset-4 profile__container"> | ||
<img | ||
alt="profile" | ||
src={profileImageUrl} | ||
className="profile__image" | ||
width="40" | ||
/> | ||
|
||
<h3 className="profile__h3">{name}</h3> | ||
<h3 className="profile__h3">{name}</h3> | ||
|
||
<hr /> | ||
<hr /> | ||
|
||
<dl className="profile__dl"> | ||
<dt>Name:</dt> | ||
<dd>{name}</dd> | ||
<dt>Email:</dt> | ||
<dd>{email}</dd> | ||
</dl> | ||
</div> | ||
); | ||
<dl className="profile__dl"> | ||
<dt>Name:</dt> | ||
<dd>{name}</dd> | ||
<dt>Email:</dt> | ||
<dd>{email}</dd> | ||
</dl> | ||
</div> | ||
); | ||
} | ||
|
||
UserShow.propTypes = { | ||
user: UserProfile.isRequired, | ||
}; | ||
|
||
export default function init(ngModule) { | ||
ngModule.component('userShow', react2angular(UserShow)); | ||
} | ||
|
||
init.init = true; |
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,51 @@ | ||
import React from 'react'; | ||
import { react2angular } from 'react2angular'; | ||
|
||
import { EmailSettingsWarning } from '@/components/EmailSettingsWarning'; | ||
import UserEdit from '@/components/users/UserEdit'; | ||
import UserShow from '@/components/users/UserShow'; | ||
import LoadingState from '@/components/items-list/components/LoadingState'; | ||
|
||
import { User } from '@/services/user'; | ||
import settingsMenu from '@/services/settingsMenu'; | ||
import { $route } from '@/services/ng'; | ||
import { currentUser } from '@/services/auth'; | ||
import './settings.less'; | ||
|
||
class UserProfile extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { user: null }; | ||
} | ||
|
||
componentDidMount() { | ||
const userId = $route.current.params.userId || currentUser.id; | ||
User.get({ id: userId }, user => this.setState({ user: User.convertUserInfo(user) })); | ||
} | ||
|
||
render() { | ||
const { user } = this.state; | ||
const canEdit = user && (currentUser.isAdmin || currentUser.id === user.id); | ||
const UserComponent = canEdit ? UserEdit : UserShow; | ||
return ( | ||
<React.Fragment> | ||
<EmailSettingsWarning featureName="invite emails" /> | ||
<div className="row"> | ||
{user ? <UserComponent user={user} /> : <LoadingState className="" />} | ||
</div> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default function init(ngModule) { | ||
settingsMenu.add({ | ||
title: 'Account', | ||
path: 'users/me', | ||
order: 7, | ||
}); | ||
|
||
ngModule.component('pageUserProfile', react2angular(UserProfile)); | ||
} | ||
|
||
init.init = true; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure if I should keep this, but I did in case anyone uses it to track the event.
Lmk in case I should remove it now that this is a Dialog and not a page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay to keep it