Skip to content

Commit

Permalink
Paid newsletter importer updates (#94703)
Browse files Browse the repository at this point in the history
* reset importer on summary buttons click

* show subscribers import button

* update stripe step

* fixesss

* update copy

* Only show done status

* Remove is fetching

* Update the progressBar

* Improve the subscriber done state

---------

Co-authored-by: Enej Bajgoric <[email protected]>
  • Loading branch information
pkuliga and enejb committed Sep 20, 2024
1 parent 4cf5fb6 commit 9c10391
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 131 deletions.
5 changes: 3 additions & 2 deletions client/data/paid-newsletter/use-reset-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
} from '@tanstack/react-query';
import { useCallback } from 'react';
import wp from 'calypso/lib/wp';
import { StepId } from './use-paid-newsletter-query';

interface MutationVariables {
siteId: number;
engine: string;
currentStep: string;
currentStep: StepId;
}

export const useResetMutation = (
Expand Down Expand Up @@ -48,7 +49,7 @@ export const useResetMutation = (
const { mutate } = mutation;

const resetPaidNewsletter = useCallback(
( siteId: number, engine: string, currentStep: string ) =>
( siteId: number, engine: string, currentStep: StepId ) =>
mutate( { siteId, engine, currentStep } ),
[ mutate ]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class UploadingPane extends PureComponent {
return (
<div className="content-upload-form__in-progress">
<p>{ uploaderPrompt }</p>
<ProgressBar className="content-upload-form__in-progress-bar" />
<ProgressBar className="content-upload-form__in-progress-bar is-larger-progress-bar" />
</div>
);
}
Expand Down
3 changes: 2 additions & 1 deletion client/my-sites/importer/newsletter/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { fetchImporterState, startImport } from 'calypso/state/imports/actions';
import { appStates } from 'calypso/state/imports/constants';
import { getImporterStatusForSiteId } from 'calypso/state/imports/selectors';
import FileImporter from './content-upload/file-importer';
import { EngineTypes } from './types';
import type { SiteDetails } from '@automattic/data-stores';

interface ContentProps {
nextStepUrl: string;
engine: string;
engine: EngineTypes;
selectedSite: SiteDetails;
siteSlug: string;
fromSite: string;
Expand Down
15 changes: 12 additions & 3 deletions client/my-sites/importer/newsletter/importer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
clear: both;
margin-bottom: 12px;

p {
position: relative;
overflow: hidden;
margin-bottom: 0;
}

svg {
float: left;
margin-right: 6px;
Expand All @@ -52,6 +58,11 @@
}
}

.summary__content-indent {
margin-top: -20;
margin-left: 20px;
}

.stripe-logo {
width: 48px;
padding-left: 8px;
Expand Down Expand Up @@ -81,9 +92,7 @@
display: block;
margin: 24px 0;
}

.subscriber-upload-form__progress-bar,
.content-upload-form__in-progress-bar {
.is-larger-progress-bar {
height: 5px;
border-radius: 3px;
}
Expand Down
9 changes: 6 additions & 3 deletions client/my-sites/importer/newsletter/importer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function NewsletterImporter( {
const [ validFromSite, setValidFromSite ] = useState( false );
const [ autoFetchData, setAutoFetchData ] = useState( false );

const { data: paidNewsletterData, isFetching: isFetchingPaidNewsletter } = usePaidNewsletterQuery(
const { data: paidNewsletterData } = usePaidNewsletterQuery(
engine,
step,
selectedSite?.ID,
Expand Down Expand Up @@ -171,12 +171,15 @@ export default function NewsletterImporter( {
cardData={ paidNewsletterData.steps[ step ]?.content }
engine={ engine }
status={ paidNewsletterData.steps[ step ]?.status || 'initial' }
isFetchingContent={ isFetchingPaidNewsletter }
setAutoFetchData={ setAutoFetchData }
/>
) }
{ step === 'summary' && (
<Summary selectedSite={ selectedSite } steps={ paidNewsletterData.steps } />
<Summary
selectedSite={ selectedSite }
steps={ paidNewsletterData.steps }
engine={ engine }
/>
) }
</>
) }
Expand Down
2 changes: 0 additions & 2 deletions client/my-sites/importer/newsletter/subscribers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default function Subscribers( {
selectedSite,
fromSite,
status,
isFetchingContent,
siteSlug,
skipNextStep,
cardData,
Expand All @@ -35,7 +34,6 @@ export default function Subscribers( {
cardData={ cardData }
engine={ engine }
fromSite={ fromSite }
isFetchingContent={ isFetchingContent }
nextStepUrl={ nextStepUrl }
selectedSite={ selectedSite }
setAutoFetchData={ setAutoFetchData }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function PaidSubscribers( {
nextStepUrl,
selectedSite,
fromSite,
isFetchingContent,
siteSlug,
skipNextStep,
cardData,
Expand Down Expand Up @@ -39,7 +38,6 @@ export default function PaidSubscribers( {
cardData={ cardData }
engine={ engine }
fromSite={ fromSite }
isFetchingContent={ isFetchingContent }
nextStepUrl={ nextStepUrl }
selectedSite={ selectedSite }
setAutoFetchData={ setAutoFetchData }
Expand All @@ -53,7 +51,6 @@ export default function PaidSubscribers( {
cardData={ cardData }
engine={ engine }
fromSite={ fromSite }
isFetchingContent={ isFetchingContent }
nextStepUrl={ nextStepUrl }
selectedSite={ selectedSite }
setAutoFetchData={ setAutoFetchData }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { getQueryArg, addQueryArgs } from '@wordpress/url';
import { QueryArgParsed } from '@wordpress/url/build-types/get-query-arg';
import StripeLogo from 'calypso/assets/images/jetpack/stripe-logo-white.svg';
import { navigate } from 'calypso/lib/navigate';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import ImporterActionButton from '../../../importer-action-buttons/action-button';
import ImporterActionButtonContainer from '../../../importer-action-buttons/container';
import { SubscribersStepProps } from '../../types';
import StartImportButton from '../start-import-button';

/**
* Update the connect URL with the from_site and engine parameters.
Expand All @@ -27,9 +29,10 @@ export default function ConnectStripe( {
cardData,
fromSite,
engine,
isFetchingContent,
selectedSite,
siteSlug,
}: SubscribersStepProps ) {
if ( isFetchingContent || cardData?.connect_url === undefined ) {
if ( cardData?.connect_url === undefined ) {
return null;
}

Expand All @@ -39,8 +42,8 @@ export default function ConnectStripe( {
<>
<h2>Do you have paid subscribers?</h2>
<p>
To your migrate your <strong>paid subscribers</strong> to WordPress.com, make sure you're
connecting <strong>the same Stripe account</strong> you use with Substack.
To migrate your <strong>paid subscribers</strong> to WordPress.com, make sure you're
connecting the <strong>same</strong> Stripe account you use with Substack.
</p>
<ImporterActionButtonContainer noSpacing>
<ImporterActionButton
Expand All @@ -52,6 +55,16 @@ export default function ConnectStripe( {
>
Connect <img src={ StripeLogo } className="stripe-logo" width="48px" alt="Stripe logo" />
</ImporterActionButton>
<StartImportButton
engine={ engine }
siteId={ selectedSite.ID }
step="subscribers"
primary={ false }
navigate={ () => {
navigate( `/import/newsletter/${ engine }/${ siteSlug }/summary?from=${ fromSite }` );
} }
label="Continue free subscriber import"
/>
</ImporterActionButtonContainer>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ function formatCurrencyFloat( amount: number, currency: string ) {
return parseFloat( formattedCurrency );
}

function shouldShowButton( cardData: any ) {
// Show the button if
function shouldEnableImporting( cardData: any ) {
// Enable the button if
if ( ! cardData?.is_connected_stripe ) {
return true;
}

// show the button if we have mapped all the
// Enable the button if we have mapped all the
const plans = cardData?.plans ?? [];
const map_plans = cardData?.map_plans ?? {};

Expand Down Expand Up @@ -137,7 +137,7 @@ export default function MapPlans( {
},
};

const showButton = shouldShowButton( cardData );
const isImportButtonDisabled = ! shouldEnableImporting( cardData ) || isSavingPlanMapping;

const onProductSelect = ( stripePlanId: string, productId: string ) => {
mapStripePlanToProduct( selectedSite.ID, engine, currentStep, stripePlanId, productId );
Expand Down Expand Up @@ -181,19 +181,15 @@ export default function MapPlans( {
} ) }
</div>

{ showButton && ! isSavingPlanMapping && (
<StartImportButton
engine={ engine }
siteId={ selectedSite.ID }
hasPaidSubscribers
step={ currentStep }
navigate={ () => {
navigate( `/import/newsletter/${ engine }/${ siteSlug }/summary?from=${ fromSite }` );
} }
/>
) }
{ showButton && isSavingPlanMapping && <p>Saving selection...</p> }
{ ! showButton && <p>Map plans on WordPress.com to continue...</p> }
<StartImportButton
engine={ engine }
siteId={ selectedSite.ID }
step={ currentStep }
navigate={ () => {
navigate( `/import/newsletter/${ engine }/${ siteSlug }/summary?from=${ fromSite }` );
} }
disabled={ isImportButtonDisabled }
/>

{ productToAdd && (
<RecurringPaymentsPlanAddEditModal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,36 @@
import { FormLabel } from '@automattic/components';
import { useState } from '@wordpress/element';
import { ChangeEvent } from 'react';
import FormCheckbox from 'calypso/components/forms/form-checkbox';
import { StepId } from 'calypso/data/paid-newsletter/use-paid-newsletter-query';
import { useSubscriberImportMutation } from 'calypso/data/paid-newsletter/use-subscriber-import-mutation';
import ImporterActionButton from '../../importer-action-buttons/action-button';

type Props = {
step: string;
step: StepId;
engine: string;
siteId: number;
hasPaidSubscribers: boolean;
navigate?: () => void;
disabled?: boolean;
primary?: boolean;
label?: string;
};

export default function StartImportButton( {
siteId,
hasPaidSubscribers,
step,
engine,
navigate = () => {},
disabled,
primary = true,
label,
}: Props ) {
const [ isDisabled, setIsDisabled ] = useState( ! hasPaidSubscribers );

const { enqueueSubscriberImport } = useSubscriberImportMutation();

const importSubscribers = () => {
enqueueSubscriberImport( siteId, engine, step );
navigate();
};

const onChange = ( { target: { checked } }: ChangeEvent< HTMLInputElement > ) =>
setIsDisabled( checked );

return (
<>
{ hasPaidSubscribers && (
<>
<p>
<strong>To prevent any unexpected actions by your old provider</strong>, go to your
Stripe dashboard and click “Revoke access” for any service previously associated with
this subscription.
</p>

<p>
<FormLabel>
<FormCheckbox checked={ isDisabled } onChange={ onChange } />
I’ve disconnected other providers from the Stripe account
</FormLabel>
</p>
</>
) }
<ImporterActionButton primary disabled={ ! isDisabled } onClick={ importSubscribers }>
Import subscribers
</ImporterActionButton>
</>
<ImporterActionButton primary={ primary } disabled={ disabled } onClick={ importSubscribers }>
{ label || 'Import subscribers' }
</ImporterActionButton>
);
}
16 changes: 14 additions & 2 deletions client/my-sites/importer/newsletter/subscribers/step-done.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { Card } from '@automattic/components';
import { Notice } from '@wordpress/components';
import ImporterActionButton from '../../importer-action-buttons/action-button';
import { SubscribersStepProps } from '../types';

export default function StepDone() {
return <Card>DONE!</Card>;
export default function StepDone( { cardData, nextStepUrl }: SubscribersStepProps ) {
const subscribedCount = parseInt( cardData.meta?.subscribed_count || '0' );
return (
<Card>
<h2>Import your subscribers to WordPress.com</h2>
<Notice status="success" className="importer__notice" isDismissible={ false }>
Success! { subscribedCount } subscribers have been added!
</Notice>
<ImporterActionButton href={ nextStepUrl }>View Summary</ImporterActionButton>
</Card>
);
}
24 changes: 22 additions & 2 deletions client/my-sites/importer/newsletter/subscribers/step-importing.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { Card } from '@automattic/components';
import { ProgressBar } from '@wordpress/components';
import { Icon, atSymbol } from '@wordpress/icons';
import ImporterActionButton from '../../importer-action-buttons/action-button';
import { SubscribersStepProps } from '../types';

export default function StepAwaiting() {
return <Card>Awaiting!!</Card>;
export default function StepImporting( { nextStepUrl }: SubscribersStepProps ) {
return (
<Card>
<div className="summary__content">
<p>
<Icon icon={ atSymbol } /> <strong>We're importing your subscribers</strong>
</p>
</div>
<p>
This may take a few minutes. Feel free to leave this window – we'll let you know when it's
done.
</p>
<p>
<ProgressBar className="is-larger-progress-bar" />
</p>
<ImporterActionButton href={ nextStepUrl }>View Summary</ImporterActionButton>
</Card>
);
}
Loading

0 comments on commit 9c10391

Please sign in to comment.