How to use the cozy-client.models.instance 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-bar / src / components / Settings / index.jsx View on Github external
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { compose } from 'redux'
import get from 'lodash/get'

import { translate } from 'cozy-ui/react/I18n'
import { Button } from 'cozy-ui/react/Button'
import { queryConnect } from 'cozy-client/dist'
import { models } from 'cozy-client'
let instanceModel = undefined
let hasAnOffer = undefined
let isFremiumFixed = undefined
if (models) {
  instanceModel = models.instance
  //TODO fallback from cozy-client
  isFremiumFixed = data => {
    const GB = 1000 * 1000 * 1000
    const PREMIUM_QUOTA = 50 * GB
    const quota = get(data, 'diskUsage.data.attributes.quota', false)
    return parseInt(quota) < PREMIUM_QUOTA
  }
  hasAnOffer = data => {
    return (
      !instanceModel.isSelfHosted(data) &&
      instanceModel.arePremiumLinksEnabled(data) &&
      instanceModel.getUuid(data) &&
      !isFremiumFixed(data)
    )
  }
}