Vulcan/packages/framework-demo/lib/components/Accounts.jsx

58 lines
No EOL
1.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { PropTypes, Component } from 'react';
import { Button, FormControl } from 'react-bootstrap';
import { Accounts } from 'meteor/std:accounts-ui';
import { withApollo } from 'react-apollo';
Accounts.ui.config({
passwordSignupFields: 'USERNAME_AND_EMAIL',
});
const AccountsComponent = ({client}) => {
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') {
return <a href={ href } className={ className } onClick={ onClick }>{ label }</a>;
}
return <Button
bsStyle="primary"
className={ className }
type={ type } 
disabled={ disabled }
onClick={ onClick }>{ label }
</Button>;
}
}
class AccountsField extends Accounts.ui.Field {
render() {
const { id, hint, /* label, */ type = 'text', onChange, className = "field", defaultValue = "", message } = this.props;
const { mount = true } = this.state;
return mount ? (
<div className={ className }>
<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>
)}
</div>
) : null;
}
}
Accounts.ui.Button = AccountsButton;
Accounts.ui.Field = AccountsField;
export default withApollo(AccountsComponent);