File size: 22,515 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
import { __ } from '@wordpress/i18n';
import { SiteGoal } from '../onboard';
import { wpcomRequest } from '../wpcom-request-controls';
import { DEFAULT_GLOBAL_STYLES_VARIATION_SLUG } from './constants';
import {
SiteLaunchError,
AtomicTransferError,
LatestAtomicTransferError,
AtomicSoftwareStatusError,
AtomicSoftwareInstallError,
GlobalStyles,
AssembleSiteOptions,
} from './types';
import { createCustomHomeTemplateContent } from './utils';
import type {
CreateSiteParams,
NewSiteErrorResponse,
NewSiteSuccessResponse,
SiteDetails,
SiteError,
Cart,
Domain,
LatestAtomicTransfer,
SiteLaunchError as SiteLaunchErrorType,
AtomicTransferError as AtomicTransferErrorType,
LatestAtomicTransferError as LatestAtomicTransferErrorType,
AtomicSoftwareStatusError as AtomicSoftwareStatusErrorType,
AtomicSoftwareInstallError as AtomicSoftwareInstallErrorType,
AtomicSoftwareStatus,
SiteSettings,
ActiveTheme,
CurrentTheme,
} from './types';
import type { WpcomClientCredentials } from '../shared-types';
import type { RequestTemplate } from '../templates';
import type { Design, DesignOptions } from '@automattic/design-picker/src/types'; // Import from a specific file directly to avoid the circular dependencies
export function createActions( clientCreds: WpcomClientCredentials ) {
const fetchSite = () => ( {
type: 'FETCH_SITE' as const,
} );
const fetchNewSite = () => ( {
type: 'FETCH_NEW_SITE' as const,
} );
const receiveNewSite = ( response: NewSiteSuccessResponse ) => ( {
type: 'RECEIVE_NEW_SITE' as const,
response,
} );
const receiveNewSiteFailed = ( error: NewSiteErrorResponse ) => ( {
type: 'RECEIVE_NEW_SITE_FAILED' as const,
error,
} );
function* createSite( params: CreateSiteParams ) {
yield fetchNewSite();
try {
const { authToken, ...providedParams } = params;
const defaultParams = {
client_id: clientCreds.client_id,
client_secret: clientCreds.client_secret,
// will find an available `*.wordpress.com` url based on the `blog_name`
find_available_url: true,
// Private site is default, but overridable, setting
public: -1,
};
const mergedParams = {
...defaultParams,
...providedParams,
// Set to false because site validation should be a separate action
validate: false,
};
const newSite: NewSiteSuccessResponse = yield wpcomRequest( {
path: '/sites/new',
apiVersion: '1.1',
method: 'post',
body: mergedParams,
token: authToken,
} );
yield receiveNewSite( newSite );
return true;
} catch ( err ) {
yield receiveNewSiteFailed( err as NewSiteErrorResponse );
return false;
}
}
const receiveSite = ( siteId: number, response: SiteDetails | undefined ) => ( {
type: 'RECEIVE_SITE' as const,
siteId,
response,
} );
const receiveSiteTitle = ( siteId: number, name: string | undefined ) => ( {
type: 'RECEIVE_SITE_TITLE' as const,
siteId,
name,
} );
const receiveSiteTagline = ( siteId: number, tagline: string | undefined ) => ( {
type: 'RECEIVE_SITE_TAGLINE' as const,
siteId,
tagline,
} );
const receiveSiteVerticalId = ( siteId: number, verticalId: string | undefined ) => ( {
type: 'RECEIVE_SITE_VERTICAL_ID' as const,
siteId,
verticalId,
} );
const receiveSiteFailed = ( siteId: number, response: SiteError ) => ( {
type: 'RECEIVE_SITE_FAILED' as const,
siteId,
response,
} );
const reset = () => ( {
type: 'RESET_SITE_STORE' as const,
} );
const resetNewSiteFailed = () => ( {
type: 'RESET_RECEIVE_NEW_SITE_FAILED' as const,
} );
const launchSiteStart = ( siteId: number ) => ( {
type: 'LAUNCH_SITE_START' as const,
siteId,
} );
const launchSiteSuccess = ( siteId: number ) => ( {
type: 'LAUNCH_SITE_SUCCESS' as const,
siteId,
} );
const launchSiteFailure = ( siteId: number, error: SiteLaunchErrorType ) => ( {
type: 'LAUNCH_SITE_FAILURE' as const,
siteId,
error,
} );
function* launchSite( siteId: number ) {
yield launchSiteStart( siteId );
try {
yield wpcomRequest( {
path: `/sites/${ siteId }/launch`,
apiVersion: '1.1',
method: 'post',
} );
yield launchSiteSuccess( siteId );
} catch ( _ ) {
yield launchSiteFailure( siteId, SiteLaunchError.INTERNAL );
}
}
// TODO: move getCart and setCart to a 'cart' data-store
function* getCart( siteId: number ) {
const success: Cart = yield wpcomRequest( {
path: '/me/shopping-cart/' + siteId,
apiVersion: '1.1',
method: 'GET',
} );
return success;
}
const receiveSiteDomains = ( siteId: number, domains: Domain[] ) => ( {
type: 'RECEIVE_SITE_DOMAINS' as const,
siteId,
domains,
} );
const receiveSiteTheme = ( siteId: number, theme: CurrentTheme ) => ( {
type: 'RECEIVE_SITE_THEME' as const,
siteId,
theme,
} );
const receiveSiteSettings = ( siteId: number, settings: SiteSettings ) => ( {
type: 'RECEIVE_SITE_SETTINGS' as const,
siteId,
settings,
} );
const updateSiteSettings = ( siteId: number, settings: SiteSettings ) => ( {
type: 'UPDATE_SITE_SETTINGS' as const,
siteId,
settings,
} );
function* setCart( siteId: number, cartData: Cart ) {
const success: Cart = yield wpcomRequest( {
path: '/me/shopping-cart/' + siteId,
apiVersion: '1.1',
method: 'POST',
body: cartData,
} );
return success;
}
const receiveSiteGlobalStyles = ( siteId: number, globalStyles: GlobalStyles ) => ( {
type: 'RECEIVE_SITE_GLOBAL_STYLES' as const,
siteId,
globalStyles,
} );
function* getGlobalStyles( siteId: number, stylesheet: string ) {
const globalStyles: GlobalStyles = yield wpcomRequest( {
path: `/sites/${ siteId }/global-styles/themes/${ stylesheet }`,
apiNamespace: 'wp/v2',
} );
yield receiveSiteGlobalStyles( siteId, globalStyles );
return globalStyles;
}
function* setGlobalStyles(
siteIdOrSlug: number | string,
stylesheet: string,
globalStyles: GlobalStyles,
activatedTheme?: ActiveTheme
) {
// only update if there settings or styles to update
if (
Object.keys( globalStyles.settings ?? {} ).length ||
Object.keys( globalStyles.styles ?? {} ).length
) {
const globalStylesId: number =
activatedTheme?.global_styles_id || ( yield getGlobalStylesId( siteIdOrSlug, stylesheet ) );
const updatedGlobalStyles: GlobalStyles = yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteIdOrSlug ) }/global-styles/${ globalStylesId }`,
apiNamespace: 'wp/v2',
method: 'POST',
body: {
id: globalStylesId,
settings: globalStyles.settings ?? {},
styles: globalStyles.styles ?? {},
},
} );
return updatedGlobalStyles;
}
}
function* resetGlobalStyles(
siteIdOrSlug: number | string,
stylesheet: string,
activatedTheme?: ActiveTheme
) {
const globalStylesId: number =
activatedTheme?.global_styles_id || ( yield getGlobalStylesId( siteIdOrSlug, stylesheet ) );
const updatedGlobalStyles: GlobalStyles = yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteIdOrSlug ) }/global-styles/${ globalStylesId }`,
apiNamespace: 'wp/v2',
method: 'POST',
body: {
id: globalStylesId,
settings: {},
styles: {},
},
} );
return updatedGlobalStyles;
}
function* getGlobalStylesId( siteIdOrSlug: number | string, stylesheet: string ) {
const theme: ActiveTheme = yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteIdOrSlug ) }/themes/${ stylesheet }`,
method: 'GET',
apiNamespace: 'wp/v2',
} );
const globalStylesUrl = theme?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]?.href;
if ( globalStylesUrl ) {
// eslint-disable-next-line no-useless-escape
const match = globalStylesUrl.match( /global-styles\/(?<id>[\/\w-]+)/ );
if ( match && match.groups ) {
return match.groups.id;
}
}
return null;
}
function* getGlobalStylesVariations( siteIdOrSlug: number | string, stylesheet: string ) {
const variations: GlobalStyles[] = yield wpcomRequest( {
path: `/sites/${ encodeURIComponent(
siteIdOrSlug
) }/global-styles/themes/${ stylesheet }/variations`,
method: 'GET',
apiNamespace: 'wp/v2',
} );
return variations;
}
function* saveSiteSettings(
siteId: number,
settings: {
blogname?: string;
blogdescription?: string;
launchpad_screen?: string;
site_vertical_id?: string;
woocommerce_store_address?: string;
woocommerce_store_address_2?: string;
woocommerce_store_city?: string;
woocommerce_store_postcode?: string;
woocommerce_defaut_country?: string;
woocommerce_onboarding_profile?: { [ key: string ]: any };
}
) {
try {
// extract this into its own function as a generic settings setter
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteId ) }/settings`,
apiVersion: '1.4',
body: settings,
method: 'POST',
} );
if ( 'blogname' in settings ) {
yield receiveSiteTitle( siteId, settings.blogname );
}
if ( 'blogdescription' in settings ) {
yield receiveSiteTagline( siteId, settings.blogdescription );
}
if ( 'site_vertical_id' in settings ) {
yield receiveSiteVerticalId( siteId, settings.site_vertical_id );
}
yield updateSiteSettings( siteId, settings );
} catch ( e ) {}
}
function* setIntentOnSite( siteSlug: string, intent: string ) {
try {
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteSlug ) }/site-intent`,
apiNamespace: 'wpcom/v2',
body: { site_intent: intent },
method: 'POST',
} );
} catch ( e ) {}
}
function* setStaticHomepageOnSite( siteID: number, pageId: number ) {
try {
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteID ) }/homepage`,
apiVersion: '1.1',
body: { is_page_on_front: true, page_on_front_id: pageId },
method: 'POST',
} );
} catch ( e ) {}
}
function* setGoalsOnSite( siteSlug: string, goals: SiteGoal[] ) {
try {
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteSlug ) }/site-goals`,
apiNamespace: 'wpcom/v2',
body: { site_goals: goals },
method: 'POST',
} );
} catch ( e ) {}
}
function* saveSiteTitle( siteId: number, blogname: string | undefined ) {
yield saveSiteSettings( siteId, { blogname } );
}
function* saveSiteTagline( siteId: number, blogdescription: string | undefined ) {
yield saveSiteSettings( siteId, { blogdescription } );
}
function* installTheme( siteSlugOrId: string | string, themeSlug: string ) {
yield wpcomRequest( {
path: `/sites/${ siteSlugOrId }/themes/${ themeSlug }/install`,
apiVersion: '1.1',
method: 'POST',
} );
}
function* runThemeSetupOnSite( siteSlug: string ) {
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteSlug ) }/theme-setup/?_locale=user`,
apiNamespace: 'wpcom/v2',
method: 'POST',
} );
}
/**
* Set the design on the site.
* @param siteSlug The site slug.
* @param selectedDesign The selected design.
* @param options The options.
* @returns The activated theme.
* @yields Yields effects for theme activation and global styles reset, including API calls and Redux actions.
*/
function* setDesignOnSite(
siteSlug: string,
selectedDesign: Design,
options: DesignOptions = {}
) {
const themeSlug =
selectedDesign.slug ||
selectedDesign.recipe?.stylesheet?.split( '/' )[ 1 ] ||
selectedDesign.theme;
const { styleVariation, globalStyles, enableThemeSetup } = options;
const activatedTheme: ActiveTheme = yield wpcomRequest( {
path: `/sites/${ siteSlug }/themes/mine?_locale=user`,
apiVersion: '1.1',
body: {
theme: themeSlug,
},
method: 'POST',
} );
const activatedThemeId = activatedTheme.stylesheet ?? activatedTheme.id;
if ( styleVariation?.slug === DEFAULT_GLOBAL_STYLES_VARIATION_SLUG ) {
yield* resetGlobalStyles( siteSlug, activatedThemeId, activatedTheme );
}
// @todo Always use the global styles for consistency
else if ( styleVariation?.slug ) {
const variations: GlobalStyles[] = yield* getGlobalStylesVariations(
siteSlug,
activatedThemeId
);
const currentVariation = variations.find(
( variation ) =>
variation.title &&
variation.title.split( ' ' ).join( '-' ).toLowerCase() === styleVariation?.slug
);
if ( currentVariation ) {
yield* setGlobalStyles( siteSlug, activatedThemeId, currentVariation, activatedTheme );
}
}
if ( globalStyles ) {
yield* setGlobalStyles( siteSlug, activatedThemeId, globalStyles, activatedTheme );
}
// Potentially runs Headstart.
// E.g. if the homepage has a Query Loop block, we insert placeholder posts on the new site.
if ( enableThemeSetup ) {
yield* runThemeSetupOnSite( siteSlug );
}
return activatedTheme;
}
function* createCustomTemplate(
siteSlug: string,
stylesheet: string,
slug: string,
title: string,
content: string
) {
const templateId = `${ stylesheet }//${ slug }`;
let existed = true;
try {
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteSlug ) }/templates/${ templateId }`,
apiNamespace: 'wp/v2',
method: 'GET',
} );
} catch {
existed = false;
}
const templatePath = `templates/${ existed ? templateId : '' }`;
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteSlug ) }/${ templatePath }`,
apiNamespace: 'wp/v2',
body: {
slug,
theme: stylesheet,
title,
content,
status: 'publish',
is_wp_suggestion: true,
},
method: 'POST',
} );
}
function* assembleSite(
siteSlug: string,
stylesheet = '',
{
homeHtml,
headerHtml,
footerHtml,
pages,
globalStyles,
canReplaceContent,
siteSetupOption,
}: AssembleSiteOptions = {}
) {
const templates = [
{
type: 'wp_template' as const,
slug: 'home',
title: __( 'Home' ),
content: createCustomHomeTemplateContent(
stylesheet,
!! headerHtml,
!! footerHtml,
!! homeHtml,
homeHtml
),
},
headerHtml && {
type: 'wp_template_part' as const,
slug: 'header',
title: __( 'Header' ),
content: headerHtml,
},
footerHtml && {
type: 'wp_template_part' as const,
slug: 'footer',
title: __( 'Footer' ),
content: footerHtml,
},
].filter( Boolean ) as RequestTemplate[];
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteSlug ) }/site-assembler`,
apiNamespace: 'wpcom/v2',
body: {
templates,
pages,
global_styles: globalStyles,
can_replace_content: canReplaceContent,
site_setup_option: siteSetupOption,
},
method: 'POST',
} );
}
const setSiteSetupError = ( error: string, message: string ) => ( {
type: 'SET_SITE_SETUP_ERROR',
error,
message,
} );
const clearSiteSetupError = ( siteId: number ) => ( {
type: 'CLEAR_SITE_SETUP_ERROR',
siteId,
} );
const atomicTransferStart = (
siteId: number,
softwareSet: string | undefined,
transferIntent: string | undefined
) => ( {
type: 'ATOMIC_TRANSFER_START' as const,
siteId,
softwareSet,
transferIntent,
} );
const atomicTransferSuccess = (
siteId: number,
softwareSet: string | undefined,
transferIntent: string | undefined
) => ( {
type: 'ATOMIC_TRANSFER_SUCCESS' as const,
siteId,
softwareSet,
transferIntent,
} );
const atomicTransferFailure = (
siteId: number,
softwareSet: string | undefined,
error: AtomicTransferErrorType
) => ( {
type: 'ATOMIC_TRANSFER_FAILURE' as const,
siteId,
softwareSet,
error,
} );
function* initiateAtomicTransfer(
siteId: number,
softwareSet: string | undefined,
transferIntent: string | undefined
) {
yield atomicTransferStart( siteId, softwareSet, transferIntent );
try {
const body = {
context: softwareSet || 'unknown',
software_set: softwareSet ? encodeURIComponent( softwareSet ) : undefined,
transfer_intent: transferIntent ? encodeURIComponent( transferIntent ) : undefined,
};
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteId ) }/atomic/transfers`,
apiNamespace: 'wpcom/v2',
method: 'POST',
body,
} );
yield atomicTransferSuccess( siteId, softwareSet, transferIntent );
} catch ( _ ) {
yield atomicTransferFailure( siteId, softwareSet, AtomicTransferError.INTERNAL );
}
}
const latestAtomicTransferStart = ( siteId: number ) => ( {
type: 'LATEST_ATOMIC_TRANSFER_START' as const,
siteId,
} );
const latestAtomicTransferSuccess = ( siteId: number, transfer: LatestAtomicTransfer ) => ( {
type: 'LATEST_ATOMIC_TRANSFER_SUCCESS' as const,
siteId,
transfer,
} );
const latestAtomicTransferFailure = (
siteId: number,
error: LatestAtomicTransferErrorType
) => ( {
type: 'LATEST_ATOMIC_TRANSFER_FAILURE' as const,
siteId,
error,
} );
function* requestLatestAtomicTransfer( siteId: number ) {
yield latestAtomicTransferStart( siteId );
try {
const transfer: LatestAtomicTransfer = yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteId ) }/atomic/transfers/latest`,
apiNamespace: 'wpcom/v2',
method: 'GET',
} );
yield latestAtomicTransferSuccess( siteId, transfer );
} catch ( err ) {
yield latestAtomicTransferFailure( siteId, err as LatestAtomicTransferError );
}
}
const atomicSoftwareStatusStart = ( siteId: number, softwareSet: string ) => ( {
type: 'ATOMIC_SOFTWARE_STATUS_START' as const,
siteId,
softwareSet,
} );
const atomicSoftwareStatusSuccess = (
siteId: number,
softwareSet: string,
status: AtomicSoftwareStatus
) => ( {
type: 'ATOMIC_SOFTWARE_STATUS_SUCCESS' as const,
siteId,
softwareSet,
status,
} );
const atomicSoftwareStatusFailure = (
siteId: number,
softwareSet: string,
error: AtomicSoftwareStatusErrorType
) => ( {
type: 'ATOMIC_SOFTWARE_STATUS_FAILURE' as const,
siteId,
softwareSet,
error,
} );
function* requestAtomicSoftwareStatus( siteId: number, softwareSet: string ) {
yield atomicSoftwareStatusStart( siteId, softwareSet );
try {
const status: AtomicSoftwareStatus = yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteId ) }/atomic/software/${ encodeURIComponent(
softwareSet
) }`,
apiNamespace: 'wpcom/v2',
method: 'GET',
} );
yield atomicSoftwareStatusSuccess( siteId, softwareSet, status );
} catch ( err ) {
yield atomicSoftwareStatusFailure( siteId, softwareSet, err as AtomicSoftwareStatusError );
}
}
const atomicSoftwareInstallStart = ( siteId: number, softwareSet: string ) => ( {
type: 'ATOMIC_SOFTWARE_INSTALL_START' as const,
siteId,
softwareSet,
} );
const atomicSoftwareInstallSuccess = ( siteId: number, softwareSet: string ) => ( {
type: 'ATOMIC_SOFTWARE_INSTALL_SUCCESS' as const,
siteId,
softwareSet,
} );
const atomicSoftwareInstallFailure = (
siteId: number,
softwareSet: string,
error: AtomicSoftwareInstallErrorType
) => ( {
type: 'ATOMIC_SOFTWARE_INSTALL_FAILURE' as const,
siteId,
softwareSet,
error,
} );
function* initiateSoftwareInstall( siteId: number, softwareSet: string ) {
yield atomicSoftwareInstallStart( siteId, softwareSet );
try {
yield wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteId ) }/atomic/software/${ encodeURIComponent(
softwareSet
) }`,
apiNamespace: 'wpcom/v2',
method: 'POST',
body: {},
} );
yield atomicSoftwareInstallSuccess( siteId, softwareSet );
} catch ( err ) {
yield atomicSoftwareInstallFailure( siteId, softwareSet, err as AtomicSoftwareInstallError );
}
}
const setBundledPluginSlug = ( siteSlug: string, pluginSlug: string ) => ( {
type: 'SET_BUNDLED_PLUGIN_SLUG' as const,
siteSlug,
pluginSlug,
} );
return {
receiveSiteDomains,
receiveSiteSettings,
receiveSiteTheme,
saveSiteTitle,
saveSiteSettings,
setIntentOnSite,
setStaticHomepageOnSite,
setGoalsOnSite,
receiveSiteTitle,
fetchNewSite,
fetchSite,
receiveNewSite,
receiveNewSiteFailed,
resetNewSiteFailed,
installTheme,
setDesignOnSite,
createCustomTemplate,
assembleSite,
createSite,
receiveSite,
receiveSiteFailed,
receiveSiteTagline,
receiveSiteVerticalId,
updateSiteSettings,
saveSiteTagline,
reset,
launchSite,
launchSiteStart,
launchSiteSuccess,
launchSiteFailure,
getCart,
setCart,
getGlobalStyles,
setGlobalStyles,
receiveSiteGlobalStyles,
setSiteSetupError,
clearSiteSetupError,
initiateAtomicTransfer,
atomicTransferStart,
atomicTransferSuccess,
atomicTransferFailure,
latestAtomicTransferStart,
latestAtomicTransferSuccess,
latestAtomicTransferFailure,
requestLatestAtomicTransfer,
atomicSoftwareStatusStart,
atomicSoftwareStatusSuccess,
atomicSoftwareStatusFailure,
requestAtomicSoftwareStatus,
initiateSoftwareInstall,
atomicSoftwareInstallStart,
atomicSoftwareInstallSuccess,
atomicSoftwareInstallFailure,
setBundledPluginSlug,
};
}
export type ActionCreators = ReturnType< typeof createActions >;
export type Action =
| ReturnType<
| ActionCreators[ 'fetchNewSite' ]
| ActionCreators[ 'fetchSite' ]
| ActionCreators[ 'receiveSiteDomains' ]
| ActionCreators[ 'receiveSiteSettings' ]
| ActionCreators[ 'receiveSiteTheme' ]
| ActionCreators[ 'receiveNewSite' ]
| ActionCreators[ 'receiveSiteTitle' ]
| ActionCreators[ 'receiveNewSiteFailed' ]
| ActionCreators[ 'receiveSiteTagline' ]
| ActionCreators[ 'receiveSiteVerticalId' ]
| ActionCreators[ 'receiveSite' ]
| ActionCreators[ 'receiveSiteFailed' ]
| ActionCreators[ 'updateSiteSettings' ]
| ActionCreators[ 'receiveSiteGlobalStyles' ]
| ActionCreators[ 'reset' ]
| ActionCreators[ 'resetNewSiteFailed' ]
| ActionCreators[ 'launchSiteStart' ]
| ActionCreators[ 'launchSiteSuccess' ]
| ActionCreators[ 'launchSiteFailure' ]
| ActionCreators[ 'atomicTransferStart' ]
| ActionCreators[ 'atomicTransferSuccess' ]
| ActionCreators[ 'atomicTransferFailure' ]
| ActionCreators[ 'latestAtomicTransferStart' ]
| ActionCreators[ 'latestAtomicTransferSuccess' ]
| ActionCreators[ 'latestAtomicTransferFailure' ]
| ActionCreators[ 'atomicSoftwareStatusStart' ]
| ActionCreators[ 'atomicSoftwareStatusSuccess' ]
| ActionCreators[ 'atomicSoftwareStatusFailure' ]
| ActionCreators[ 'atomicSoftwareInstallStart' ]
| ActionCreators[ 'atomicSoftwareInstallSuccess' ]
| ActionCreators[ 'atomicSoftwareInstallFailure' ]
| ActionCreators[ 'setBundledPluginSlug' ]
>
// Type added so we can dispatch actions in tests, but has no runtime cost
| { type: 'TEST_ACTION' };
|