Created
March 27, 2019 00:29
-
-
Save Wicker25/99d08ab0c852a3780700743b82d4861e to your computer and use it in GitHub Desktop.
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
import autobind from 'autobind-decorator'; | |
import React from 'react'; | |
import { inject, observer } from 'mobx-react'; | |
import CreateUserModalStore from './CreateUserModalStore'; | |
export default class CreateUserModal extends React.Component { | |
constructor(props) { | |
super(props); | |
this.modalStore = new CreateUserModalStore(); | |
} | |
@autobind | |
onUserNameChanged(event) { | |
this.modalStore.setUserName(event.target.value); | |
} | |
// ... | |
@autobind | |
onSubmit(event) { | |
event.preventDefault(); | |
this.props.onSubmit(this.modalStore.user); | |
} | |
render() { | |
const { isOpen, isLoading, errorMessage, onClose } = this.props; | |
if (isLoading) { | |
return <Spinner />; | |
} | |
return ( | |
<Modal show={isOpen} onClose={onClose}> | |
<Form onSubmit={this.onSubmit}> | |
<Form.Control | |
type="text" | |
placeholder="name" | |
onChange={this.onUserNameChanged} | |
/> | |
{/* ... other inputs ... */} | |
<Button type="submit">Create</Button> | |
</Form> | |
<Alert>{errorMessage}</Alert> | |
</Modal> | |
); | |
} | |
} |
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
import autobind from 'autobind-decorator'; | |
import React from 'react'; | |
import { inject, observer } from 'mobx-react'; | |
import CreateUserModal from './CreateUserModal'; | |
@inject('appStore') | |
@observer | |
export default class UserManagementPage extends React.Component { | |
@autobind | |
onCreateUserModalSubmitted(user) { | |
this.props.appStore.createUser(user); | |
} | |
@autobind | |
onCreateUserModalClosed() { | |
this.props.appStore.closeCreateUserModal(); | |
} | |
render() { | |
const { appStore } = this.props; | |
return ( | |
<div id="user-management-page"> | |
<Button onClick={appStore.openCreateUserModal}>Create User</Button> | |
<CreateUserModal | |
isOpen={appStore.isCreateUserModalOpen} | |
isLoading={appStore.isCreateUserModalLoading} | |
errorMessage={appStore.createUserModalErrorMessage} | |
onSubmit={this.onCreateUserModalSubmitted} | |
onClose={this.onCreateUserModalClosed} | |
/> | |
{/* ... */} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment