-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ScanDesktopActionsAlert component
This component add an alert in Desktop mode to warn of the existence of the Cozy Cloud app. Allows you to install the app, via a QR Code or to hide this alert
- Loading branch information
Showing
11 changed files
with
296 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions
54
packages/cozy-mespapiers-lib/src/components/ModelSteps/Scan/ScanActions/QRCodeModal.jsx
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
import { IllustrationDialog } from 'cozy-ui/transpiled/react/CozyDialogs' | ||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
|
||
import QRCode from '../../../../assets/images/QRCode.png' | ||
import appStoreIcon from '../../../../assets/images/appstore.png' | ||
import playStoreIcon from '../../../../assets/images/playstore.png' | ||
import { ANDROID_APP_URL, IOS_APP_URL } from '../../../../constants/const' | ||
|
||
const QRCodeModal = ({ onClose }) => { | ||
const { t } = useI18n() | ||
|
||
return ( | ||
<IllustrationDialog | ||
open | ||
size="small" | ||
transitionDuration={0} | ||
disableGutters | ||
onClose={onClose} | ||
content={ | ||
<div | ||
className="u-flex u-flex-column u-flex-items-center u-flex-justify-center u-pt-3 u-pb-2 u-ph-1-half" | ||
data-testid="QRCodeModal" | ||
> | ||
<img src={QRCode} width="100%" alt="" aria-hidden /> | ||
<Typography gutterBottom variant="h3" color="textPrimary"> | ||
{t('QRCodeModal.title')} | ||
</Typography> | ||
<Typography | ||
color="textSecondary" | ||
className="u-ta-center" | ||
dangerouslySetInnerHTML={{ | ||
__html: t('QRCodeModal.text', { | ||
androidUrl: ANDROID_APP_URL, | ||
androidIconSrc: playStoreIcon, | ||
iosUrl: IOS_APP_URL, | ||
iosIconSrc: appStoreIcon | ||
}) | ||
}} | ||
/> | ||
</div> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
QRCodeModal.propTypes = { | ||
onClose: PropTypes.func | ||
} | ||
|
||
export default QRCodeModal |
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
60 changes: 60 additions & 0 deletions
60
...ozy-mespapiers-lib/src/components/ModelSteps/Scan/ScanActions/ScanDesktopActionsAlert.jsx
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import PropTypes from 'prop-types' | ||
import React, { useState } from 'react' | ||
|
||
import Alert from 'cozy-ui/transpiled/react/Alert' | ||
import AlertTitle from 'cozy-ui/transpiled/react/AlertTitle' | ||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
|
||
import QRCodeModal from './QRCodeModal' | ||
import IlluScanner from '../../../../assets/icons/IlluScanner.svg' | ||
|
||
const ScanDesktopActionsAlert = ({ onClose }) => { | ||
const [showQRCodeModal, setShowQRCodeModal] = useState(false) | ||
|
||
const { t } = useI18n() | ||
|
||
const handleInstallApp = () => { | ||
setShowQRCodeModal(true) | ||
} | ||
|
||
return ( | ||
<> | ||
<Alert | ||
block | ||
icon={<Icon icon={IlluScanner} size={96} />} | ||
action={ | ||
<> | ||
<Button | ||
component="a" | ||
onClick={onClose} | ||
variant="text" | ||
label={t('ScanDesktopActionsAlert.actions.hide')} | ||
/> | ||
<Button | ||
component="a" | ||
onClick={handleInstallApp} | ||
variant="text" | ||
label={t('ScanDesktopActionsAlert.actions.install')} | ||
/> | ||
</> | ||
} | ||
data-testid="ScanDesktopActionsAlert" | ||
> | ||
<AlertTitle>{t('ScanDesktopActionsAlert.title')}</AlertTitle> | ||
{t('ScanDesktopActionsAlert.text')} | ||
</Alert> | ||
|
||
{showQRCodeModal && ( | ||
<QRCodeModal onClose={() => setShowQRCodeModal(false)} /> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
ScanDesktopActionsAlert.propTypes = { | ||
onClose: PropTypes.func | ||
} | ||
|
||
export default ScanDesktopActionsAlert |
42 changes: 42 additions & 0 deletions
42
...espapiers-lib/src/components/ModelSteps/Scan/ScanActions/ScanDesktopActionsAlert.spec.jsx
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import ScanDesktopActionsAlert from './ScanDesktopActionsAlert' | ||
import AppLike from '../../../../../test/components/AppLike' | ||
|
||
jest.mock('cozy-client/dist/utils', () => ({ | ||
...jest.requireActual('cozy-client/dist/utils'), | ||
hasQueryBeenLoaded: jest.fn() | ||
})) | ||
|
||
const setup = ({ onCloseFn = jest.fn() } = {}) => { | ||
return render( | ||
<AppLike> | ||
<ScanDesktopActionsAlert onClose={onCloseFn} /> | ||
</AppLike> | ||
) | ||
} | ||
|
||
describe('ScanDesktopActionsAlert', () => { | ||
it('should display QRCodeModal modal when click on "Install the app" button', () => { | ||
const { getByText, getByTestId } = setup() | ||
const installAppButton = getByText('Install the app') | ||
|
||
fireEvent.click(installAppButton) | ||
|
||
const QRCodeModal = getByTestId('QRCodeModal') | ||
|
||
expect(QRCodeModal).toBeInTheDocument() | ||
}) | ||
|
||
it('should call client.save when click on "No, thanks" button', () => { | ||
const onCloseFn = jest.fn() | ||
const { getByText } = setup({ onCloseFn }) | ||
const hideButton = getByText('No, thanks') | ||
|
||
fireEvent.click(hideButton) | ||
|
||
expect(onCloseFn).toBeCalledTimes(1) | ||
}) | ||
}) |
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