<commit_before>import React from 'react';
import {connect} from 'react-redux';
import Button from 'react-bootstrap/lib/Button.js';

import {register}  from '../client.js';
import RegistrationFields from '../sections/registration-fields.jsx';
import * as actionCreators from '../action_creators';
import composePage from './base-page.jsx';

class NewVolunteerPage extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            focusElement: "data.q_first_name",
            alertVisible: false,
            errorFields: {},
            errorMessage : 'Form error',
            disabled: false,
            value: "Create"
        };

        this.schema = {
            fieldPrefix: 'data.',
            properties: {
                q_first_name: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_last_name: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_1: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_city: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_state: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_zip: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_email: {
                    type: 'string',
                    maxLength: 255,
                    format: 'email',
                    required: true,
                    allowEmpty: false
                },
                q_dob: {
                    type: 'string',
                    pattern: /^((0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2})*$/,
                    required: true
                },
                q_password: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                }
            }
        };

        this.doRegister = this.doRegister.bind(this);
        this.doCancel = this.doCancel.bind(this);
    }


    componentWillMount() {
        // reset to initial state whenever this form appears
        this.props.reset();
        this.props.fetchOptions();
        // fetch list options

    }

    doRegister() {
        // validation
        var self = this;
        if ( this.props.doValidate(this.schema, this.props.data) ) {
            var data = {
                'username' : this.props.data['q_email'],
                'last_name' : this.props.data['q_last_name'],
                'first_name' : this.props.data['q_first_name'],
                'middle_name' : this.props.data['q_middle_name'],
                'email': this.props.data['q_email'],
                'password' : <PASSWORD>['<PASSWORD>']
            };
            // disable button on click to prevent multiple clicks
            this.setState({
              disabled: true,
              value: "Please Wait"
            });

            register(data).then(
                (response) => {
                    self.props.login({
                        token: response.token
                    })
                    sessionStorage.setItem('token', response.token);
                    this.props.saveApplication();
                    self.props.history.pushState(null, '/do-register');
<commit_msg>only transition to next page on successful save<commit_after>import React from 'react';
import {connect} from 'react-redux';
import Button from 'react-bootstrap/lib/Button.js';

import {register}  from '../client.js';
import RegistrationFields from '../sections/registration-fields.jsx';
import * as actionCreators from '../action_creators';
import composePage from './base-page.jsx';

class NewVolunteerPage extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            focusElement: "data.q_first_name",
            alertVisible: false,
            errorFields: {},
            errorMessage : 'Form error',
            disabled: false,
            value: "Create"
        };

        this.schema = {
            fieldPrefix: 'data.',
            properties: {
                q_first_name: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_last_name: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_1: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_city: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_state: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_address_zip: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                },
                q_email: {
                    type: 'string',
                    maxLength: 255,
                    format: 'email',
                    required: true,
                    allowEmpty: false
                },
                q_dob: {
                    type: 'string',
                    pattern: /^((0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2})*$/,
                    required: true
                },
                q_password: {
                    type: 'string',
                    maxLength: 255,
                    required: true,
                    allowEmpty: false
                }
            }
        };

        this.doRegister = this.doRegister.bind(this);
        this.doCancel = this.doCancel.bind(this);
    }


    componentWillMount() {
        // reset to initial state whenever this form appears
        this.props.reset();
        this.props.fetchOptions();
        // fetch list options

    }

    doRegister() {
        // validation
        var self = this;
        if ( this.props.doValidate(this.schema, this.props.data) ) {
            var data = {
                'username' : this.props.data['q_email'],
                'last_name' : this.props.data['q_last_name'],
                'first_name' : this.props.data['q_first_name'],
                'middle_name' : this.props.data['q_middle_name'],
                'email': this.props.data['q_email'],
                'password' : this.props.data['q_password']
            };
            // disable button on click to prevent multiple clicks
            this.setState({
              disabled: true,
              value: "Please Wait"
            });

            register(data).then(
                (response) => {
                  self.props.login({
                      token: response.token
                  })
                  sessionStorage.setItem('token', response.token);
                  this.props.saveApplication().then(
                    (success) => {
                      self.props.history.pushState(null, '/do-register');
                    },
                    (error) => {
                      sessionStorage.clear();
                      self.props.handleAlertShow({
                          errorMessage: "Something went wrong, please try again in a little while",
                          focusElement: 'q_first_name'
                      });
                      self.setState({
                          disabled: false,
                          value: "Continue"
                      });
                    }
                  )
{'fraction_non_alphanumeric': 0.10610110400929693, 'fraction_numerical': 0.011388727484020918, 'mean_word_length': 1.0378877575183518, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2751117', 'n_tokens_mistral': 2221, 'n_tokens_neox': 1992, 'n_words': 427}