forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assembler: Redirect back to the previous screen after the checkout (A…
…utomattic#81069) * Assembler: Sync screen to search parameters * Handle initial path * Handle goBack from the intermediate screen * Refactor * Resolve conflicts
- Loading branch information
1 parent
5ec2854
commit 1cbf9f1
Showing
17 changed files
with
212 additions
and
69 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
...ding/stepper/declarative-flow/internals/steps-repository/pattern-assembler/hooks/index.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,11 @@ | ||
export { default as useCategoriesOrder } from './use-categories-order'; | ||
export { default as useCurrentScreen } from './use-current-screen'; | ||
export { default as useDotcomPatterns } from './use-dotcom-patterns'; | ||
export { default as useGlobalStylesUpgradeModal } from './use-global-styles-upgrade-modal'; | ||
export { default as useInitialPath } from './use-initial-path'; | ||
export { default as usePatternCategories } from './use-pattern-categories'; | ||
export { default as usePatternsMapByCategory } from './use-patterns-map-by-category'; | ||
export * from './use-prefetch-images'; | ||
export { default as useRecipe } from './use-recipe'; | ||
export { default as useScreen } from './use-screen'; | ||
export { default as useSyncNavigatorScreen } from './use-sync-navigator-screen'; |
14 changes: 14 additions & 0 deletions
14
...eclarative-flow/internals/steps-repository/pattern-assembler/hooks/use-current-screen.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { INITIAL_SCREEN } from '../constants'; | ||
import useScreen from './use-screen'; | ||
import type { ScreenName } from '../types'; | ||
|
||
const useCurrentScreen = () => { | ||
const [ searchParams ] = useSearchParams(); | ||
const currentScreenName = ( searchParams.get( 'screen' ) ?? INITIAL_SCREEN ) as ScreenName; | ||
const currentScreen = useScreen( currentScreenName ); | ||
|
||
return currentScreen; | ||
}; | ||
|
||
export default useCurrentScreen; |
22 changes: 22 additions & 0 deletions
22
...r/declarative-flow/internals/steps-repository/pattern-assembler/hooks/use-initial-path.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,22 @@ | ||
import { useMemo } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { INITIAL_PATH } from '../constants'; | ||
|
||
const useInitialPath = () => { | ||
const [ searchParams ] = useSearchParams(); | ||
|
||
return useMemo( () => { | ||
const screen = searchParams.get( 'screen' ); | ||
const screenParameter = searchParams.get( 'screen_parameter' ); | ||
if ( ! screen ) { | ||
return INITIAL_PATH; | ||
} | ||
|
||
return [ screen, screenParameter ] | ||
.filter( Boolean ) | ||
.map( ( path ) => `/${ path }` ) | ||
.join( '' ); | ||
}, [] ); | ||
}; | ||
|
||
export default useInitialPath; |
53 changes: 53 additions & 0 deletions
53
...tepper/declarative-flow/internals/steps-repository/pattern-assembler/hooks/use-screen.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useHasEnTranslation } from '@automattic/i18n-utils'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { NAVIGATOR_PATHS } from '../constants'; | ||
import type { ScreenName } from '../types'; | ||
|
||
const useScreen = ( screenName: ScreenName ) => { | ||
const translate = useTranslate(); | ||
const hasEnTranslation = useHasEnTranslation(); | ||
const screens = { | ||
main: { | ||
name: 'main', | ||
title: translate( 'Design your own' ), | ||
initialPath: NAVIGATOR_PATHS.MAIN_HEADER, | ||
}, | ||
styles: { | ||
name: 'styles', | ||
title: hasEnTranslation( 'Pick your style' ) | ||
? translate( 'Pick your style' ) | ||
: translate( 'Styles' ), | ||
initialPath: NAVIGATOR_PATHS.STYLES_COLORS, | ||
}, | ||
upsell: { | ||
name: 'upsell', | ||
title: translate( 'Custom styles' ), | ||
}, | ||
activation: { | ||
name: 'activation', | ||
title: translate( 'Activate this theme' ), | ||
initialPath: NAVIGATOR_PATHS.ACTIVATION, | ||
}, | ||
confirmation: { | ||
name: 'confirmation', | ||
title: translate( 'Great job!' ), | ||
initialPath: NAVIGATOR_PATHS.CONFIRMATION, | ||
}, | ||
}; | ||
|
||
/** @todo Handle the upsell screen in the following PR */ | ||
const previousScreens = { | ||
main: null, | ||
styles: screens.main, | ||
upsell: screens.styles, | ||
activation: screens.styles, | ||
confirmation: screens.styles, | ||
}; | ||
|
||
return { | ||
...screens[ screenName ], | ||
previousScreen: previousScreens[ screenName ], | ||
}; | ||
}; | ||
|
||
export default useScreen; |
30 changes: 30 additions & 0 deletions
30
...tive-flow/internals/steps-repository/pattern-assembler/hooks/use-sync-navigator-screen.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,30 @@ | ||
import { useNavigatorListener } from '@automattic/onboarding'; | ||
import { useCallback } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { INITIAL_SCREEN } from '../constants'; | ||
|
||
const useSyncNavigatorScreen = () => { | ||
const [ , setSearchParams ] = useSearchParams(); | ||
const handleNavigatorPathChange = useCallback( | ||
( path = '' ) => { | ||
setSearchParams( | ||
( currentSearchParams ) => { | ||
const [ screen, screenParameter ] = path.split( '/' ).slice( 1 ); | ||
currentSearchParams.set( 'screen', screen ?? INITIAL_SCREEN ); | ||
if ( screenParameter ) { | ||
currentSearchParams.set( 'screen_parameter', screenParameter ); | ||
} else { | ||
currentSearchParams.delete( 'screen_parameter' ); | ||
} | ||
return currentSearchParams; | ||
}, | ||
{ replace: true } | ||
); | ||
}, | ||
[ setSearchParams ] | ||
); | ||
|
||
useNavigatorListener( handleNavigatorPathChange ); | ||
}; | ||
|
||
export default useSyncNavigatorScreen; |
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
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
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
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
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
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
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 @@ | ||
export { default as useNavigatorListener } from './use-navigator-listener'; |
Oops, something went wrong.