Account connection
Shows whether a merchant has connected a third-party account to the app, and lets them connect or disconnect it in one click.
Preview
Code
Example.jsx
import { useState, useCallback } from 'react';
import { AccountConnection, Link } from '@shopify/polaris';
const ACCOUNT_NAME = 'Mailchimp';
const CONNECTED_ACCOUNT = 'jane@snowdevil.com';
export const Example = () => {
const [connected, setConnected] = useState(false);
const handleAction = useCallback(() => {
setConnected((prev) => !prev);
}, []);
const details = connected ? `Connected as ${CONNECTED_ACCOUNT}` : 'No account connected';
const terms = connected ? null : (
<p>
By clicking <strong>Connect</strong>, you agree to accept {ACCOUNT_NAME}’s{' '}
<Link url="https://mailchimp.com/legal/terms/" target="_blank">
terms and conditions
</Link>
. Your customer list will be synced every hour.
</p>
);
return (
<AccountConnection
title={ACCOUNT_NAME}
accountName={connected ? CONNECTED_ACCOUNT : ''}
connected={connected}
action={{
content: connected ? 'Disconnect' : 'Connect',
onAction: handleAction,
}}
details={details}
termsOfService={terms}
/>
);
};