Skip to content

Commit

Permalink
feat: Display My offer if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash-- committed Dec 9, 2019
1 parent 529d856 commit 3c6396c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/components/Settings/SettingsContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const SettingsContent = ({
isClaudyLoading,
toggleSupport,
shoulDisplayViewOfferButton,
managerUrlPremiumLink
managerUrlPremiumLink,
viewOfferButtonText
}) => (
<div className="coz-nav-pop-content">
{isDrawer && <hr />}
Expand Down Expand Up @@ -86,8 +87,8 @@ const SettingsContent = ({
role="menuitem"
className="coz-nav-settings-item-btn"
icon="cloud-happy"
title={t('view_offers')}
label={t('view_offers')}
title={viewOfferButtonText}
label={viewOfferButtonText}
href={managerUrlPremiumLink}
/>
</li>
Expand Down Expand Up @@ -138,6 +139,7 @@ SettingsContent.propTypes = {
onClaudy: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
isDrawer: PropTypes.bool,
isClaudyLoading: PropTypes.bool,
toggleSupport: PropTypes.func.isRequired
toggleSupport: PropTypes.func.isRequired,
viewOfferButtonText: PropTypes.string
}
export default translate()(SettingsContent)
29 changes: 28 additions & 1 deletion src/components/Settings/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
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)
)
}
}

import SettingsContent from 'components/Settings/SettingsContent'
Expand Down Expand Up @@ -80,6 +99,7 @@ export class Settings extends Component {
let shouldDisplayViewOfferButton = false
let managerUrlPremiumLink
let isFetchingFromQueries
let viewOfferButtonText = ''
const canCheckPremium = cozyClientCanCheckPremium()
if (canCheckPremium) {
isFetchingFromQueries = isFetchingQueries([
Expand All @@ -93,8 +113,14 @@ export class Settings extends Component {
diskUsage: diskUsageQuery,
instance: instanceQuery
}
shouldDisplayViewOfferButton =
instanceModel.shouldDisplayOffers(data) || hasAnOffer(data)

shouldDisplayViewOfferButton = instanceModel.shouldDisplayOffers(data)
if (shouldDisplayViewOfferButton && !hasAnOffer(data)) {
viewOfferButtonText = t('view_offers')
} else if (hasAnOffer(data)) {
viewOfferButtonText = t('view_my_offer')
}
managerUrlPremiumLink = instanceModel.buildPremiumLink(data)
}
}
Expand Down Expand Up @@ -145,6 +171,7 @@ export class Settings extends Component {
settingsAppURL={settingsAppURL}
shoulDisplayViewOfferButton={shouldDisplayViewOfferButton}
managerUrlPremiumLink={managerUrlPremiumLink}
viewOfferButtonText={viewOfferButtonText}
/>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"storage": "Storage",
"storage_phrase": "%{diskUsage} GB of %{diskQuota} GB used",
"view_offers": "View offers",
"view_my_offer": "My offer",
"help": "Help",
"logout": "Sign out",
"soon": "soon",
Expand Down

0 comments on commit 3c6396c

Please sign in to comment.