File size: 2,958 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Button, Gridicon, FormLabel, SelectDropdown } from '@automattic/components';
import { chevronRight, Icon } from '@wordpress/icons';
import { useI18n } from '@wordpress/react-i18n';
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import {
	getImportersAsImporterOption,
	type ImporterConfigPriority,
} from 'calypso/lib/importer/importer-config';
import ImporterLogo from 'calypso/my-sites/importer/importer-logo';
import type { ImporterPlatform } from 'calypso/lib/importer/types';
import './style.scss';

export interface ImporterOption {
	value: ImporterPlatform;
	label: string;
	icon?: string;
	priority?: ImporterConfigPriority;
}

interface Props {
	siteSlug: string | null;
	title?: string;
	subTitle?: string;
	submit?: ( dependencies: { platform: ImporterPlatform; url: string } ) => void;
	getFinalImporterUrl: (
		siteSlug: string,
		fromSite: string,
		platform: ImporterPlatform,
		backToFlow?: string
	) => string;
	onNavBack?: () => void;
}

export default function ListStep( props: Props ) {
	const { __ } = useI18n();
	const urlQueryParams = useQuery();
	const { siteSlug, submit, getFinalImporterUrl, onNavBack } = props;
	const backToFlow = urlQueryParams.get( 'backToFlow' );
	const fromSite = urlQueryParams.get( 'from' );

	// We need to remove the wix importer from the primary importers list.
	const primaryListOptions: ImporterOption[] = getImportersAsImporterOption( 'primary' ).filter(
		( option ) => option.value !== 'wix'
	);
	// We need to remove the icon property for secondary importers to avoid display issues.
	const secondaryListOptions: ImporterOption[] = getImportersAsImporterOption( 'secondary' ).map(
		( { icon, ...rest } ) => rest
	);

	const onImporterSelect = ( platform: ImporterPlatform ): void => {
		const importerUrl = getFinalImporterUrl(
			siteSlug ?? '',
			fromSite ?? '',
			platform,
			backToFlow ?? undefined
		);
		submit?.( { platform, url: importerUrl } );
	};

	return (
		<>
			{ onNavBack && (
				<div className="import__navigation">
					<Button onClick={ onNavBack } borderless type="button">
						<Gridicon icon="chevron-left" size={ 18 } />
						Back
					</Button>
				</div>
			) }
			<div className="list__wrapper">
				<div className="list__importers list__importers-primary">
					{ primaryListOptions.map( ( x ) => (
						<Button
							key={ x.value }
							className="list__importers-item-card"
							onClick={ () => onImporterSelect( x.value ) }
						>
							<ImporterLogo icon={ x.icon } />
							<h2>{ x.label }</h2>
							<Icon icon={ chevronRight } />
						</Button>
					) ) }
				</div>

				<div className="list__importers list__importers-secondary">
					<FormLabel>{ __( 'Other platforms' ) }</FormLabel>
					<SelectDropdown
						selectedText={ __( 'Select other platform' ) }
						options={ secondaryListOptions }
						onSelect={ ( x: ImporterOption ) => onImporterSelect( x.value ) }
					/>
				</div>
			</div>
		</>
	);
}