File size: 1,646 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
import { translate } from 'i18n-calypso';
import { SITE_LAUNCH } from 'calypso/state/action-types';
import { requestEligibility } from 'calypso/state/automated-transfer/actions';
import { requestSiteChecklist } from 'calypso/state/checklist/actions';
import { registerHandlers } from 'calypso/state/data-layer/handler-registry';
import { http } from 'calypso/state/data-layer/wpcom-http/actions';
import { dispatchRequest } from 'calypso/state/data-layer/wpcom-http/utils';
import { errorNotice, infoNotice, successNotice } from 'calypso/state/notices/actions';
import { updateSiteSettings } from 'calypso/state/site-settings/actions';
import { receiveSite } from 'calypso/state/sites/actions';
import { launchSiteFailure, launchSiteSuccess } from 'calypso/state/sites/launch/actions';

const handleLaunchSiteRequest = dispatchRequest( {
	fetch: ( action ) => [
		infoNotice( translate( 'Launching your site…' ), { duration: 1000 } ),
		http(
			{
				method: 'POST',
				path: `/sites/${ action.siteId }/launch`,
			},
			action
		),
	],
	onSuccess: ( action, data ) => [
		receiveSite( data ),
		updateSiteSettings( data.ID, data.options ),
		requestSiteChecklist( data.ID ),
		requestEligibility( data.ID ),
		successNotice(
			translate( 'Your site has been launched; now you can share it with the world!' ),
			{
				duration: 5000,
			}
		),
		launchSiteSuccess( data.ID ),
	],
	onError: ( action, data ) => {
		return [ errorNotice( data.message, { duration: 5000 } ), launchSiteFailure( action.siteId ) ];
	},
} );

registerHandlers( 'state/data-layer/wpcom/sites/launch/index.js', {
	[ SITE_LAUNCH ]: [ handleLaunchSiteRequest ],
} );