Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pending sticker when loading the "how to migrate" step #95413

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import { useTranslate } from 'i18n-calypso';
import { FC, useMemo } from 'react';
import DocumentHead from 'calypso/components/data/document-head';
import FormattedHeader from 'calypso/components/formatted-header';
import { useUpdateMigrationStatus } from 'calypso/data/site-migration/use-update-migration-status';
import { useAnalyzeUrlQuery } from 'calypso/data/site-profiler/use-analyze-url-query';
import { useHostingProviderQuery } from 'calypso/data/site-profiler/use-hosting-provider-query';
import { HOW_TO_MIGRATE_OPTIONS } from 'calypso/landing/stepper/constants';
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { usePresalesChat } from 'calypso/lib/presales-chat';
import useHostingProviderName from 'calypso/site-profiler/hooks/use-hosting-provider-name';
import FlowCard from '../components/flow-card';
import usePendingMigrationStatus from './use-pending-migration-status';
import type { StepProps } from '../../types';

import './style.scss';
Expand All @@ -26,7 +25,6 @@ const SiteMigrationHowToMigrate: FC< Props > = ( props ) => {
const { navigation, headerText } = props;

const translate = useTranslate();
const site = useSite();
const importSiteQueryParam = useQuery().get( 'from' ) || '';
usePresalesChat( 'wpcom', true, true );

Expand Down Expand Up @@ -64,29 +62,14 @@ const SiteMigrationHowToMigrate: FC< Props > = ( props ) => {
urlData
);

const { onOptionClick } = usePendingMigrationStatus( { onSubmit: navigation.submit } );

const hostingProviderSlug = hostingProviderData?.hosting_provider?.slug;
const shouldDisplayHostIdentificationMessage =
hostingProviderSlug &&
hostingProviderSlug !== 'unknown' &&
hostingProviderSlug !== 'automattic';

const canInstallPlugins = site?.plan?.features?.active.find(
( feature ) => feature === 'install-plugins'
)
? true
: false;

const { updateMigrationStatus } = useUpdateMigrationStatus();

const handleClick = ( how: string ) => {
const destination = canInstallPlugins ? 'migrate' : 'upgrade';
if ( site?.ID ) {
const parsedHow = how === HOW_TO_MIGRATE_OPTIONS.DO_IT_MYSELF ? 'diy' : how;
updateMigrationStatus( site.ID, `migration-pending-${ parsedHow }` );
}
return navigation.submit?.( { how, destination } );
};

const stepContent = (
<>
<div className="how-to-migrate__list">
Expand All @@ -95,7 +78,7 @@ const SiteMigrationHowToMigrate: FC< Props > = ( props ) => {
key={ i }
title={ option.label }
text={ option.description }
onClick={ () => handleClick( option.value ) }
onClick={ () => onOptionClick( option.value ) }
/>
) ) }
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect } from 'react';
import { useUpdateMigrationStatus } from 'calypso/data/site-migration/use-update-migration-status';
import { HOW_TO_MIGRATE_OPTIONS } from 'calypso/landing/stepper/constants';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import type { NavigationControls } from '../../types';

interface PendingMigrationStatusProps {
onSubmit?: Pick< NavigationControls, 'submit' >[ 'submit' ];
}

const usePendingMigrationStatus = ( { onSubmit }: PendingMigrationStatusProps ) => {
const site = useSite();
const siteId = site?.ID;

const canInstallPlugins = site?.plan?.features?.active.find(
( feature ) => feature === 'install-plugins'
)
? true
: false;

const { updateMigrationStatus } = useUpdateMigrationStatus();

// Register pending migration status when loading the step.
useEffect( () => {
if ( siteId ) {
updateMigrationStatus( siteId, 'migration-pending' );
}
}, [ siteId, updateMigrationStatus ] );

const onOptionClick = ( how: string ) => {
const destination = canInstallPlugins ? 'migrate' : 'upgrade';
if ( siteId ) {
const parsedHow = how === HOW_TO_MIGRATE_OPTIONS.DO_IT_MYSELF ? 'diy' : how;
updateMigrationStatus( siteId, `migration-pending-${ parsedHow }` );
}

if ( onSubmit ) {
return onSubmit( { how, destination } );
}
};

return { onOptionClick };
};

export default usePendingMigrationStatus;
Loading