|
@ -8,6 +8,7 @@ import { createDatabases } from './../util/orbit'; |
|
|
import { updateUsername } from '../redux/actions/transactionsMonitorActions'; |
|
|
import { updateUsername } from '../redux/actions/transactionsMonitorActions'; |
|
|
|
|
|
|
|
|
const contract = "Forum"; |
|
|
const contract = "Forum"; |
|
|
|
|
|
const checkUsernameTakenMethod = "isUserNameTaken"; |
|
|
const signUpMethod = "signUp"; |
|
|
const signUpMethod = "signUp"; |
|
|
|
|
|
|
|
|
class UsernameFormContainer extends Component { |
|
|
class UsernameFormContainer extends Component { |
|
@ -18,11 +19,14 @@ class UsernameFormContainer extends Component { |
|
|
this.handleSubmit = this.handleSubmit.bind(this); |
|
|
this.handleSubmit = this.handleSubmit.bind(this); |
|
|
this.completeAction = this.completeAction.bind(this); |
|
|
this.completeAction = this.completeAction.bind(this); |
|
|
|
|
|
|
|
|
this.contracts = context.drizzle.contracts; |
|
|
this.drizzle = context.drizzle; |
|
|
|
|
|
this.contracts = this.drizzle.contracts; |
|
|
|
|
|
|
|
|
this.state = { |
|
|
this.state = { |
|
|
usernameInput: '', |
|
|
usernameInput: '', |
|
|
error: false, |
|
|
error: false, |
|
|
|
|
|
errorHeader: "", |
|
|
|
|
|
errorMessage: "", |
|
|
signingUp: false |
|
|
signingUp: false |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
@ -33,9 +37,18 @@ class UsernameFormContainer extends Component { |
|
|
|
|
|
|
|
|
handleSubmit() { |
|
|
handleSubmit() { |
|
|
if (this.state.usernameInput === ''){ |
|
|
if (this.state.usernameInput === ''){ |
|
|
this.setState({ error: true }); |
|
|
this.setState({ |
|
|
|
|
|
error: true, |
|
|
|
|
|
errorHeader: "Data Incomplete", |
|
|
|
|
|
errorMessage: "You need to provide a username" |
|
|
|
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
this.completeAction(); |
|
|
this.checkUsernameTakenDataKey = this.contracts[contract].methods[checkUsernameTakenMethod] |
|
|
|
|
|
.cacheCall(this.state.usernameInput); |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
error: false |
|
|
|
|
|
}); |
|
|
|
|
|
this.checkingUsernameTaken = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -63,6 +76,28 @@ class UsernameFormContainer extends Component { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentWillUpdate() { |
|
|
|
|
|
if (this.checkingUsernameTaken){ |
|
|
|
|
|
let dataFetched = this.drizzle.store.getState() |
|
|
|
|
|
.contracts[contract][checkUsernameTakenMethod][this.checkUsernameTakenDataKey]; |
|
|
|
|
|
if (dataFetched){ |
|
|
|
|
|
this.checkingUsernameTaken = false; |
|
|
|
|
|
if (dataFetched.value){ |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
error: true, |
|
|
|
|
|
errorHeader: "Data disapproved", |
|
|
|
|
|
errorMessage: "This username is already taken" |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
error: false |
|
|
|
|
|
}); |
|
|
|
|
|
this.completeAction(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const hasSignedUp = this.props.user.hasSignedUp; |
|
|
const hasSignedUp = this.props.user.hasSignedUp; |
|
|
|
|
|
|
|
@ -85,14 +120,14 @@ class UsernameFormContainer extends Component { |
|
|
</Form.Field> |
|
|
</Form.Field> |
|
|
<Message |
|
|
<Message |
|
|
error |
|
|
error |
|
|
header='Data Incomplete' |
|
|
header={this.state.errorHeader} |
|
|
content='You need to provide a username to sign up for an account.' |
|
|
content={this.state.errorMessage} |
|
|
/> |
|
|
/> |
|
|
<Button type='submit'>{buttonText}</Button> |
|
|
<Button type='submit'>{buttonText}</Button> |
|
|
</Form> |
|
|
</Form> |
|
|
<Dimmer active={this.state.signingUp} page> |
|
|
<Dimmer active={this.state.signingUp || this.checkingUsernameTaken} page> |
|
|
<Header as='h2' inverted> |
|
|
<Header as='h2' inverted> |
|
|
<Loader size='large'>Magic elves are processing your noble request.</Loader> |
|
|
<Loader size='large'>Magic elfs are processing your nobel request.</Loader> |
|
|
</Header> |
|
|
</Header> |
|
|
</Dimmer> |
|
|
</Dimmer> |
|
|
</div> |
|
|
</div> |
|
@ -109,7 +144,6 @@ UsernameFormContainer.contextTypes = { |
|
|
|
|
|
|
|
|
const mapStateToProps = state => { |
|
|
const mapStateToProps = state => { |
|
|
return { |
|
|
return { |
|
|
contracts: state.contracts, |
|
|
|
|
|
user: state.user |
|
|
user: state.user |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|