Skip to content

Commit

Permalink
Simplify and improve our onboarding links and flows handling (#9105)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Mallory <[email protected]>
  • Loading branch information
vladolaru and dmallory42 authored Aug 8, 2024
1 parent ac6d1d8 commit 28a3248
Show file tree
Hide file tree
Showing 66 changed files with 4,251 additions and 1,095 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix onboarding redirect loop when starting from Woo Settings Payments.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../utils';
import { getTracksIdentity } from 'tracks';
import { getAppearance } from 'wcpay/checkout/upe-styles';
import getAppearanceType from 'wcpay/checkout/utils';
import { getAppearanceType } from 'wcpay/checkout/utils';

export const expressCheckoutIframe = async ( api, context, emailSelector ) => {
const woopayEmailInput = await getTargetElement( emailSelector );
Expand Down
37 changes: 10 additions & 27 deletions client/components/account-status/account-tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ import strings from './strings';
import './styles.scss';
import ResetAccountModal from 'wcpay/overview/modal/reset-account';
import { trackAccountReset } from 'wcpay/onboarding/tracking';
import { recordEvent } from 'wcpay/tracks';
import { isInDevMode } from 'wcpay/utils';

interface Props {
accountLink: string;
detailsSubmitted: boolean;
openModal: () => void;
}

const handleReset = () => {
trackAccountReset();

window.location.href = addQueryArgs( wcpaySettings.connectUrl, {
'wcpay-reset-account': true,
'wcpay-reset-account': 'true',
source: 'wcpay-reset-account', // Overwrite any existing source because we are starting over.
} );
};

export const AccountTools: React.FC< Props > = ( props: Props ) => {
const accountLink = addQueryArgs( props.accountLink, {
source: 'account-tools__finish-setup-button',
} );
const detailsSubmitted = props.detailsSubmitted;
export const AccountTools: React.FC< Props > = () => {
const [ modalVisible, setModalVisible ] = useState( false );

// Only render when in dev/sandbox mode.
if ( ! isInDevMode() ) {
return null;
}

return (
<>
<div className="account-tools">
Expand All @@ -43,25 +43,8 @@ export const AccountTools: React.FC< Props > = ( props: Props ) => {
<p>{ strings.description }</p>
{ /* Use wrapping div to keep buttons grouped together. */ }
<div className="account-tools__actions">
{ ! detailsSubmitted && (
<Button
variant={ 'secondary' }
onClick={ () =>
recordEvent(
'wcpay_account_details_link_clicked',
{
source:
'account-tools__finish-setup-button',
}
)
}
href={ accountLink }
>
{ strings.finish }
</Button>
) }
<Button
variant={ detailsSubmitted ? 'secondary' : 'tertiary' }
variant={ 'secondary' }
onClick={ () => setModalVisible( true ) }
>
{ strings.reset }
Expand Down
1 change: 0 additions & 1 deletion client/components/account-status/account-tools/strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export default {
'Payments and deposits are disabled until account setup is completed. If you are experiencing problems completing account setup, or need to change the email/country associated with your account, you can reset your account and start from the beginning.',
'woocommerce-payments'
),
finish: __( 'Finish setup', 'woocommerce-payments' ),
reset: __( 'Reset account', 'woocommerce-payments' ),
};
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AccountTools should render in live mode 1`] = `
<div>
<div
class="account-tools"
>
<hr
aria-orientation="horizontal"
class="components-divider components-card__divider components-card-divider css-yo8r29-DividerView-renderBorder-renderSize-renderMargin-Divider-borderColor e19on6iw0"
data-wp-c16t="true"
data-wp-component="CardDivider"
role="separator"
/>
<h4>
Account Tools
</h4>
<p>
Payments and deposits are disabled until account setup is completed. If you are experiencing problems completing account setup, or need to change the email/country associated with your account, you can reset your account and start from the beginning.
</p>
<div
class="account-tools__actions"
>
<a
class="components-button is-secondary"
href="/onboarding?source=account-tools__finish-setup-button"
>
Finish setup
</a>
<button
class="components-button is-tertiary"
type="button"
>
Reset account
</button>
</div>
</div>
</div>
`;
exports[`AccountTools should NOT render in live mode 1`] = `<div />`;

exports[`AccountTools should render in sandbox mode 1`] = `
<div>
Expand All @@ -59,14 +23,8 @@ exports[`AccountTools should render in sandbox mode 1`] = `
<div
class="account-tools__actions"
>
<a
class="components-button is-secondary"
href="/onboarding?source=account-tools__finish-setup-button"
>
Finish setup
</a>
<button
class="components-button is-tertiary"
class="components-button is-secondary"
type="button"
>
Reset account
Expand Down
34 changes: 5 additions & 29 deletions client/components/account-status/account-tools/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* External dependencies
*/
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render } from '@testing-library/react';

/**
* Internal dependencies
*/
import { AccountTools } from '..';

const accountLink = '/onboarding';
const openModal = jest.fn();

declare const global: {
Expand All @@ -20,18 +19,15 @@ declare const global: {
};

describe( 'AccountTools', () => {
it( 'should render in live mode', () => {
it( 'should NOT render in live mode', () => {
global.wcpaySettings = {
devMode: false,
};

const { container } = render(
<AccountTools
accountLink={ accountLink }
detailsSubmitted={ false }
openModal={ openModal }
/>
<AccountTools openModal={ openModal } />
);

expect( container ).toMatchSnapshot();
} );

Expand All @@ -41,29 +37,9 @@ describe( 'AccountTools', () => {
};

const { container } = render(
<AccountTools
accountLink={ accountLink }
detailsSubmitted={ false }
openModal={ openModal }
/>
<AccountTools openModal={ openModal } />
);

expect( container ).toMatchSnapshot();
} );

it( 'should render in sandbox mode for details submitted account without finish setup button', () => {
global.wcpaySettings = {
devMode: true,
};

render(
<AccountTools
accountLink={ accountLink }
detailsSubmitted={ true }
openModal={ openModal }
/>
);

expect( screen.queryByText( 'Finish setup' ) ).not.toBeInTheDocument();
} );
} );
14 changes: 5 additions & 9 deletions client/components/account-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import StatusChip from './status-chip';
import './style.scss';
import './shared.scss';
import { AccountTools } from './account-tools';
import { isInDevMode } from 'wcpay/utils';
import { recordEvent } from 'wcpay/tracks';
import { addQueryArgs } from '@wordpress/url';

Expand Down Expand Up @@ -62,7 +61,8 @@ const AccountStatusError = () => {
const AccountStatusDetails = ( props ) => {
const { accountStatus, accountFees } = props;
const accountLink = addQueryArgs( accountStatus.accountLink, {
source: 'account-details',
from: 'WCPAY_ACCOUNT_DETAILS',
source: 'wcpay-account-details',
} );
const cardTitle = (
<>
Expand All @@ -83,7 +83,8 @@ const AccountStatusDetails = ( props ) => {
variant={ 'link' }
onClick={ () =>
recordEvent( 'wcpay_account_details_link_clicked', {
source: 'account-details',
from: 'WCPAY_ACCOUNT_DETAILS',
source: 'wcpay-account-details',
} )
}
href={ accountLink }
Expand Down Expand Up @@ -118,12 +119,7 @@ const AccountStatusDetails = ( props ) => {
}
/>
</AccountStatusItem>
{ ( ! accountStatus.detailsSubmitted || isInDevMode() ) && (
<AccountTools
accountLink={ wcpaySettings.connectUrl }
detailsSubmitted={ accountStatus.detailsSubmitted }
/>
) }
<AccountTools />
{ accountFees.length > 0 && (
<AccountFees accountFees={ accountFees } />
) }
Expand Down
Loading

0 comments on commit 28a3248

Please sign in to comment.