Skip to content

Commit

Permalink
Integrate Account Management component into the Settings Page (#10287)
Browse files Browse the repository at this point in the history
  • Loading branch information
mordeth authored Feb 12, 2025
1 parent 50aa483 commit 1916341
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog/add-9129-account-management-component
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add the Stripe embedded account management component into the Payments → Settings page.
68 changes: 68 additions & 0 deletions client/settings/account-management/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* External dependencies
*/
import React, { useState } from 'react';
import { Card, CardBody } from '@wordpress/components';
import {
ConnectAccountManagement,
ConnectComponentsProvider,
} from '@stripe/react-connect-js';

/**
* Internal dependencies
*/
import StripeSpinner from 'wcpay/components/stripe-spinner';
import BannerNotice from 'wcpay/components/banner-notice';
import appearance from 'wcpay/utils/embedded-components/appearance';
import useAccountSession from 'wcpay/utils/embedded-components/account-session';
import './style.scss';

const AccountManagement = () => {
const [ loadErrorMessage, setLoadErrorMessage ] = useState( '' );
const [ loading, setLoading ] = useState( true );
const stripeConnectInstance = useAccountSession( {
setLoadErrorMessage,
appearance,
} );

return (
<>
<Card>
<CardBody>
{ loading && (
<div className="account-management-loader-wrapper">
<StripeSpinner />
</div>
) }
{ loadErrorMessage ? (
<BannerNotice status="error">
{ loadErrorMessage }
</BannerNotice>
) : (
stripeConnectInstance && (
<ConnectComponentsProvider
connectInstance={ stripeConnectInstance }
>
<ConnectAccountManagement
onLoaderStart={ () => setLoading( false ) }
onLoadError={ ( loadError ) =>
setLoadErrorMessage(
loadError.error.message ||
'Unknown error'
)
}
collectionOptions={ {
fields: 'eventually_due',
futureRequirements: 'include',
} }
/>
</ConnectComponentsProvider>
)
) }
</CardBody>
</Card>
</>
);
};

export default AccountManagement;
6 changes: 6 additions & 0 deletions client/settings/account-management/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Wrap loader so it's centered and does not get cut.
.account-management-loader-wrapper {
text-align: center;
height: 35px;
padding: 20px 0;
}
26 changes: 25 additions & 1 deletion client/settings/settings-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SettingsLayout from '../settings-layout';
import SaveSettingsSection from '../save-settings-section';
import Transactions from '../transactions';
import Deposits from '../deposits';
import AccountManagement from '../account-management';
import LoadableSettingsSection from '../loadable-settings-section';
import PaymentMethodsSection from '../payment-methods-section';
import BuyNowPayLaterSection from '../buy-now-pay-later-section';
Expand Down Expand Up @@ -102,6 +103,20 @@ const DepositsDescription = () => {
);
};

const AccountDetailsDescription = () => {
return (
<>
<h2>{ __( 'Account details', 'woocommerce-payments' ) }</h2>
<p>
{ __(
'View and edit your WooPayments account details like personal or business information and public information.',
'woocommerce-payments'
) }
</p>
</>
);
};

const FraudProtectionDescription = () => {
return (
<>
Expand Down Expand Up @@ -143,7 +158,6 @@ const SettingsManager = () => {
const [ isTransactionInputsValid, setTransactionInputsValid ] = useState(
true
);

const { isLoading } = useSettings();

useLayoutEffect( () => {
Expand Down Expand Up @@ -211,6 +225,16 @@ const SettingsManager = () => {
</LoadableSettingsSection>
</SettingsSection>
</DuplicatedPaymentMethodsContext.Provider>
<SettingsSection
description={ AccountDetailsDescription }
id="account-details"
>
<LoadableSettingsSection numLines={ 20 }>
<ErrorBoundary>
<AccountManagement />
</ErrorBoundary>
</LoadableSettingsSection>
</SettingsSection>
<SettingsSection
description={ TransactionsDescription }
id="transactions"
Expand Down

0 comments on commit 1916341

Please sign in to comment.