<commit_before>// TODO: IK: maybe rename this / move somewhere else
import createAction from '@f/create-action'

import { combineEpics } from 'redux-observable'
import Rx from 'rxjs'

import { actions as tokenConsumes } from '../../tokens/dux/tokenConsumes'
import { authentication } from 'dogstack-agents/actions'

import { merge } from 'ramda'

// actions
const payloadCtor = (cid, payload) => payload
const metaCtor = (cid) => ({ cid })

export const invitedPatchPassword = createAction('INVITED_PATCH_PASSWORD', payloadCtor, metaCtor)

// epics
export default combineEpics(patchPasswordAndSignIn)

export function patchPasswordAndSignIn (action$, store, { feathers }) {
  return action$.ofType(invitedPatchPassword.type)
    .switchMap(({ payload, meta: { cid }}) => {
      const patchPasswordPayload = { jwt: payload.jwt, payload: { data: { password: payload.password } } }
      return Rx.Observable.merge(
        Rx.Observable.of(tokenConsumes.create(cid, patchPasswordPayload)),
        action$.ofType(tokenConsumes.start.type).filter((action) => action.meta.cid === cid).take(1)
      )
    })
    .do(console.log)
}
<commit_msg>successful password update and sign in, breaking on redirect to home with form not destroying correctly<commit_after>// TODO: IK: maybe rename this / move somewhere else
import createAction from '@f/create-action'
import { push } from 'react-router-redux'

import { combineEpics } from 'redux-observable'
import Rx from 'rxjs'

import { actions as tokenConsumes } from '../../tokens/dux/tokenConsumes'
import { authentication } from 'dogstack-agents/actions'

import { merge } from 'ramda'

// actions
const payloadCtor = (cid, payload) => payload
const metaCtor = (cid) => ({ cid })

export const invitedPatchPassword = createAction('INVITED_PATCH_PASSWORD', payloadCtor, metaCtor)

// epics
export default combineEpics(patchPasswordAndSignIn)

export function patchPasswordAndSignIn (action$, store, { feathers }) {
  return action$.ofType(invitedPatchPassword.type)
    .switchMap(({ payload, meta: { cid }}) => {
      // TODO: IK: this should probably be a util function or somthing ramda-smart
      function onlyCid (action) {
        return action.meta.cid === cid
      }

      const tokenConsumesComplete$ = action$.ofType(tokenConsumes.complete.type).filter(onlyCid).take(1)
      const tokenConsumesSet$ = action$.ofType(tokenConsumes.set.type).filter(onlyCid)
      const signInSuccess$ = action$.ofType(authentication.signInSuccess.type).filter(onlyCid).take(1)

      const password = <PASSWORD>
      const patchPasswordPayload = { jwt: payload.jwt, payload: { data: { password } } }

      return Rx.Observable.merge(
        Rx.Observable.of(tokenConsumes.create(cid, patchPasswordPayload)),
        tokenConsumesComplete$
          .withLatestFrom(tokenConsumesSet$, (success, set) => set.payload.data)
          .mergeMap(({ result: { email } }) => {
            return Rx.Observable.of(authentication.signIn(cid, { strategy: 'local', email, password }))
          }),
        signInSuccess$.mapTo(push('/')) // TODO this should be configurable
      )
    })
}

{'fraction_non_alphanumeric': 0.1255203330131284, 'fraction_numerical': 0.0009606147934678194, 'mean_word_length': 3.9430379746835444, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 13, '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': '5482636', 'n_tokens_mistral': 940, 'n_tokens_neox': 929, 'n_words': 230}