Merge pull request #94 from xavcz/master

Better support for Server-Side Rendering & client-only code in React client-only lifecycle hook
This commit is contained in:
Tim Brandin 2017-02-06 21:18:52 +01:00 committed by GitHub
commit 79781e2439

View file

@ -44,46 +44,51 @@ export class LoginForm extends Tracker.Component {
onSignedOutHook: props.onSignedOutHook || Accounts.ui._options.onSignedOutHook,
onPreSignUpHook: props.onPreSignUpHook || Accounts.ui._options.onPreSignUpHook,
onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook,
// Add default field values.
...this.getDefaultFieldValues(),
};
}
componentDidMount() {
this.setState(prevState => ({ waiting: false, ready: true }));
let changeState = Session.get(KEY_PREFIX + 'state');
switch (changeState) {
case 'enrollAccountToken':
this.setState(prevState => ({
formState: STATES.ENROLL_ACCOUNT
}));
Session.set(KEY_PREFIX + 'state', null);
break;
case 'resetPasswordToken':
this.setState(prevState => ({
formState: STATES.PASSWORD_CHANGE
}));
Session.set(KEY_PREFIX + 'state', null);
break;
case 'justVerifiedEmail':
this.setState(prevState => ({
formState: STATES.PROFILE
}));
Session.set(KEY_PREFIX + 'state', null);
break;
}
// Add default field values once the form did mount on the client
this.setState(prevState => ({
...this.getDefaultFieldValues(),
}));
// Listen for the user to login/logout.
this.autorun(() => {
// Add the services list to the user.
this.subscribe('servicesList');
this.setState({
user: Accounts.user()
});
});
}
componentDidMount() {
this.setState({ waiting: false, ready: true });
let changeState = Session.get(KEY_PREFIX + 'state');
switch (changeState) {
case 'enrollAccountToken':
this.setState({
formState: STATES.ENROLL_ACCOUNT
});
Session.set(KEY_PREFIX + 'state', null);
break;
case 'resetPasswordToken':
this.setState({
formState: STATES.PASSWORD_CHANGE
});
Session.set(KEY_PREFIX + 'state', null);
break;
case 'justVerifiedEmail':
this.setState({
formState: STATES.PROFILE
});
Session.set(KEY_PREFIX + 'state', null);
break;
}
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.formState && nextProps.formState !== this.state.formState) {
this.setState({
@ -992,6 +997,6 @@ export class LoginForm extends Tracker.Component {
/>
);
}
};
}
Accounts.ui.LoginForm = LoginForm;