Skip to content

Commit

Permalink
ensure deposit schedule summary & tooltip (and surrounding markup) is…
Browse files Browse the repository at this point in the history
… only rendered when there is a valid schedule
  • Loading branch information
Rua Haszard committed Feb 28, 2024
1 parent 34288a9 commit 29979d0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
28 changes: 16 additions & 12 deletions client/components/deposits-overview/deposit-schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import HelpOutlineIcon from 'gridicons/dist/help-outline';
* Internal dependencies
*/
import { ClickTooltip } from 'components/tooltip';
import { getDepositMonthlyAnchorLabel } from 'wcpay/deposits/utils';
import {
hasAutomaticScheduledDeposits,
getDepositMonthlyAnchorLabel,
} from 'wcpay/deposits/utils';
import type * as AccountOverview from 'wcpay/types/account-overview';

interface DepositScheduleProps {
Expand Down Expand Up @@ -101,13 +104,18 @@ const DepositScheduleSummary: React.FC< DepositScheduleProps > = ( {
};

/**
* Renders a summary of the deposit schedule so merchant understands when they will get paid.
* Renders a summary of the deposit schedule & a tooltip so merchant understands when they will get paid.
*
* eg "Your deposits are dispatched automatically every day"
* If the merchant has no schedule configured, renders nothing.
*/
const DepositSchedule: React.FC< DepositScheduleProps > = ( {
depositsSchedule,
} ) => {
// Bail if the merchant is on manual or ad-hoc deposits.
if ( ! hasAutomaticScheduledDeposits( depositsSchedule.interval ) ) {
return null;
}

const nextDepositHelpContent = (
<>
{ __(
Expand Down Expand Up @@ -182,15 +190,11 @@ const DepositSchedule: React.FC< DepositScheduleProps > = ( {
return (
<>
<DepositScheduleSummary depositsSchedule={ depositsSchedule } />
{ [ 'daily', 'weekly', 'monthly' ].includes(
depositsSchedule.interval
) && (
<ClickTooltip
content={ nextDepositHelpContent }
buttonIcon={ <HelpOutlineIcon /> }
buttonLabel={ 'Deposit schedule tooltip' }
/>
) }
<ClickTooltip
content={ nextDepositHelpContent }
buttonIcon={ <HelpOutlineIcon /> }
buttonLabel={ 'Deposit schedule tooltip' }
/>
</>
);
};
Expand Down
6 changes: 5 additions & 1 deletion client/components/deposits-overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
NoFundsAvailableForDepositNotice,
SuspendedDepositNotice,
} from './deposit-notices';
import { hasAutomaticScheduledDeposits } from 'wcpay/deposits/utils';
import useRecentDeposits from './hooks';
import './style.scss';

Expand Down Expand Up @@ -68,6 +69,9 @@ const DepositsOverview: React.FC = () => {
! account?.deposits_blocked && hasCompletedWaitingPeriod;
// Only show the deposit history section if the page is finished loading and there are deposits. */ }
const hasRecentDeposits = ! isLoading && deposits?.length > 0 && !! account;
const hasScheduledDeposits = hasAutomaticScheduledDeposits(
account?.deposits_schedule?.interval
);

// Show a loading state if the page is still loading.
if ( isLoading ) {
Expand Down Expand Up @@ -113,7 +117,7 @@ const DepositsOverview: React.FC = () => {
</CardHeader>

{ /* Deposit schedule message */ }
{ isDepositsUnrestricted && !! account && (
{ isDepositsUnrestricted && !! account && hasScheduledDeposits && (
<CardBody className="wcpay-deposits-overview__schedule__container">
<DepositSchedule
depositsSchedule={ account.deposits_schedule }
Expand Down
9 changes: 6 additions & 3 deletions client/deposits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import DepositSchedule from 'components/deposits-overview/deposit-schedule';
import { useAllDepositsOverviews } from 'data';
import { useSettings } from 'wcpay/data';
import DepositsList from './list';
import { hasAutomaticScheduledDeposits } from 'wcpay/deposits/utils';

const useNextDepositNoticeState = () => {
const { updateOptions } = useDispatch( 'wc/admin/options' );
Expand Down Expand Up @@ -53,14 +54,16 @@ const NextDepositNotice: React.FC = () => {
const hasCompletedWaitingPeriod =
wcpaySettings.accountStatus.deposits?.completed_waiting_period;

const hasScheduledDeposits = hasAutomaticScheduledDeposits(
account?.deposits_schedule.interval
);

if (
! isDepositsUnrestricted ||
! hasCompletedWaitingPeriod ||
! account ||
isNextDepositNoticeDismissed ||
! [ 'daily', 'weekly', 'monthly' ].includes(
account.deposits_schedule.interval
)
! hasScheduledDeposits
) {
return null;
}
Expand Down
13 changes: 13 additions & 0 deletions client/deposits/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ export const getDepositMonthlyAnchorLabel = ( {
}
return label;
};

// Determine if the store/merchant has scheduled deposits configured.
export const hasAutomaticScheduledDeposits = (
depositsScheduleInterval: string | undefined
): boolean => {
if ( ! depositsScheduleInterval ) {
return false;
}

return [ 'daily', 'weekly', 'monthly' ].includes(
depositsScheduleInterval
);
};

0 comments on commit 29979d0

Please sign in to comment.