Add phases to CreateRoom organism

This commit is contained in:
Erik Johnston 2015-07-14 17:27:22 +01:00
parent a077abfb99
commit c4764af9a2
2 changed files with 54 additions and 10 deletions

View File

@ -45,13 +45,29 @@ module.exports = React.createClass({
}, },
render: function() { render: function() {
var curr_phase = this.state.phase;
if (curr_phase == this.phases.CREATING) {
return (
<div>Creating...</div>
);
} else {
var error_box = "";
if (curr_phase == this.phases.ERROR) {
error_box = (
<div className="mx_Error">
An error occured: {this.state.error_string}
</div>
);
}
return ( return (
<div className="mx_CreateRoom"> <div className="mx_CreateRoom">
<label>Room Name <RoomNameTextbox ref="name_textbox" /></label> <label>Room Name <RoomNameTextbox ref="name_textbox" /></label>
<Presets ref="presets"/> <Presets ref="presets"/>
<UserSelector ref="user_selector"/> <UserSelector ref="user_selector"/>
<CreateRoomButton onCreateRoom={this.onCreateRoom} /> <CreateRoomButton onCreateRoom={this.onCreateRoom} />
{error_box}
</div> </div>
); );
} }
}
}); });

View File

@ -24,12 +24,26 @@ module.exports = {
onRoomCreated: React.PropTypes.func, onRoomCreated: React.PropTypes.func,
}, },
phases: {
CONFIG: "CONFIG",
CREATING: "CREATING",
CREATED: "CREATED",
ERROR: "ERROR",
},
getDefaultProps: function() { getDefaultProps: function() {
return { return {
onRoomCreated: function() {}, onRoomCreated: function() {},
}; };
}, },
getInitialState: function() {
return {
phase: this.phases.CONFIG,
error_string: "",
};
},
onCreateRoom: function() { onCreateRoom: function() {
var options = {}; var options = {};
@ -57,8 +71,22 @@ module.exports = {
var deferred = MatrixClientPeg.get().createRoom(options); var deferred = MatrixClientPeg.get().createRoom(options);
deferred.done(function () { this.setState({
this.props.onRoomCreated(); phase: this.phases.CREATING,
});
var self = this;
deferred.then(function () {
self.setState({
phase: self.phases.CREATED,
});
self.props.onRoomCreated();
}, function(err) {
self.setState({
phase: self.phases.ERROR,
error_string: err.toString(),
});
}); });
} }
}; };