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

Reorganise payments overview currency switcher, welcome message and balances card #8791

Merged
merged 63 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
fcbcfaf
Separate welcome message from account balance card
Jinksi May 7, 2024
85826b1
Remove WooPayments logo from welcome message
Jinksi May 7, 2024
5a91ee3
Update Welcome Message styles
Jinksi May 7, 2024
f3a4e01
Show currency select in welcome message
Jinksi May 7, 2024
57ec77c
Refactor Account Balance Card to show selected currency without tabs
Jinksi May 7, 2024
e5f006b
Refactor Account Balance Card to show selected currency without tabs
Jinksi May 7, 2024
814b12c
Merge branch 'develop' into update/8765-payments-overview-currency-se…
Jinksi May 21, 2024
b93a423
Show currency symbol in select component
Jinksi May 21, 2024
612254c
Initial CustomSelectControl fork and styling
Jinksi Jun 3, 2024
dc153aa
Ensure custom-select-control styles are inherited
Jinksi Jun 3, 2024
1ac7c43
Update comment to mention the forked-from CustomSelectControl
Jinksi Jun 3, 2024
ab51a06
Show optional hints
Jinksi Jun 3, 2024
7ef73bd
Update hint styles
Jinksi Jun 4, 2024
af32550
Close dropdown by default
Jinksi Jun 4, 2024
008f406
Remove menu item borders
Jinksi Jun 4, 2024
1c0826c
update hover/focus bg color
Jinksi Jun 4, 2024
756b9ce
Merge branch 'develop' into update/8765-payments-overview-currency-se…
Jinksi Jun 4, 2024
b5dd1ce
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
Jinksi Jun 4, 2024
1f36782
Adjust border and focus shadow to match design
Jinksi Jun 4, 2024
e173789
Ensure label doesn't wrap
Jinksi Jun 4, 2024
3063ae8
Add more code comments
Jinksi Jun 4, 2024
e199140
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 4, 2024
e2fb316
Use new FilterSelectControl component
Jinksi Jun 4, 2024
56cc950
Update code comment
Jinksi Jun 4, 2024
ad173ea
Show only currency code if code and symbol are identical
Jinksi Jun 4, 2024
f18110e
Update list item padding and border radius to match design
Jinksi Jun 4, 2024
b23f8f4
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 4, 2024
6495acc
Update snapshot test to match changes
Jinksi Jun 4, 2024
92dd922
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
Jinksi Jun 4, 2024
64229a7
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 4, 2024
3bb71e2
Update AccountBalances tests
Jinksi Jun 4, 2024
b22ce05
Remove redundant util function `getCurrencyTabTitle`
Jinksi Jun 4, 2024
97e1958
AccountBalances tests: remove redundant jest.mock
Jinksi Jun 4, 2024
f0e8fcc
Add changelog entry
Jinksi Jun 4, 2024
c923579
Update FilterSelectControl tests
Jinksi Jun 4, 2024
b56b86b
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
Jinksi Jun 4, 2024
6ae3e0e
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 4, 2024
dfb81a7
Select the default currency if invalid/undefined
Jinksi Jun 4, 2024
70b2899
Rename `Props` → `ControlProps` to remain consistent with `CustomSele…
Jinksi Jun 5, 2024
00940a3
Rename `Item`/`ItemType` → `SelectItem`/`SelectItemType` to clarify m…
Jinksi Jun 5, 2024
35a907b
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 5, 2024
bb70ee7
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
jessy-p Jun 5, 2024
35a72ff
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
jessy-p Jun 5, 2024
3a120e5
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
jessy-p Jun 5, 2024
28715a3
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
Jinksi Jun 5, 2024
a83058f
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 5, 2024
d4cf6a1
Remove additional border from the Account Balances card
Jinksi Jun 5, 2024
e4f7609
Move default currency selection to separate react hook
Jinksi Jun 6, 2024
659499b
Move `CurrencySelect` to an individual tsx file to improve readability
Jinksi Jun 6, 2024
692fdfc
Use `depositCurrencies` prop name to clarify expected value
Jinksi Jun 6, 2024
d8d40f6
Add tests for Currency Select
Jinksi Jun 6, 2024
504d862
Avoid double-negative condition to improve readability
Jinksi Jun 6, 2024
b0ce32e
Record tracks event on currency select
Jinksi Jun 6, 2024
8146208
Add changelog entry
Jinksi Jun 6, 2024
a19f745
Merge branch 'develop' into add/8788-select-component-for-currency-sw…
Jinksi Jun 6, 2024
c84c9a5
Rename to `InlineLabelSelect` to clarify what component is and differ…
Jinksi Jun 7, 2024
050d4a8
Merge branch 'add/8788-select-component-for-currency-switcher' into u…
Jinksi Jun 7, 2024
a32f931
Update to new naming of select component `InlineLabelSelect`
Jinksi Jun 7, 2024
8638176
Add tracks event suffix `_change` to clarify user intent
Jinksi Jun 7, 2024
379549c
Merge branch 'develop' into update/8765-payments-overview-currency-se…
Jinksi Jun 7, 2024
c6da1bf
update PW e2e test to reflect removal of WooPayments logo
Jinksi Jun 7, 2024
be6e613
Improve welcome/currency select layout on mobile viewport
Jinksi Jun 7, 2024
3cfe037
Encapsulate AccountBalances in an error boundary to limit failure to …
Jinksi Jun 7, 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/update-8765-payments-overview-currency-select
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Update the Payments Overview screen with a new currency selection UI for stores with multiple deposit currencies
200 changes: 69 additions & 131 deletions client/components/account-balances/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,114 +2,69 @@
* External dependencies
*/
import * as React from 'react';
import { Flex, TabPanel } from '@wordpress/components';
import { Flex } from '@wordpress/components';

/**
* Internal dependencies
*/
import { useAllDepositsOverviews } from 'wcpay/data';
import { useSelectedCurrency } from 'wcpay/overview/hooks';
import { getCurrencyTabTitle } from './utils';
import BalanceBlock from './balance-block';
import {
TotalBalanceTooltip,
AvailableBalanceTooltip,
} from './balance-tooltip';
import { fundLabelStrings } from './strings';
import InstantDepositButton from 'deposits/instant-deposits';
import { recordEvent } from 'tracks';
import type * as AccountOverview from 'wcpay/types/account-overview';
import './style.scss';

/**
* BalanceTabProps
*
* @typedef {Object} BalanceTab
*
* @param {string} name Name of the tab.
* @param {string} title Title of the tab.
* @param {string} currencyCode Currency code of the tab.
* @param {number} availableFunds Available funds of the tab.
* @param {number} pendingFunds Pending funds of the tab.
* @param {number} delayDays The account's pending period in days.
*/
type BalanceTabProps = {
name: string;
title: string;
currencyCode: string;
availableFunds: number;
pendingFunds: number;
delayDays: number;
instantBalance?: AccountOverview.InstantBalance;
};

/**
* Renders an account balances panel with tab navigation for each deposit currency.
*
* @return {JSX.Element} Rendered balances panel with tab navigation for each currency.
* Renders account balances for the selected currency.
*/
const AccountBalances: React.FC = () => {
const { overviews, isLoading } = useAllDepositsOverviews();
const { selectedCurrency, setSelectedCurrency } = useSelectedCurrency();
const { selectedCurrency } = useSelectedCurrency();

if ( ! isLoading && overviews.currencies.length === 0 ) {
return null;
}

const onTabSelect = ( tabName: BalanceTabProps[ 'name' ] ) => {
setSelectedCurrency( tabName );
recordEvent( 'wcpay_overview_balances_currency_tab_click', {
selected_currency: tabName,
} );
};

if ( isLoading ) {
// While the data is loading, we show a loading currency tab.
const loadingTabs: BalanceTabProps[] = [
{
name: 'loading',
title: getCurrencyTabTitle(
wcpaySettings.accountDefaultCurrency
),
currencyCode: wcpaySettings.accountDefaultCurrency,
availableFunds: 0,
pendingFunds: 0,
delayDays: 0,
},
];
// While the data is loading, we show a loading state for the balances.
const loadingData = {
name: 'loading',
currencyCode: wcpaySettings.accountDefaultCurrency,
availableFunds: 0,
pendingFunds: 0,
delayDays: 0,
};

return (
<TabPanel tabs={ loadingTabs }>
{ ( tab: BalanceTabProps ) => (
<Flex
gap={ 0 }
className="wcpay-account-balances__balances"
>
<BalanceBlock
id={ `wcpay-account-balances-${ tab.currencyCode }-total` }
title={ fundLabelStrings.total }
amount={ 0 }
currencyCode={ tab.currencyCode }
isLoading
/>
<BalanceBlock
id={ `wcpay-account-balances-${ tab.currencyCode }-available` }
title={ fundLabelStrings.available }
amount={ 0 }
currencyCode={ tab.currencyCode }
isLoading
/>
</Flex>
) }
</TabPanel>
<Flex gap={ 0 } className="wcpay-account-balances__balances">
<BalanceBlock
id={ `wcpay-account-balances-${ loadingData.currencyCode }-total` }
title={ fundLabelStrings.total }
amount={ 0 }
currencyCode={ loadingData.currencyCode }
isLoading
/>
<BalanceBlock
id={ `wcpay-account-balances-${ loadingData.currencyCode }-available` }
title={ fundLabelStrings.available }
amount={ 0 }
currencyCode={ loadingData.currencyCode }
isLoading
/>
</Flex>
);
}

const { currencies, account } = overviews;

const depositCurrencyTabs = currencies.map(
const depositCurrencyOverviews = currencies.map(
( overview: AccountOverview.Overview ) => ( {
name: overview.currency,
title: getCurrencyTabTitle( overview.currency ),
currencyCode: overview.currency,
availableFunds: overview.available?.amount ?? 0,
pendingFunds: overview.pending?.amount ?? 0,
Expand All @@ -118,65 +73,48 @@ const AccountBalances: React.FC = () => {
} )
);

// Selected currency is not valid if it is not in the list of deposit currencies.
const isSelectedCurrencyValid =
selectedCurrency &&
depositCurrencyTabs.some( ( tab ) => tab.name === selectedCurrency );
const selectedOverview =
depositCurrencyOverviews.find(
( overview ) => overview.name === selectedCurrency
) || depositCurrencyOverviews[ 0 ];

return (
<TabPanel
tabs={ depositCurrencyTabs }
onSelect={ onTabSelect }
initialTabName={
isSelectedCurrencyValid ? selectedCurrency : undefined
}
>
{ ( tab: BalanceTabProps ) => {
const totalBalance = tab.availableFunds + tab.pendingFunds;
const totalBalance =
selectedOverview.availableFunds + selectedOverview.pendingFunds;

return (
<>
<Flex
gap={ 0 }
className="wcpay-account-balances__balances"
>
<BalanceBlock
id={ `wcpay-account-balances-${ tab.currencyCode }-total` }
title={ fundLabelStrings.total }
amount={ totalBalance }
currencyCode={ tab.currencyCode }
tooltip={
<TotalBalanceTooltip
balance={ totalBalance }
/>
}
/>
<BalanceBlock
id={ `wcpay-account-balances-${ tab.currencyCode }-available` }
title={ fundLabelStrings.available }
amount={ tab.availableFunds }
currencyCode={ tab.currencyCode }
tooltip={
<AvailableBalanceTooltip
balance={ tab.availableFunds }
/>
}
/>
</Flex>
{ tab.instantBalance && tab.instantBalance.amount > 0 && (
<Flex
gap={ 0 }
className="wcpay-account-balances__instant-deposit"
>
<InstantDepositButton
instantBalance={ tab.instantBalance }
/>
</Flex>
) }
</>
);
} }
</TabPanel>
return (
<>
<Flex gap={ 0 } className="wcpay-account-balances__balances">
<BalanceBlock
id={ `wcpay-account-balances-${ selectedOverview.currencyCode }-total` }
title={ fundLabelStrings.total }
amount={ totalBalance }
currencyCode={ selectedOverview.currencyCode }
tooltip={ <TotalBalanceTooltip balance={ totalBalance } /> }
/>
<BalanceBlock
id={ `wcpay-account-balances-${ selectedOverview.currencyCode }-available` }
title={ fundLabelStrings.available }
amount={ selectedOverview.availableFunds }
currencyCode={ selectedOverview.currencyCode }
tooltip={
<AvailableBalanceTooltip
balance={ selectedOverview.availableFunds }
/>
}
/>
</Flex>
{ selectedOverview.instantBalance &&
selectedOverview.instantBalance.amount > 0 && (
<Flex
gap={ 0 }
className="wcpay-account-balances__instant-deposit"
>
<InstantDepositButton
instantBalance={ selectedOverview.instantBalance }
/>
</Flex>
) }
</>
);
};

Expand Down
7 changes: 2 additions & 5 deletions client/components/account-balances/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.wcpay-account-balances__balances {
border-top: 1px solid $gray-200;
}

.wcpay-account-balances__balances > * + * {
border-left: 1px solid $gray-200;
}
Expand All @@ -21,14 +17,15 @@
&__amount {
font-weight: 500;
font-size: 20px;
line-height: 0px;
margin: 0;
color: $gray-900;
}
}

.wcpay-account-balances__balances__item__title {
display: flex;
align-items: center;
margin-top: 0;
}

.wcpay-account-balances__instant-deposit {
Expand Down
Loading
Loading