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

Payouts: Show bank reference key on payout details page #9886

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
33208a5
Add bank reference key to the deposit details header
Dec 5, 2024
98333d5
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 5, 2024
1939d4e
Add conditional
Dec 5, 2024
2d5a129
Changelog
Dec 5, 2024
e0f0dd6
CSS adjustments for mobile view
Dec 5, 2024
aea1f35
Css tweak
Dec 5, 2024
a935636
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 5, 2024
6386ab8
show n/a when ref key not available
Dec 6, 2024
3ace18a
Update test snapshots
Dec 6, 2024
d318c33
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 6, 2024
735fe94
Add copy button
Dec 6, 2024
e96ba95
Tweak appearance of button and snapshots
Dec 6, 2024
ed00ff5
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 6, 2024
d1339f9
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 6, 2024
292bfd9
Change Ref ID font to monospace
Dec 6, 2024
b503845
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
haszari Dec 9, 2024
8bda02c
CSS tweak
Dec 9, 2024
25b87b3
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 9, 2024
294a44d
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 11, 2024
34790c9
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 11, 2024
21b2e01
Move DepositDateItem to its own React FC
Dec 11, 2024
05ee6ca
WIP changes
Dec 11, 2024
4a4720a
Fix brackets
Dec 11, 2024
a159495
Update snapshots
Dec 11, 2024
aa7eb1b
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 12, 2024
af176bd
Simplify click handler
Dec 12, 2024
0d26f76
Move copy button to component
Dec 12, 2024
5c3c6aa
Add test and label prop
Dec 12, 2024
feb2746
Merge branch 'develop' into add/9878-bank-ref-key-payout-details
Dec 12, 2024
3b4bcc9
Use named exports as per TS guidelines
Dec 13, 2024
8a4f35e
Add comments for props
Dec 13, 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/add-9878-bank-ref-key-payout-details
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Show Bank reference key on top of the payout details page, whenever available.
90 changes: 72 additions & 18 deletions client/deposits/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* External dependencies
*/
import React from 'react';
import React, { useEffect } from 'react';
import { dateI18n } from '@wordpress/date';
import { __, sprintf } from '@wordpress/i18n';
import moment from 'moment';
Expand Down Expand Up @@ -70,7 +70,7 @@ interface SummaryItemProps {
label: string;
value: string | JSX.Element;
valueClass?: string | false;
detail?: string;
detail?: string | JSX.Element;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this align with the types for the component we are overriding (SummaryNumber from Woo core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original SummaryItemNumber ( child within the summary list ) , does not have a detail prop. It was introduced in the customized SummaryListItem for the Deposit Overview header.

Copy link
Contributor

@haszari haszari Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but I think we should avoid inheriting/overriding components like this. We risk depending on implementation details, so our plugin is sensitive to changes in Woo core.

Ideally we'd either:

  • Use components from Woo/upstream as is, with no customisations or overrides.
  • Implement our own self-contained components, with no dependencies.

}

/**
Expand Down Expand Up @@ -130,28 +130,82 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
depositDateLabel = __( 'Withdrawal date', 'woocommerce-payments' );
}

const depositDateItem = (
<SummaryItem
key="depositDate"
label={
`${ depositDateLabel }: ` +
dateI18n(
'M j, Y',
moment.utc( deposit.date ).toISOString(),
true // TODO Change call to gmdateI18n and remove this deprecated param once WP 5.4 support ends.
)
const DepositDateItem = () => {
useEffect( () => {
const copyButton = document.querySelector(
'.woopayments-copy-bank-reference-key'
);

if ( copyButton ) {
copyButton.addEventListener( 'click', () => {
const bankReferenceKey = document.querySelector(
'.woopayments-payout-bank-reference-key'
)?.textContent;

if ( bankReferenceKey ) {
navigator.clipboard.writeText( bankReferenceKey );

copyButton.classList.add( 'state--copied' );
setTimeout( () => {
copyButton.classList.remove( 'state--copied' );
}, 2000 );
}
} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we implement the copy button behaviour in a more React-idiomatic way, without using a side effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed this and used useEffect to track the state of the copy button click. Thanks for the guidance to align with the declarative way of doing things in React!

}
value={ <DepositStatusIndicator deposit={ deposit } /> }
detail={ deposit.bankAccount }
/>
);
}, [] );

return (
<SummaryItem
key="depositDate"
label={
`${ depositDateLabel }: ` +
dateI18n(
'M j, Y',
moment.utc( deposit.date ).toISOString(),
true // TODO Change call to gmdateI18n and remove this deprecated param once WP 5.4 support ends.
)
}
value={ <DepositStatusIndicator deposit={ deposit } /> }
detail={
<>
{ deposit.bankAccount }
<br />
Bank reference key:{ ' ' }
{ deposit.bank_reference_key ? (
<>
<span className="woopayments-payout-bank-reference-key">
{ deposit.bank_reference_key }
</span>
<button
type="button"
className="woopayments-copy-button-bank-reference-key"
aria-label={ __(
'Copy bank reference key to clipboard',
'woocommerce-payments'
) }
title={ __(
'Copy to clipboard',
'woocommerce-payments'
) }
>
<i></i>
</button>
</>
) : (
'N/A'
) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a custom component that encapsulates all this behaviour, e.g. PayoutBankDetails?

That component would take care of:

  • Rendering the bank account / payout destination (as before)
  • Rendering the bank ref, with a clickable button to copy
  • Handling the click on the bank ref & copying to clipboard
  • Setting state somewhere to show that the ref has been copied
  • Whatever is needed to look / behave like a SummaryNumber

Then, we could just render that component alongside all the others in the table header:

<SummaryList>
  <SummaryItem  />
  <SummaryItem  />
  <PayoutBankDetails />
</SummaryList>

Copy link
Contributor Author

@nagpai nagpai Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per discussion during our pair coding session:

  • If the component were to be built from scratch, it would be better to use a Card and add the design we need directly as a custom component here. The design requirement diverts quite a bit from the SummaryList + SummaryNumber / SummaryItem .
  • We will need to also check for behavior needed for conditional views like Instant Deposit and Withdrawals if we redesign
  • For the current PR the next best thing we could do is to move DepositDateItem as an independent component outside DepositOverview where it is currently nested in a complex way. This will make it simple, modular and more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haszari - We discussed adding a smooth transition during our pair coding session. We are currently using SVG as mask-image attribute on the same button. This attribute is not smooth animatable from what i checked. It is classified as discrete .

I checked a workaround of rendering separate icons and making them appear and disappear with transitions, but not sure if the added complexity was worth it. Hence have not indulged in the transition animation for now.

</>
}
/>
);
};

return (
<div className="wcpay-deposit-overview">
{ deposit.automatic ? (
<Card className="wcpay-deposit-automatic">
<ul>
{ depositDateItem }
{ DepositDateItem() }
<li className="wcpay-deposit-amount">
{ formatExplicitCurrency(
deposit.amount,
Expand All @@ -172,7 +226,7 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
}
>
{ () => [
depositDateItem,
DepositDateItem(),
<SummaryItem
key="depositAmount"
label={
Expand Down
64 changes: 64 additions & 0 deletions client/deposits/details/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,55 @@
font-size: 20px;
line-height: 28px;
}

.wcpay-summary__item-detail {
color: $dark-gray-500;

@include breakpoint( '<480px' ) {
word-wrap: break-word;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this useful at all screen sizes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup it is. Thanks for catching that. I will remove the media query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - 8bda02c !

}

.woopayments-payout-bank-reference-key {
font-family: monospace;
}

.woopayments-copy-button-bank-reference-key {
line-height: 1.2em;
display: inline-flex;
background: transparent;
border: none;
border-radius: 0;
vertical-align: middle;
font-weight: normal;
cursor: pointer;
color: inherit;
margin-left: 2px;
align-items: center;

i {
display: block;
width: 1.2em;
height: 1.2em;
mask-image: url( 'assets/images/icons/copy.svg?asset' );
mask-size: contain;
mask-repeat: no-repeat;
mask-position: center;
background-color: currentColor;

&:hover {
opacity: 0.7;
}

&:active {
transform: scale( 0.9 );
}
}

&.state--copied i {
mask-image: url( 'assets/images/icons/check-green.svg?asset' );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of css (and some React behaviour) for this little copy-to-clipboard button. Could we package it into a little component? The button is nicely general-purpose so is a good candidate for an abstraction.

Copy link
Contributor Author

@nagpai nagpai Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! I have moved the button to a separate component via 0d26f76 and 5c3c6aa

This will be certainly useful with the new design. Once it is approved, I can also suggest it to be used in the checkout from where I originally borrowed :D

}
}
}

.wcpay-deposit-fee {
Expand All @@ -52,13 +101,21 @@
margin: 0;
list-style-type: none;

@include breakpoint( '<660px' ) {
flex-direction: column;
}

.woocommerce-summary__item {
border-bottom: 0;
background-color: inherit;
color: inherit;
.woocommerce-summary__item-label:hover {
color: inherit;
}

@include breakpoint( '<660px' ) {
border-right: none;
}
}

.wcpay-deposit-amount {
Expand All @@ -67,6 +124,13 @@
text-align: right;
font-size: 36px;
line-height: 82px;

@include breakpoint( '<660px' ) {
padding: 24px;
line-height: 36px;
text-align: left;
border-top: 1px solid $studio-gray-5;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we tweaking for smaller (<660px) screens? Should we make that behaviour the default, and progressively enhance on larger screens (i.e. mobile first)?

Copy link
Contributor Author

@nagpai nagpai Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are making the font size smaller, making it left aligned and adding a border on top.

The layout by itself - overall is desktop first. The columns have a sideways scroll. My gut feel is that merchants would mostly use a tablet or a laptop to check WP admin. Hence would prefer keeping it as-is, but open to revisiting that! The padding property within the media query is redundant though, removed it - 8bda02c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are making the font size smaller, making it left aligned and adding a border on top.

Why? Ideally the style changes for smaller screens are minimal (so it's easy to maintain), this sounds like a lot! If you are adding different behaviour for different screen sizes I'd recommend including details in the PR description – I see you have a screenshot, but even better if you explain why the changes are needed.

Copy link
Contributor Author

@nagpai nagpai Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are adding different behaviour for different screen sizes I'd recommend including details in the PR description – I see you have a screenshot, but even better if you explain why the changes are needed.

I have added a note on why we are doing the CSS change, in the PR description

The PR also adds a few CSS fixes for mobile view. This is needed to change the alignment of the summary items as column, and adjust borders + text alignment for smaller screens < 660px .

}
}

Expand Down
12 changes: 12 additions & 0 deletions client/deposits/details/test/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ exports[`Deposit overview renders automatic payout correctly 1`] = `
class="wcpay-summary__item-detail"
>
MOCK BANK •••• 1234 (USD)
<br />
Bank reference key:

N/A
</div>
</div>
</li>
Expand Down Expand Up @@ -117,6 +121,10 @@ exports[`Deposit overview renders automatic withdrawal correctly 1`] = `
class="wcpay-summary__item-detail"
>
MOCK BANK •••• 1234 (USD)
<br />
Bank reference key:

N/A
</div>
</div>
</li>
Expand Down Expand Up @@ -195,6 +203,10 @@ exports[`Deposit overview renders instant deposit correctly 1`] = `
class="wcpay-summary__item-detail"
>
MOCK BANK •••• 1234 (USD)
<br />
Bank reference key:

N/A
</div>
</div>
</li>
Expand Down
Loading