Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update QuotaAlert design by exposing QuotaPaywall
- Loading branch information
Showing
4 changed files
with
37 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,18 @@ | ||
import React from 'react' | ||
import get from 'lodash/get' | ||
|
||
import { useClient } from 'cozy-client' | ||
import { isMobileApp } from 'cozy-device-helper' | ||
import createDepreciationLogger from '../../helpers/createDepreciationLogger' | ||
import { QuotaPaywall } from '../../Paywall' | ||
|
||
import { Dialog } from '../../CozyDialogs' | ||
import Button from '../Button' | ||
|
||
import useInstance from '../../helpers/useInstance' | ||
|
||
import withLocales from '../../I18n/withLocales' | ||
import en from './locales/en.json' | ||
import fr from './locales/fr.json' | ||
|
||
const locales = { | ||
en, | ||
fr | ||
} | ||
|
||
const buildPremiumLink = (uuid, managerUrl) => | ||
`${managerUrl}/cozy/instances/${uuid}/premium` | ||
|
||
const QuotaModalAlert = withLocales(locales)(({ t, onClose, instance }) => { | ||
const uuid = get(instance, 'instance.data.attributes.uuid') | ||
const managerUrl = get(instance, 'context.data.attributes.manager_url') | ||
return ( | ||
<Dialog | ||
open={true} | ||
title={t('quotaalert.title')} | ||
content={t('quotaalert.desc')} | ||
actions={ | ||
<> | ||
<Button | ||
theme="secondary" | ||
onClick={onClose} | ||
label={t('quotaalert.confirm')} | ||
/> | ||
{uuid && managerUrl && ( | ||
<Button | ||
theme="primary" | ||
label={t('quotaalert.increase')} | ||
onClick={() => | ||
window.open(buildPremiumLink(uuid, managerUrl), 'self') | ||
} | ||
/> | ||
)} | ||
</> | ||
} | ||
onClose={onClose} | ||
/> | ||
) | ||
}) | ||
const logDeprecatedComponent = createDepreciationLogger() | ||
|
||
/** | ||
* @deprecated This component is depreacated, please use [QuotaPaywall](#/Paywall) instead. | ||
*/ | ||
const QuotaAlert = ({ onClose }) => { | ||
const client = useClient() | ||
/** | ||
* We don't want to call useInstance if we are on | ||
* mobile since we don't want to create a link to the cozy manager | ||
* because Apple and Google have restricted policy about | ||
* making a link to an outside purchase. | ||
* | ||
* So no call, no instance info, no button | ||
*/ | ||
if (isMobileApp()) { | ||
return <QuotaModalAlert onClose={onClose} /> | ||
} | ||
// TODO: why is there a conditional hook here? | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const instanceInfo = useInstance(client) | ||
return <QuotaModalAlert instance={instanceInfo} onClose={onClose} /> | ||
logDeprecatedComponent( | ||
'QuotaAlert is now exported from the cozy-ui as QuotaPaywall. Please import the component from "cozy-ui/transpiled/react/Paywall"' | ||
) | ||
return <QuotaPaywall onClose={onClose} /> | ||
} | ||
|
||
export default QuotaAlert |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.