import { fetchTriggers as cozyClientFetchTriggers } from 'lib/redux-cozy-client'

export const DOCTYPE = 'io.cozy.triggers'

const triggersCollectionKey = 'triggers'

// CRUD action creators

export const fetchTriggers = () =>
  cozyClientFetchTriggers(triggersCollectionKey, ['client', 'konnector'])

// selectors
export const getKonnectorTriggers = (
  state,
  konnector,
  existingAccountIds = []
) => {
  return (
    (!!state.documents[DOCTYPE] &&
      Object.values(state.documents[DOCTYPE]).filter(trigger => {
        return (
          (trigger.worker === 'konnector' || trigger.worker === 'client') &&
          trigger.message &&
          trigger.message.konnector === konnector.slug &&
          trigger.message.account &&
          existingAccountIds.includes(trigger.message.account)
        )
      })) ||
    []
  )
}

export const getTrigger = (state, id) =>
  !!state.documents &&
  !!state.documents[DOCTYPE] &&
  state.documents[DOCTYPE][id]

@@ -544,70 +544,34 @@
     
-(trigger.worker === 'konnector' %7C%7C trigger.worker === 'client'
+isKonnectorTrigger(trigger
 ) &&
@@ -795,16 +795,130 @@
 %0A  )%0A%7D%0A%0A
+const isKonnectorTrigger = trigger =%3E %7B%0A  return trigger.worker === 'konnector' %7C%7C trigger.worker === 'client'%0A%7D%0A%0A
 export c

isKonnectorTrigger function