How to use the cozy-client.useClient function in cozy-client

To help you get started, we’ve selected a few cozy-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cozy / cozy.github.io / en / cozy-banks / src / ducks / recurrence / RecurrencePage.jsx View on Github external
const useDocument = (doctype, id) => {
  const client = useClient()
  return client.getDocumentFromState(doctype, id)
}
github cozy / cozy.github.io / en / cozy-banks / src / ducks / recurrence / RecurrencePage.jsx View on Github external
const BundleInfo = withRouter(({ bundle, router }) => {
  const { t } = useI18n()
  const client = useClient()
  const { isMobile } = useBreakpoints()
  if (!bundle) {
    return null
  }

  const [showingActionsMenu, showActionsMenu, hideActionsMenu] = useToggle(
    false
  )
  const [showingRename, showRename, hideRename] = useToggle(false)

  const goToRecurrenceRoot = useCallback(() => router.push('/recurrence'), [
    router
  ])

  const handleOpenRename = useCallback(() => {
    showRename()
github cozy / cozy.github.io / en / cozy-banks / src / ducks / transactions / TransactionCategoryEditor.jsx View on Github external
const TransactionCategoryEditor = props => {
  const client = useClient()
  const { transaction, beforeUpdate, afterUpdate, onCancel, modal } = props

  const handleSelect = async category => {
    if (beforeUpdate) {
      await beforeUpdate()
    }
    const newTransaction = await updateTransactionCategory(
      client,
      transaction,
      category
    )
    if (afterUpdate) {
      await afterUpdate(newTransaction)
    }
  }
github cozy / cozy.github.io / en / cozy-banks / src / ducks / recurrence / RecurrencePage.jsx View on Github external
const RenameBundleModal = ({ bundle, dismissAction }) => {
  const client = useClient()
  const { t } = useI18n()
  const renameInputRef = useRef()

  const handleRename = async () => {
    try {
      await renameRecurrenceManually(
        client,
        bundle,
        renameInputRef.current.value
      )
      dismissAction()
      Alerter.success(t('Recurrence.rename.save-success'))
    } catch (e) {
      Alerter.error(t('Recurrence.rename.save-error'))
    }
  }
github cozy / cozy.github.io / en / cozy-banks / src / ducks / transactions / TransactionRecurrenceEditor.jsx View on Github external
const TransactionRecurrenceEditor = ({
  transaction,
  beforeUpdate,
  afterUpdate
}) => {
  const { t } = useI18n()
  const client = useClient()

  const current = transaction.recurrence.data
  const currentId = current && current._id
  const recurrenceCol = useQuery(recurrenceConn.query, recurrenceConn)

  const { data: allRecurrences } = recurrenceCol

  const recurrenceOptions = useMemo(
    () =>
      allRecurrences
        ? [makeNewRecurrenceOption(t)].concat(
            allRecurrences.map(makeOptionFromRecurrence)
          )
        : null,
    [allRecurrences, t]
  )
github cozy / cozy.github.io / en / cozy-banks / src / ducks / recurrence / DebugRecurrencePage.jsx View on Github external
for (let day of days) {
      const newTransactionsOfDay = byDay[day]
      curBundles = updateRecurrences(bundles, newTransactionsOfDay, rules)
    }
    return curBundles
  }, [bundles, newTransactions, rules])

  const finalBundles = useMemo(() => {
    const filteredBundles = updatedBundles.filter(
      makeTextFilter(bundleFilter, bundle => bundle.ops[0].label)
    )
    const sortedBundles = sortBy(filteredBundles, bundle => bundle.ops[0].label)
    return sortedBundles
  }, [updatedBundles, bundleFilter])

  const client = useClient()

  const [savingBundles, setSavingBundles] = useState()
  const [resettingBundles, setResettingBundles] = useState()
  const handleSaveBundles = useCallback(
    async function() {
      setSavingBundles(true)
      try {
        await saveHydratedBundles(client, finalBundles)
      } catch (error) {
        Alerter.error(error.message)
      } finally {
        setSavingBundles(false)
      }
    },
    [finalBundles, client]
  )