Skip to content

Commit

Permalink
feat: Update QuotaAlert design by exposing QuotaPaywall
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Jul 12, 2023
1 parent 1263285 commit 8a11f9b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 118 deletions.
63 changes: 27 additions & 36 deletions react/deprecated/QuotaAlert/Readme.md
Expand Up @@ -3,47 +3,38 @@
The link to the manager is only displayed if there is a managerUrl
in the stack response

```jsx noeditor
```jsx
import QuotaAlert from "cozy-ui/transpiled/react/deprecated/QuotaAlert";
import { CozyProvider } from "cozy-client";
import { BreakpointsProvider } from "cozy-ui/transpiled/react/hooks/useBreakpoints";
import DemoProvider from 'cozy-ui/docs/components/DemoProvider'

<BreakpointsProvider>
<div>
const mockClient = {
getStackClient: () => ({
fetchJSON: (_, url) => {
let attributes = {}
if(url === '/settings/context') {
attributes = {
attributes: {
enable_premium_links: true,
manager_url: "http://mycozy.cloud",
}
}
} else if(url === '/settings/instance') {
attributes = {
attributes: { uuid: "1223" }
}
}

return Promise.resolve({ data: attributes })
}
})
};

<DemoProvider client={mockClient}>
<button onClick={() => setState({ modalOpened: !state.modalOpened })}>
Toggle modal
</button>

{state.modalOpened && (
<CozyProvider
client={{
getStackClient: () => ({
fetchJSON: () =>
Promise.resolve({
data: {
attributes: { uuid: "1223", manager_url: "http://mycozy.cloud" }
}
})
})
}}
>
<QuotaAlert onClose={() => setState({ modalOpened: false })} />
</CozyProvider>
<QuotaAlert onClose={() => setState({ modalOpened: false })} />
)}
</div>
</BreakpointsProvider>;
```

```jsx static
import QuotaAlert from "cozy-ui/transpiled/react/deprecated/QuotaAlert";

<div>
<button onClick={() => setState({ modalOpened: !state.modalOpened })}>
Toggle modal
</button>

{state.modalOpened && (
<QuotaAlert onClose={() => setState({ modalOpened: false })} />
)}
</div>;
</DemoProvider>
```
76 changes: 10 additions & 66 deletions react/deprecated/QuotaAlert/index.jsx
@@ -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
8 changes: 0 additions & 8 deletions react/deprecated/QuotaAlert/locales/en.json

This file was deleted.

8 changes: 0 additions & 8 deletions react/deprecated/QuotaAlert/locales/fr.json

This file was deleted.

0 comments on commit 8a11f9b

Please sign in to comment.