Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'Withdrawal' and 'Deducted' labels when referring to withdrawal deposits, to more accurately communicate the type of transaction that has occurred #9500

Merged
merged 29 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dda3707
Show paid withdrawals as 'Deducted' in deposit status chip
Jinksi Sep 27, 2024
ab2ac05
Show paid withdrawals as 'Deducted' in deposit detail screen status i…
Jinksi Sep 27, 2024
e0ae386
Fix imported dependency order to improve code quality
Jinksi Sep 27, 2024
2b345b7
Replace 'Deposit' with 'Withdrawal' on deposit details screen
Jinksi Sep 27, 2024
146eec5
Don't use 'deducted' status for deposit list advanced filters or queries
Jinksi Sep 27, 2024
ab764e3
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Sep 29, 2024
d3873ae
Rename `displayStatus` to `depositStatusLabels` to improve clarity
Jinksi Oct 1, 2024
e97d829
Add changelog entry
Jinksi Oct 1, 2024
ea76c62
Render advanced filter deposit status label as 'Paid / Deducted' to m…
Jinksi Oct 1, 2024
b1d8326
Add DepositOverview test case for withdrawal labels
Jinksi Oct 1, 2024
28fa3b5
Add a withdrawal test case to the DepositsOverview component tests
Jinksi Oct 1, 2024
7d1b4d1
Add a withdrawal test case to the deposits list snapshots
Jinksi Oct 1, 2024
2db4e34
Add a withdrawal test case to the transactions list snapshots
Jinksi Oct 1, 2024
bbd6e4e
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 1, 2024
cbbf62c
Simplify the deposit details heading `Deposit / Withdrawal transactio…
Jinksi Oct 2, 2024
6bdfbce
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 16, 2024
9f33dbb
Add "Type" column to payments overview recent deposits list
Jinksi Oct 17, 2024
95d44ac
Update snapshot for deposits overview
Jinksi Oct 17, 2024
8ea82da
Prefer inferred types to simplify code
Jinksi Oct 17, 2024
08fad5b
Change Paid / Deducted to Completed (paid/deducted)
Jinksi Oct 17, 2024
334a5c7
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 20, 2024
3473f80
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 28, 2024
cf6ab74
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 29, 2024
acf6ede
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 30, 2024
4a18b89
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Oct 31, 2024
bee6b8f
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Nov 3, 2024
e806f82
Revert "Add "Type" column to payments overview recent deposits list"
Jinksi Nov 5, 2024
6106fc1
Revert "Update snapshot for deposits overview"
Jinksi Nov 5, 2024
59b3c3c
Merge branch 'develop' into fix/7802-deposit-withdrawal-text-changes
Jinksi Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading