Basic registration form functionality
This commit is contained in:
parent
7d3089270a
commit
af2cbc3455
3 changed files with 33 additions and 3 deletions
|
@ -6,6 +6,10 @@ export const AUTH_APP_AUTHORIZED = 'AUTH_APP_AUTHORIZED';
|
||||||
export const AUTH_LOGGED_IN = 'AUTH_LOGGED_IN';
|
export const AUTH_LOGGED_IN = 'AUTH_LOGGED_IN';
|
||||||
export const AUTH_LOGGED_OUT = 'AUTH_LOGGED_OUT';
|
export const AUTH_LOGGED_OUT = 'AUTH_LOGGED_OUT';
|
||||||
|
|
||||||
|
export const AUTH_REGISTER_REQUEST = 'AUTH_REGISTER_REQUEST';
|
||||||
|
export const AUTH_REGISTER_SUCCESS = 'AUTH_REGISTER_SUCCESS';
|
||||||
|
export const AUTH_REGISTER_FAIL = 'AUTH_REGISTER_FAIL';
|
||||||
|
|
||||||
export function createAuthApp() {
|
export function createAuthApp() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const appToken = getState().getIn(['auth', 'app', 'access_token']);
|
const appToken = getState().getIn(['auth', 'app', 'access_token']);
|
||||||
|
@ -57,6 +61,17 @@ export function logOut() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function register(params) {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
dispatch({ type: AUTH_REGISTER_REQUEST });
|
||||||
|
return api(getState).post('/api/v1/accounts', params).then(response => {
|
||||||
|
dispatch({ type: AUTH_REGISTER_SUCCESS, response });
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch({ type: AUTH_REGISTER_FAIL, error });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function authAppCreated(app) {
|
export function authAppCreated(app) {
|
||||||
return {
|
return {
|
||||||
type: AUTH_APP_CREATED,
|
type: AUTH_APP_CREATED,
|
||||||
|
|
|
@ -115,7 +115,7 @@ FieldsGroup.propTypes = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Checkbox = props => (
|
export const Checkbox = props => (
|
||||||
<SimpleInput type='checkbox' {...props} />
|
<SimpleInput type='checkbox' value {...props} />
|
||||||
);
|
);
|
||||||
|
|
||||||
export class RadioGroup extends ImmutablePureComponent {
|
export class RadioGroup extends ImmutablePureComponent {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
TextInput,
|
TextInput,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
} from 'gabsocial/features/forms';
|
} from 'gabsocial/features/forms';
|
||||||
|
import { register } from 'gabsocial/actions/auth';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
instance: state.get('instance'),
|
instance: state.get('instance'),
|
||||||
|
@ -21,8 +22,16 @@ class RegistrationForm extends ImmutablePureComponent {
|
||||||
instance: ImmutablePropTypes.map,
|
instance: ImmutablePropTypes.map,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onInputChange = e => {
|
||||||
|
this.setState({ [e.target.name]: e.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
onCheckboxChange = e => {
|
||||||
|
this.setState({ [e.target.name]: e.target.checked });
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit = e => {
|
onSubmit = e => {
|
||||||
// TODO: Dispatch action
|
this.props.dispatch(register(this.state));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -38,6 +47,7 @@ class RegistrationForm extends ImmutablePureComponent {
|
||||||
placeholder='Username'
|
placeholder='Username'
|
||||||
name='username'
|
name='username'
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
|
onChange={this.onInputChange}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<SimpleInput
|
<SimpleInput
|
||||||
|
@ -45,6 +55,7 @@ class RegistrationForm extends ImmutablePureComponent {
|
||||||
name='email'
|
name='email'
|
||||||
type='email'
|
type='email'
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
|
onChange={this.onInputChange}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<SimpleInput
|
<SimpleInput
|
||||||
|
@ -52,13 +63,15 @@ class RegistrationForm extends ImmutablePureComponent {
|
||||||
name='password'
|
name='password'
|
||||||
type='password'
|
type='password'
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
|
onChange={this.onInputChange}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<SimpleInput
|
<SimpleInput
|
||||||
placeholder='Confirm password'
|
placeholder='Confirm password'
|
||||||
name='password_confirmation'
|
name='confirm'
|
||||||
type='password'
|
type='password'
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
|
onChange={this.onInputChange}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -66,9 +79,11 @@ class RegistrationForm extends ImmutablePureComponent {
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label={<>I agree to the <Link to='/about/tos' target='_blank'>Terms of Service</Link>.</>}
|
label={<>I agree to the <Link to='/about/tos' target='_blank'>Terms of Service</Link>.</>}
|
||||||
name='agreement'
|
name='agreement'
|
||||||
|
onChange={this.onCheckboxChange}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<input type='hidden' name='locale' value='en_US' />
|
||||||
<div className='actions'>
|
<div className='actions'>
|
||||||
<button name='button' type='submit' className='btn button button-primary'>Sign up</button>
|
<button name='button' type='submit' className='btn button button-primary'>Sign up</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue