2016-11-24 15:47:51 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import { Button, FormControl } from 'react-bootstrap';
|
|
|
|
import { Accounts } from 'meteor/std:accounts-ui';
|
|
|
|
import { withApollo } from 'react-apollo';
|
2017-01-18 12:51:10 +01:00
|
|
|
import { registerComponent } from 'meteor/nova:core';
|
2016-11-24 15:47:51 +09:00
|
|
|
|
|
|
|
Accounts.ui.config({
|
|
|
|
passwordSignupFields: 'USERNAME_AND_EMAIL',
|
|
|
|
});
|
|
|
|
|
2017-01-18 12:51:10 +01:00
|
|
|
const AccountsForm = ({client}) => {
|
2016-11-24 15:47:51 +09:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Accounts.ui.LoginForm
|
|
|
|
onPostSignUpHook={() => client.resetStore()}
|
|
|
|
onSignedInHook={() => client.resetStore()}
|
|
|
|
onSignedOutHook={() => client.resetStore()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
class AccountsButton extends Accounts.ui.Button {
|
|
|
|
render () {
|
|
|
|
const {label, href, type, disabled, className, onClick} = this.props;
|
|
|
|
if (type === 'link') {
|
2017-01-18 12:51:10 +01:00
|
|
|
return <a href={ href } className={ className } onClick={ onClick }>{ label }</a>;
|
2016-11-24 15:47:51 +09:00
|
|
|
}
|
|
|
|
return <Button
|
|
|
|
bsStyle="primary"
|
|
|
|
className={ className }
|
2017-01-18 12:51:10 +01:00
|
|
|
type={ type }
|
2016-11-24 15:47:51 +09:00
|
|
|
disabled={ disabled }
|
|
|
|
onClick={ onClick }>{ label }
|
|
|
|
</Button>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AccountsField extends Accounts.ui.Field {
|
|
|
|
|
|
|
|
render() {
|
2017-01-18 10:18:33 +09:00
|
|
|
const { id, hint, /* label, */ type = 'text', onChange, className = "field", defaultValue = "", message } = this.props;
|
2016-11-24 15:47:51 +09:00
|
|
|
const { mount = true } = this.state;
|
|
|
|
return mount ? (
|
|
|
|
<div className={ className }>
|
2017-01-18 10:18:33 +09:00
|
|
|
<FormControl id={ id } type={ type } inputRef={ref => { this.input = ref; }} onChange={ onChange } placeholder={ hint } defaultValue={ defaultValue } />
|
|
|
|
{message && (
|
|
|
|
<span className={['message', message.type].join(' ').trim()}>
|
|
|
|
{message.message}</span>
|
|
|
|
)}
|
2016-11-24 15:47:51 +09:00
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Accounts.ui.Button = AccountsButton;
|
|
|
|
Accounts.ui.Field = AccountsField;
|
|
|
|
|
2017-01-18 12:51:10 +01:00
|
|
|
registerComponent('AccountsForm', AccountsForm, withApollo);
|