Skip to content

Commit

Permalink
Use 'Withdrawal' and 'Deducted' labels when referring to withdrawal d…
Browse files Browse the repository at this point in the history
…eposits, to more accurately communicate the type of transaction that has occurred (#9500)
  • Loading branch information
Jinksi authored Nov 6, 2024
1 parent d741c61 commit c061a08
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 60 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-7802-deposit-withdrawal-text-changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Use 'Withdrawal' and 'Deducted' labels when referring to withdrawal deposits, to more accurately communicate the type of transaction that has occurred
20 changes: 12 additions & 8 deletions client/components/deposit-status-chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import * as React from 'react';
/**
* Internal dependencies
*/
import { displayStatus } from 'deposits/strings';
import Chip, { ChipType } from 'components/chip';
import type { DepositStatus } from 'wcpay/types/deposits';
import type { CachedDeposit, DepositStatus } from 'wcpay/types/deposits';
import { depositStatusLabels } from 'wcpay/deposits/strings';

/**
* Maps a DepositStatus to a ChipType.
Expand All @@ -23,13 +23,17 @@ const mappings: Record< DepositStatus, ChipType > = {

/**
* Renders a deposits status chip.
*
* @return {JSX.Element} Deposit status chip.
*/
const DepositStatusChip: React.FC< {
status: DepositStatus;
} > = ( { status } ): JSX.Element => (
<Chip type={ mappings[ status ] } message={ displayStatus[ status ] } />
);
deposit: Pick< CachedDeposit, 'status' | 'type' >;
} > = ( { deposit } ) => {
let message = depositStatusLabels[ deposit.status ];

// Withdrawals are displayed as 'Deducted' instead of 'Paid'.
if ( deposit.type === 'withdrawal' && deposit.status === 'paid' ) {
message = depositStatusLabels.deducted;
}
return <Chip type={ mappings[ deposit.status ] } message={ message } />;
};

export default DepositStatusChip;
18 changes: 14 additions & 4 deletions client/components/deposit-status-chip/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ import DepositStatusChip from '..';

