2016-04-10 02:58:48 +00:00
|
|
|
import React, {Component, PropTypes} from 'react'
|
|
|
|
import {connect} from 'react-redux'
|
|
|
|
import {bindActionCreators} from 'redux'
|
|
|
|
|
2016-04-23 06:16:23 +00:00
|
|
|
import * as ModalActions from '../redux/modules/modals'
|
|
|
|
import PromptModal from '../components/base/PromptModal'
|
2016-04-10 02:58:48 +00:00
|
|
|
|
2016-04-23 06:16:23 +00:00
|
|
|
import * as db from '../database'
|
2016-04-26 07:29:24 +00:00
|
|
|
import {
|
|
|
|
MODAL_REQUEST_RENAME,
|
|
|
|
MODAL_REQUEST_GROUP_RENAME,
|
|
|
|
MODAL_WORKSPACE_RENAME
|
|
|
|
} from '../lib/constants';
|
2016-04-16 23:24:57 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
class Prompts extends Component {
|
2016-04-10 02:58:48 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this._prompts = {};
|
2016-04-23 06:08:52 +00:00
|
|
|
this._prompts[MODAL_REQUEST_RENAME] = {
|
2016-04-10 02:58:48 +00:00
|
|
|
header: 'Rename Request',
|
|
|
|
submit: 'Rename',
|
|
|
|
onSubmit: (modal, name) => {
|
2016-04-27 03:17:05 +00:00
|
|
|
db.requestUpdate(modal.data.request, {name})
|
2016-04-10 02:58:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-23 06:08:52 +00:00
|
|
|
this._prompts[MODAL_REQUEST_GROUP_RENAME] = {
|
2016-04-10 02:58:48 +00:00
|
|
|
header: 'Rename Request Group',
|
|
|
|
submit: 'Rename',
|
|
|
|
onSubmit: (modal, name) => {
|
2016-04-27 03:17:05 +00:00
|
|
|
db.requestUpdate(modal.data.requestGroup, {name})
|
2016-04-10 02:58:48 +00:00
|
|
|
}
|
|
|
|
};
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
this._prompts[MODAL_WORKSPACE_RENAME] = {
|
|
|
|
header: 'Rename Workspace',
|
|
|
|
submit: 'Rename',
|
|
|
|
onSubmit: (modal, name) => {
|
2016-04-27 03:17:05 +00:00
|
|
|
db.requestUpdate(modal.data.workspace, {name})
|
2016-04-26 07:29:24 +00:00
|
|
|
}
|
|
|
|
};
|
2016-04-10 02:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {modals, actions} = this.props;
|
|
|
|
|
|
|
|
return (
|
2016-04-15 05:23:54 +00:00
|
|
|
<div ref="prompts">
|
|
|
|
{Object.keys(this._prompts).map(id => {
|
|
|
|
const promptDef = this._prompts[id];
|
|
|
|
const modal = modals.find(m => m.id === id);
|
2016-04-10 02:58:48 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
if (!modal) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-10 02:58:48 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
return (
|
|
|
|
<PromptModal
|
|
|
|
key={id}
|
|
|
|
id={id}
|
|
|
|
headerName={promptDef.header}
|
|
|
|
submitName={promptDef.submit}
|
|
|
|
defaultValue={modal.data.defaultValue}
|
2016-04-16 23:24:57 +00:00
|
|
|
onClose={() => actions.modals.hide(modal.id)}
|
2016-04-15 05:23:54 +00:00
|
|
|
onSubmit={value => promptDef.onSubmit(modal, value)}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
2016-04-10 02:58:48 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
Prompts.propTypes = {
|
2016-04-10 02:58:48 +00:00
|
|
|
actions: PropTypes.shape({
|
2016-04-16 23:24:57 +00:00
|
|
|
modals: PropTypes.shape({
|
|
|
|
hide: PropTypes.func.isRequired
|
|
|
|
})
|
2016-04-10 02:58:48 +00:00
|
|
|
}),
|
|
|
|
modals: PropTypes.array.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
actions: state.actions,
|
|
|
|
modals: state.modals
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2016-04-16 23:24:57 +00:00
|
|
|
actions: {
|
2016-04-26 07:29:24 +00:00
|
|
|
modals: bindActionCreators(ModalActions, dispatch)
|
2016-04-16 23:24:57 +00:00
|
|
|
}
|
2016-04-10 02:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
2016-04-15 05:23:54 +00:00
|
|
|
)(Prompts);
|
2016-04-10 02:58:48 +00:00
|
|
|
|