imports/ui/pages/accounts/account_activation.js
/**
   * Validate the form and activate the user account
   */
Validate the form and activate the user account
Validate the form and activate the user account
handleConfirmActivation() {
    this.refs.locationConfirmModal.hide();
    var target = $('.btn-submit');
    target.button('loading');
    if (!this.state.professionalHeadline) {
      Alert.warning('You must set a professional headline', {
        position: 'top-right',
        effect: 'jelly'
      });
      target.button('reset');
      this.refs.professionalHeadline.focus();
      return;
    }
    if (Object.keys(this.state.skills).length < 3) {
      Alert.warning('You must choose at least 3 skills', {
        position: 'top-right',
        effect: 'jelly'
      });
      target.button('reset');
      this.refs.accountActivationSkillInput.focusInput();
      return;
    }
    console.log('this.state.location:', this.state.location);
    console.log('this.state.confirmedPlace:', this.state.confirmedPlace);
    if (this.state.location) {
      if (!this.state.confirmedPlace) {
        this.openLocationConfirmationModal();
        return;
      }
    }
    else {
      Alert.warning('You must set a location', {
        position: 'top-right',
        effect: 'jelly'
      });
      this.refs.activationGeocoder.setInputFocus();
      return;
    }
    var skills = Object.keys(this.state.skills);
    var skillsIds = [], customSkills = [];
    for (var i = 0; i < skills.length; i++) {
      if (skills[i].indexOf('custom-') > -1) {
        customSkills.push(this.state.skills[skills[i]]);
      }
      else {
        skillsIds.push(skills[i]);
      }
    }
    Meteor.call(
      'users.profile.activate',
      this.state.professionalHeadline,
      skillsIds,
      customSkills,
      this.state.confirmedPlace,
      (err, res) => {
        target.button('reset');
        if (err) {
          if (err.reason == 'Incomplete location') {
            this.setState({confirmedPlace: null});
            Alert.warning(`Incomplete address. \n
              The address must contain at least a
              country, a region and a postcode`, {
              position: 'top-right',
              effect: 'jelly'
            });
          }
        }
        else {
          let user = Meteor.user();
          browserHistory.push('/users/' + user.profile.username);
        }
    });
  }
handleConfirmActivation ( ) { this . refs . locationConfirmModal . hide ( ) ; var target = $ ( '.btn-submit' ) ; target . button ( 'loading' ) ; if ( ! this . state . professionalHeadline ) { Alert . warning ( 'You must set a professional headline' , { position : 'top-right' , effect : 'jelly' } ) ; target . button ( 'reset' ) ; this . refs . professionalHeadline . focus ( ) ; return ; } if ( Object . keys ( this . state . skills ) . length < 3 ) { Alert . warning ( 'You must choose at least 3 skills' , { position : 'top-right' , effect : 'jelly' } ) ; target . button ( 'reset' ) ; this . refs . accountActivationSkillInput . focusInput ( ) ; return ; } console . log ( 'this.state.location:' , this . state . location ) ; console . log ( 'this.state.confirmedPlace:' , this . state . confirmedPlace ) ; if ( this . state . location ) { if ( ! this . state . confirmedPlace ) { this . openLocationConfirmationModal ( ) ; return ; } } else { Alert . warning ( 'You must set a location' , { position : 'top-right' , effect : 'jelly' } ) ; this . refs . activationGeocoder . setInputFocus ( ) ; return ; } var skills = Object . keys ( this . state . skills ) ; var skillsIds = [ ] , customSkills = [ ] ; for ( var i = 0 ; i < skills . length ; i ++ ) { if ( skills [ i ] . indexOf ( 'custom-' ) > - 1 ) { customSkills . push ( this . state . skills [ skills [ i ] ] ) ; } else { skillsIds . push ( skills [ i ] ) ; } } Meteor . call ( 'users.profile.activate' , this . state . professionalHeadline , skillsIds , customSkills , this . state . confirmedPlace , ( err , res ) => { target . button ( 'reset' ) ; if ( err ) { if ( err . reason == 'Incomplete location' ) { this . setState ( { confirmedPlace : null } ) ; Alert . warning ( ` \n ` , { position : 'top-right' , effect : 'jelly' } ) ; } } else { let user = Meteor . user ( ) ; browserHistory . push ( '/users/' + user . profile . username ) ; } } ) ; }
Validate the form and activate the user account
Validate the form and activate the user account
// Hide the location confirmation modal by default // Set the submit btn state to loading // Check if the user has an professional headline // Focus on the input // Check if there is at least 3 skills // Display a warning // Focus on the input // Check if there is a location value // If the place hasn't been confirmed // Open the location confirmation modal // Focus on the input // Get the ids of the selected skills // Check if this is a custom skill // Push it in the customSkills array // If it's an existing skill // Push it in the skillsIds array // Update the user profile with his new skills // Unset the confirmedPlace // Redirect the user to his profile page