describe( 'Deposits status chip renders', () => {
test( 'Renders "Pending" status chip.', () => {
const { getByText } = render( <DepositStatusChip status="pending" /> );
const { getByText } = render(
<DepositStatusChip
deposit={ { type: 'deposit', status: 'pending' } }
/>
);
expect( getByText( 'Pending' ) ).toBeTruthy();
} );

test( 'Renders "Paid" status chip.', () => {
const { getByText } = render( <DepositStatusChip status="paid" /> );
expect( getByText( 'Paid' ) ).toBeTruthy();
const { getByText } = render(
<DepositStatusChip
deposit={ { type: 'deposit', status: 'paid' } }
/>
);
expect( getByText( 'Completed (paid)' ) ).toBeTruthy();
} );

test( 'Renders "In transit" status chip.', () => {
const { getByText } = render(
<DepositStatusChip status="in_transit" />
<DepositStatusChip
deposit={ { type: 'deposit', status: 'in_transit' } }
/>
);
expect( getByText( 'In transit' ) ).toBeTruthy();
} );
Expand Down
3 changes: 1 addition & 2 deletions client/components/deposits-overview/recent-deposits-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '@wordpress/components';
import { calendar } from '@wordpress/icons';
import { Link } from '@woocommerce/components';
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -51,7 +50,7 @@ const RecentDepositsList: React.FC< RecentDepositsProps > = ( {
</Link>
</FlexItem>
<FlexItem className={ `${ tableClass }__cell` }>
<DepositStatusChip status={ deposit.status } />
<DepositStatusChip deposit={ deposit } />
</FlexItem>
<FlexItem className={ `${ tableClass }__cell` }>
{ formatCurrency( deposit.amount, deposit.currency ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ exports[`Deposits Overview information Component Renders 1`] = `
<span
class="chip chip-success"
>
Paid
Completed (paid)
</span>
</div>
<div
Expand Down Expand Up @@ -334,6 +334,54 @@ exports[`Deposits Overview information Component Renders 1`] = `
$30.00
</div>
</div>
<div
class="components-flex wcpay-deposits-overview__table__row css-1giw1wa-View-Flex-sx-Base-sx-Items-ItemsRow em57xhy0"
data-wp-c16t="true"
data-wp-component="Flex"
>
<div
class="components-flex-item wcpay-deposits-overview__table__cell css-mw3lhz-View-Item-sx-Base em57xhy0"
data-wp-c16t="true"
data-wp-component="FlexItem"
>
<svg
aria-hidden="true"
focusable="false"
height="17"
viewBox="0 0 24 24"
width="17"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"
/>
</svg>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdeposits%2Fdetails&id=po_mock3"
>
January 4, 2020
</a>
</div>
<div
class="components-flex-item wcpay-deposits-overview__table__cell css-mw3lhz-View-Item-sx-Base em57xhy0"
data-wp-c16t="true"
data-wp-component="FlexItem"
>
<span
class="chip chip-success"
>
Completed (deducted)
</span>
</div>
<div
class="components-flex-item wcpay-deposits-overview__table__cell css-mw3lhz-View-Item-sx-Base em57xhy0"
data-wp-c16t="true"
data-wp-component="FlexItem"
>
$40.00
</div>
</div>
</div>
<div
class="components-flex components-card__footer components-card-footer wcpay-deposits-overview__footer css-p1v47q-View-Flex-sx-Base-sx-Items-ItemsRow-Footer-borderRadius-borderColor-medium em57xhy0"
Expand Down
9 changes: 9 additions & 0 deletions client/components/deposits-overview/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ const mockDeposits = [
bankAccount: 'MOCK BANK •••• 1234 (USD)',
currency: 'USD',
} as CachedDeposit,
{
id: 'po_mock3',
date: '2020-01-04 17:46:02',
type: 'withdrawal',
amount: 4000,
status: 'paid',
bankAccount: 'MOCK BANK •••• 1234 (USD)',
currency: 'USD',
} as CachedDeposit,
];

// Creates a mock Overview object for the given currency code and balance amounts.
Expand Down
78 changes: 61 additions & 17 deletions client/deposits/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,32 @@ import {
formatCurrency,
formatExplicitCurrency,
} from 'multi-currency/interface/functions';
import { displayStatus } from '../strings';
import { depositStatusLabels } from '../strings';
import './style.scss';

/**
* Renders the deposit status indicator UI, re-purposing the OrderStatus component from @woocommerce/components.
*/
const Status: React.FC< { status: string } > = ( { status } ) => (
<OrderStatus order={ { status } } orderStatusMap={ displayStatus } />
);
const DepositStatusIndicator: React.FC< {
deposit: Pick< CachedDeposit, 'status' | 'type' >;
} > = ( { deposit } ) => {
let displayStatusMap = depositStatusLabels;

// Withdrawals are displayed as 'Deducted' instead of 'Paid' when the status is 'paid'.
if ( deposit.type === 'withdrawal' ) {
displayStatusMap = {
...displayStatusMap,
paid: displayStatusMap.deducted,
};
}

return (
<OrderStatus
order={ { status: deposit.status } }
orderStatusMap={ displayStatusMap }
/>
);
};

interface SummaryItemProps {
label: string;
Expand Down Expand Up @@ -102,9 +119,15 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
);
}

const depositDateLabel = deposit.automatic
? __( 'Deposit date', 'woocommerce-payments' )
: __( 'Instant deposit date', 'woocommerce-payments' );
const isWithdrawal = deposit.type === 'withdrawal';

let depositDateLabel = __( 'Deposit date', 'woocommerce-payments' );
if ( ! deposit.automatic ) {
depositDateLabel = __( 'Instant deposit date', 'woocommerce-payments' );
}
if ( isWithdrawal ) {
depositDateLabel = __( 'Withdrawal date', 'woocommerce-payments' );
}

const depositDateItem = (
<SummaryItem
Expand All @@ -117,7 +140,7 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
true // TODO Change call to gmdateI18n and remove this deprecated param once WP 5.4 support ends.
)
}
value={ <Status status={ deposit.status } /> }
value={ <DepositStatusIndicator deposit={ deposit } /> }
detail={ deposit.bankAccount }
/>
);
Expand All @@ -138,16 +161,30 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
</Card>
) : (
<SummaryList
label={ __( 'Deposit overview', 'woocommerce-payments' ) }
label={
isWithdrawal
? __(
'Withdrawal overview',
'woocommerce-payments'
)
: __( 'Deposit overview', 'woocommerce-payments' )
}
>
{ () => [
depositDateItem,
<SummaryItem
key="depositAmount"
label={ __(
'Deposit amount',
'woocommerce-payments'
) }
label={
isWithdrawal
? __(
'Withdrawal amount',
'woocommerce-payments'
)
: __(
'Deposit amount',
'woocommerce-payments'
)
}
value={ formatExplicitCurrency(
deposit.amount + deposit.fee,
deposit.currency
Expand All @@ -170,10 +207,17 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
/>,
<SummaryItem
key="netDepositAmount"
label={ __(
'Net deposit amount',
'woocommerce-payments'
) }
label={
isWithdrawal
? __(
'Net withdrawal amount',
'woocommerce-payments'
)
: __(
'Net deposit amount',
'woocommerce-payments'
)
}
value={ formatExplicitCurrency(
deposit.amount,
deposit.currency
Expand Down
76 changes: 74 additions & 2 deletions client/deposits/details/test/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`Deposit overview renders automatic deposit correctly 1`] = `
<span
class="woocommerce-order-status__indicator is-paid"
/>
Paid
Completed (paid)
</div>
</div>
</div>
Expand Down Expand Up @@ -72,6 +72,78 @@ exports[`Deposit overview renders automatic deposit correctly 1`] = `
</div>
`;

exports[`Deposit overview renders automatic withdrawal correctly 1`] = `
<div>
<div
class="wcpay-deposit-overview"
>
<div
class="components-surface components-card wcpay-deposit-automatic css-nsno0f-View-Surface-getBorders-primary-Card-rounded em57xhy0"
data-wp-c16t="true"
data-wp-component="Card"
>
<div
class="css-mgwsf4-View-Content em57xhy0"
>
<ul>
<li
class="woocommerce-summary__item-container"
>
<div
class="woocommerce-summary__item"
>
<div
class="woocommerce-summary__item-label"
>
Withdrawal date: Jan 2, 2020
</div>
<div
class="woocommerce-summary__item-data"
>
<div
class="woocommerce-summary__item-value"
>
<div
class="woocommerce-order-status"
>
<span
class="woocommerce-order-status__indicator is-paid"
/>
Completed (deducted)
</div>
</div>
</div>
<div
class="wcpay-summary__item-detail"
>
MOCK BANK •••• 1234 (USD)
</div>
</div>
</li>
<li
class="wcpay-deposit-amount"
>
-$20.00
</li>
</ul>
</div>
<div
aria-hidden="true"
class="components-elevation css-91yjwm-View-Elevation-sx-Base-elevationClassName em57xhy0"
data-wp-c16t="true"
data-wp-component="Elevation"
/>
<div
aria-hidden="true"
class="components-elevation css-91yjwm-View-Elevation-sx-Base-elevationClassName em57xhy0"
data-wp-c16t="true"
data-wp-component="Elevation"
/>
</div>
</div>
</div>
`;

exports[`Deposit overview renders instant deposit correctly 1`] = `
<div>
<div
Expand Down Expand Up @@ -115,7 +187,7 @@ exports[`Deposit overview renders instant deposit correctly 1`] = `
<span
class="woocommerce-order-status__indicator is-paid"
/>
Paid
Completed (paid)
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit c061a08

Please sign in to comment.