<commit_before>import {
  SELECT_ORG,
  SELECT_ACCOUNT,
  SELECT_ACCOUNT_SUCCESS,
  FETCH_CURRENT_USER_SUCCESS,
  LOGIN,
  LOGIN_REQUEST,
  LOGIN_SUCCESS,
  REGISTER,
  REGISTER_SUCCESS,
  CREATE_ORG_REQUEST,
  CREATE_ORG_SUCCESS,
  CREATE_ORG_FAILED,
  LOGOUT,
  ORG_INVALID,
  LOAD_INVITE_API_SUCCESS,
  ACCEPT_INVITE_SUCCESS,
  RENAME_OBJECT_SUCCESS,
  BILLING_UPGRADE_SUBSCRIPTION,
  BILLING_OPEN_STRIPE_FORM,
  BILLING_STRIPE_FORM_SUBMITTED,
  BILLING_STRIPE_FORM_CLOSED,
  BILLING_UPDATE_SUBSCRIPTION_REQUEST,
  BILLING_UPDATE_SUBSCRIPTION_SUCCESS,
  BILLING_UPDATE_SUBSCRIPTION_FAILED,
  BILLING_UPDATE_CARD_REQUEST,
  BILLING_UPDATE_CARD_SUCCESS,
  BILLING_UPDATE_CARD_FAILED,
  FETCH_CURRENT_USER_UPDATES_API_SUCCESS,
  UPDATE_ORG_OWNER_REQUEST,
  UPDATE_ORG_OWNER_SUCCESS,
  UPDATE_ORG_OWNER_FAILED,
  BILLING_FETCH_INVOICE_LIST_REQUEST,
  BILLING_FETCH_INVOICE_LIST_SUCCESS,
  BILLING_FETCH_INVOICE_LIST_FAILED,
  BILLING_FETCH_INVOICE_PDF,
  BILLING_FETCH_INVOICE_PDF_SUCCESS,
  BILLING_FETCH_INVOICE_PDF_FAILED,
  BILLING_SAVE_INVOICE_PDF_SUCCESS,
  BILLING_SAVE_INVOICE_PDF_FAILED

} from "actions"
import R from 'ramda'
import {indexById} from './helpers'

