-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract pending migration status hook
- Loading branch information
Showing
2 changed files
with
48 additions
and
42 deletions.
There are no files selected for viewing
45 changes: 3 additions & 42 deletions
45
...epper/declarative-flow/internals/steps-repository/site-migration-how-to-migrate/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../internals/steps-repository/site-migration-how-to-migrate/use-pending-migration-status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |