2017-06-08_509bba0/509bba0_unpacked_with_node_modules/discord_app/components/ChangeVanityURLModal.js
2022-07-26 10:06:20 -07:00

74 lines
2.1 KiB
JavaScript
Executable file

import React from 'react';
import classNames from 'classnames';
import {getInviteURL} from '../utils/InstantInviteUtils';
import ChangeVanityURLModalStore from '../stores/ChangeVanityURLModalStore';
import ChangeVanityURLActionCreators from '../actions/ChangeVanityURLActionCreators';
import i18n from '../i18n';
const CODE_REF = 'CODE_REF';
const ChangeVanityURLModal = React.createClass({
statics: {
modalConfig: {
store: ChangeVanityURLModalStore,
},
},
propTypes: {
guildId: React.PropTypes.string.isRequired,
code: React.PropTypes.string,
errors: React.PropTypes.object.isRequired,
submitting: React.PropTypes.bool.isRequired,
},
close() {
ChangeVanityURLActionCreators.closeModal();
},
componentDidMount() {
this.refs[CODE_REF].select();
},
render() {
const {code, hasError} = this.props;
return (
<form className="form" onSubmit={this.handleSubmit}>
<div className="form-header">
<header>{i18n.Messages.CHANGE_VANITY_URL}</header>
</div>
<div className="form-inner">
<div className={classNames({'control-group': true, error: hasError})}>
<label htmlFor="vanity-url-code">
{hasError ? <span className="error">{i18n.Messages.CHANGE_VANITY_URL_ERROR}</span> : getInviteURL()}
</label>
<input id="vanity-url-code" type="text" ref={CODE_REF} defaultValue={code} autoFocus />
</div>
</div>
<div className="form-actions">
<button type="button" className="btn btn-default" onClick={this.close}>
{i18n.Messages.CANCEL}
</button>
<button type="submit" className="btn btn-primary" disabled={this.props.submitting}>
{i18n.Messages.SAVE}
</button>
</div>
</form>
);
},
// Handlers
handleSubmit(e) {
e.preventDefault();
const code = this.refs[CODE_REF].value;
ChangeVanityURLActionCreators.changeVanityURL(this.props.guildId, code);
},
});
export default ChangeVanityURLModal;
// WEBPACK FOOTER //
// ./discord_app/components/ChangeVanityURLModal.js