Skip to content

Commit

Permalink
feat: Use Dialog for transfer state modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Nov 12, 2020
1 parent 5439f6a commit c4fdc6e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
17 changes: 10 additions & 7 deletions src/ducks/transfers/TransferPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { withRouter } from 'react-router'

import withBreakpoints from 'cozy-ui/transpiled/react/helpers/withBreakpoints'
import Stack from 'cozy-ui/transpiled/react/Stack'
import { translate, Text, Modal, useI18n } from 'cozy-ui/transpiled/react'
import { translate, Text, useI18n } from 'cozy-ui/transpiled/react'
import {
withClient,
queryConnect,
Expand All @@ -30,8 +30,8 @@ import * as recipientUtils from 'ducks/transfers/recipients'
import * as transfers from 'ducks/transfers/transfers'

import {
TransferSuccess,
TransferError
TransferSuccessDialog,
TransferErrorDialog
} from 'ducks/transfers/steps/TransferState'
import ChooseRecipientCategory from 'ducks/transfers/steps/Category'
import ChooseBeneficiary from 'ducks/transfers/steps/Beneficiary'
Expand Down Expand Up @@ -467,15 +467,18 @@ class TransferPage extends React.Component {
return (
<>
{transferState ? (
<Modal mobileFullscreen dismissAction={this.handleModalDismiss}>
<>
{transferState === 'sending' && <Loading />}
{transferState === 'success' && (
<TransferSuccess onExit={this.handleExit} />
<TransferSuccessDialog onExit={this.handleExit} />
)}
{transferState instanceof Error && (
<TransferError error={transferState} onExit={this.handleExit} />
<TransferErrorDialog
error={transferState}
onExit={this.handleExit}
/>
)}
</Modal>
</>
) : null}
{showingPersonalInfo ? (
<PersonalInfoComponent
Expand Down
6 changes: 3 additions & 3 deletions src/ducks/transfers/TransferPage.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AppLike from 'test/AppLike'
import fixtures from 'test/fixtures'

import { accountsConn, recipientsConn, myselfConn } from 'doctypes'
import { TransferError } from 'ducks/transfers/steps/TransferState'
import { TransferErrorDialog } from 'ducks/transfers/steps/TransferState'
import TransferPage, { TransferPage as DumbTransferPage } from './TransferPage'

import * as transfers from './transfers'
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('transfer page', () => {
jest.restoreAllMocks()
})

it('should pass error to TransferError', async () => {
it('should pass error to TransferErrorDialog', async () => {
root.instance().setState({
senderAccount: accounts[0],
beneficiary: {
Expand All @@ -77,7 +77,7 @@ describe('transfer page', () => {
} catch (e) {
// eslint-disable-line no-empty
}
const errorView = root.find(TransferError)
const errorView = root.find(TransferErrorDialog)
expect(errorView.length).toBe(1)
expect(errorView.props().error).toBe(err)
})
Expand Down
55 changes: 33 additions & 22 deletions src/ducks/transfers/steps/TransferState.jsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
import React from 'react'
import Padded from 'components/Spacing/Padded'
import { Text, Button, useI18n } from 'cozy-ui/transpiled/react'
import Button from 'cozy-ui/transpiled/react/Button'
import Typography from 'cozy-ui/transpiled/react/Typography'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import { IllustrationDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
import Stack from 'cozy-ui/transpiled/react/Stack'

import styles from 'ducks/transfers/styles.styl'
import Title from 'ducks/transfers/steps/Title'
import TransferDoneImg from 'ducks/transfers/steps/TransferDoneImg'
import TransferErrorImg from 'ducks/transfers/steps/TransferErrorImg'
import { useTrackPage } from 'ducks/tracking/browser'

const TransferState = ({
const TransferStateDialog = ({
title,
description,
onClickPrimaryButton,
primaryLabel,
Img
}) => (
<Padded className={styles.TransferState}>
<Title className="u-mb-1-half">{title}</Title>
{Img}
<Text className="u-mb-1-half u-ta-center">{description}</Text>
<Button
extension="full"
className="u-mb-half"
onClick={onClickPrimaryButton}
label={primaryLabel}
/>
</Padded>
<IllustrationDialog
open
onClose={onClickPrimaryButton}
title={
<Stack spacing="m" className="u-ta-center">
{Img}
<Typography variant="h4">{title}</Typography>
</Stack>
}
content={description}
actions={
<Button
extension="full"
className="u-flex-grow-1"
onClick={onClickPrimaryButton}
label={primaryLabel}
/>
}
/>
)

export const TransferSuccess = React.memo(function TransferSuccess({ onExit }) {
export const DumbTransferSuccessDialog = ({ onExit }) => {
const { t } = useI18n()
useTrackPage('virements.succes')
return (
<TransferState
<TransferStateDialog
title={t('Transfer.success.title')}
Img={<TransferDoneImg />}
description={t('Transfer.success.description')}
onClickPrimaryButton={onExit}
primaryLabel={t('Transfer.exit')}
/>
)
})
}

export const TransferSuccessDialog = React.memo(DumbTransferSuccessDialog)

const defaultErrorPageName = 'impossible'
const konnectorErrorToPageName = {
Expand All @@ -51,14 +62,14 @@ const konnectorErrorToPageName = {
const isLoginFailed = error =>
error.message && error.message.includes('LOGIN_FAILED')

export const DumbTransferError = ({ onExit, error }) => {
export const DumbTransferErrorDialog = ({ onExit, error }) => {
const { t } = useI18n()
const loginFailed = isLoginFailed(error)
const pageName =
konnectorErrorToPageName[error.message] || defaultErrorPageName
useTrackPage(`virements.${pageName}`)
return (
<TransferState
<TransferStateDialog
title={t('Transfer.error.title')}
Img={<TransferErrorImg />}
description={
Expand All @@ -72,4 +83,4 @@ export const DumbTransferError = ({ onExit, error }) => {
)
}

export const TransferError = React.memo(DumbTransferError)
export const TransferErrorDialog = React.memo(DumbTransferErrorDialog)
6 changes: 0 additions & 6 deletions src/ducks/transfers/styles.styl

This file was deleted.

0 comments on commit c4fdc6e

Please sign in to comment.