<commit_before>import {state} from 'cerebral/tags'
import {set, when} from 'cerebral/operators'
import {isValidForm} from 'cerebral-provider-forms/operators'
import {httpPost} from 'cerebral-provider-http/operators'
import initUser from '../actions/initUser'
import setValidationError from '../factories/setValidationError'

export default [
  isValidForm(state`user.signIn`), {
    true: [
      set(state`user.signIn.isLoading`, true),
      httpPost('/login', {
        email: state`user.signIn.email.value`,
        password: state`user.signIn.password.value`
      }), {
        success: [
          set(state`user.signIn.email.value`, ''),
          set(state`user.signIn.password.value`, ''),
          set(state`user.signIn.showErrors`, false),
          set(state`user.signIn.validationError`, null),
          initUser,
          set(state`user.signIn.isLoading`, false),
          when(state`app.lastVisited`), {
            true: set(state`app.currentPage`, state`app.lastVisited`),
            false: set(state`app.currentPage`, 'home')
          }
        ],
        error: [
          set(state`user.signIn.password.value`, ''),
          set(state`user.signIn.showErrors`, false),
          setValidationError(
            'user.signIn.validationError',
            'Could not log-in!'
          ),
          set(state`user.signIn.isLoading`, false)
        ]
      }
    ],
    false: set(state`user.signIn.showErrors`, true)
  }
]<commit_msg>refactor(client): use routeTo for redirecting after login<commit_after>import {state} from 'cerebral/tags'
import {set, when} from 'cerebral/operators'
import {isValidForm} from 'cerebral-provider-forms/operators'
import {httpPost} from 'cerebral-provider-http/operators'
import routeTo from '../../common/factories/routeTo'
import initUser from '../actions/initUser'
import setValidationError from '../factories/setValidationError'

export default [
  isValidForm(state`user.signIn`), {
    true: [
      set(state`user.signIn.isLoading`, true),
      httpPost('/login', {
        email: state`user.signIn.email.value`,
        password: state`user.signIn.password.value`
      }), {
        success: [
          set(state`user.signIn.email.value`, ''),
          set(state`user.signIn.password.value`, ''),
          set(state`user.signIn.showErrors`, false),
          set(state`user.signIn.validationError`, null),
          initUser,
          set(state`user.signIn.isLoading`, false),
          when(state`app.lastVisited`), {
            true: routeTo(state`app.lastVisited`),
            false: routeTo('home')
          }
        ],
        error: [
          set(state`user.signIn.password.value`, ''),
          set(state`user.signIn.showErrors`, false),
          setValidationError(
            'user.signIn.validationError',
            'Could not log-in!'
          ),
          set(state`user.signIn.isLoading`, false)
        ]
      }
    ],
    false: set(state`user.signIn.showErrors`, true)
  }
]
{'fraction_non_alphanumeric': 0.14544843802485724, 'fraction_numerical': 0.0, 'mean_word_length': 2.592279855247286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2267716', 'n_tokens_mistral': 915, 'n_tokens_neox': 909, 'n_words': 142}