export const
  currentOrgSlug = (state = null, action)=>{
    switch(action.type){
      case SELECT_ORG:
        return action.payload

      case LOAD_INVITE_API_SUCCESS:
        return action.payload.org.slug

      case REGISTER_SUCCESS:
      case CREATE_ORG_SUCCESS:
        let orgs = action.payload.orgs
        return orgs[orgs.length - 1].slug

      case ACCEPT_INVITE_SUCCESS:
        return action.meta.orgSlug

      case LOGIN:
      case LOGIN_REQUEST:
      case REGISTER:
      case LOGOUT:
      case ORG_INVALID:
      case SELECT_ACCOUNT:
        return null

      default:
        return state
    }
  },

  orgs = (state = {}, action)=>{
    switch(action.type){
      case FETCH_CURRENT_USER_SUCCESS:
      case LOGIN_SUCCESS:
      case REGISTER_SUCCESS:
      case CREATE_ORG_SUCCESS:
      case ACCEPT_INVITE_SUCCESS:
      case SELECT_ACCOUNT_SUCCESS:
        return indexById(action.payload.orgs)

      case LOAD_INVITE_API_SUCCESS:
        return indexById([action.payload.org])

      case FETCH_CURRENT_USER_UPDATES_API_SUCCESS:
        if (action.meta && action.meta.noMinUpdatedAt){
          return action.payload.orgs ? indexById(action.payload.orgs) : state
        } else {
          return action.payload.orgs && action.payload.orgs.length ? {...state, ...indexById(action.payload.orgs)} : state
        }

      case BILLING_UPDATE_CARD_SUCCESS:
      case BILLING_UPDATE_SUBSCRIPTION_SUCCESS:
        return R.assoc(action.payload.id, action.payload, state)

      case RENAME_OBJECT_SUCCESS:
        if (action.meta.objectType == "org"){<commit_msg>fix for org settings not refreshing after successful update<commit_after>import {
  SELECT_ORG,
  SELECT_ACCOUNT,
  SELECT_ACCOUNT_SUCCESS,
  FETCH_CURRENT_USER_SUCCESS,
  LOGIN,
  LOGIN_REQUEST,
  LOGIN_SUCCESS,
  REGISTER,
  REGISTER_SUCCESS,
  CREATE_ORG_REQUEST,
  CREATE_ORG_SUCCESS,
  CREATE_ORG_FAILED,
  LOGOUT,
  ORG_INVALID,
  LOAD_INVITE_API_SUCCESS,
  ACCEPT_INVITE_SUCCESS,
  RENAME_OBJECT_SUCCESS,
  BILLING_UPGRADE_SUBSCRIPTION,
  BILLING_OPEN_STRIPE_FORM,
  BILLING_STRIPE_FORM_SUBMITTED,
  BILLING_STRIPE_FORM_CLOSED,
  BILLING_UPDATE_SUBSCRIPTION_REQUEST,
  BILLING_UPDATE_SUBSCRIPTION_SUCCESS,
  BILLING_UPDATE_SUBSCRIPTION_FAILED,
  BILLING_UPDATE_CARD_REQUEST,
  BILLING_UPDATE_CARD_SUCCESS,
  BILLING_UPDATE_CARD_FAILED,
  FETCH_CURRENT_USER_UPDATES_API_SUCCESS,
  UPDATE_ORG_OWNER_REQUEST,
  UPDATE_ORG_OWNER_SUCCESS,
  UPDATE_ORG_OWNER_FAILED,
  BILLING_FETCH_INVOICE_LIST_REQUEST,
  BILLING_FETCH_INVOICE_LIST_SUCCESS,
  BILLING_FETCH_INVOICE_LIST_FAILED,
  BILLING_FETCH_INVOICE_PDF,
  BILLING_FETCH_INVOICE_PDF_SUCCESS,
  BILLING_FETCH_INVOICE_PDF_FAILED,
  BILLING_SAVE_INVOICE_PDF_SUCCESS,
  BILLING_SAVE_INVOICE_PDF_FAILED,
  UPDATE_OBJECT_SETTINGS_SUCCESS

} from "actions"
import R from 'ramda'
import {indexById} from './helpers'

export const
  currentOrgSlug = (state = null, action)=>{
    switch(action.type){
      case SELECT_ORG:
        return action.payload

      case LOAD_INVITE_API_SUCCESS:
        return action.payload.org.slug

      case REGISTER_SUCCESS:
      case CREATE_ORG_SUCCESS:
        let orgs = action.payload.orgs
        return orgs[orgs.length - 1].slug

      case ACCEPT_INVITE_SUCCESS:
        return action.meta.orgSlug

      case LOGIN:
      case LOGIN_REQUEST:
      case REGISTER:
      case LOGOUT:
      case ORG_INVALID:
      case SELECT_ACCOUNT:
        return null

      default:
        return state
    }
  },

  orgs = (state = {}, action)=>{
    switch(action.type){
      case FETCH_CURRENT_USER_SUCCESS:
      case LOGIN_SUCCESS:
      case REGISTER_SUCCESS:
      case CREATE_ORG_SUCCESS:
      case ACCEPT_INVITE_SUCCESS:
      case SELECT_ACCOUNT_SUCCESS:
        return indexById(action.payload.orgs)

      case LOAD_INVITE_API_SUCCESS:
        return indexById([action.payload.org])

      case FETCH_CURRENT_USER_UPDATES_API_SUCCESS:
        if (action.meta && action.meta.noMinUpdatedAt){
          return action.payload.orgs ? indexById(action.payload.orgs) : state
        } else {
          return action.payload.orgs && action.payload.orgs.length ? {...state, ...indexById(action.payload.orgs)} : state
        }

      case BILLING_UPDATE_CARD_SUCCESS:
      case BILLING_UPDATE_SUBSCRIPTION_SUCCESS:
        return R.assoc(action.payload.id, action.payload, state)

      case RENAME_OBJECT_SUCCESS:
      case UPDATE_OBJECT_SETTINGS_SUCCESS:
        if (action.meta.objectType == "org"){
{'fraction_non_alphanumeric': 0.06651335574031488, 'fraction_numerical': 0.0003537944454272068, 'mean_word_length': 3.7116666666666664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2127123', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2025, 'n_words': 304}