Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 31x 31x 31x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 3x 3x 10x 10x 10x 10x 10x 13x 5x 5x 5x 5x 5x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 9x 9x 9x 6x 6x 9x 9x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x | import { __, sprintf } from '@wordpress/i18n';
import type { TransferError } from './types.ts';
/** Eligibility error codes this page has copy for. */
export const EligibilityErrors = {
BLOCKED_ATOMIC_TRANSFER: 'blocked_atomic_transfer',
TRANSFER_ALREADY_EXISTS: 'transfer_already_exists',
NO_BUSINESS_PLAN: 'no_business_plan',
NO_JETPACK_SITES: 'no_jetpack_sites',
NO_VIP_SITES: 'no_vip_sites',
SITE_GRAYLISTED: 'site_graylisted',
NON_ADMIN_USER: 'non_admin_user',
NOT_RESOLVING_TO_WPCOM: 'not_resolving_to_wpcom',
NO_SSL_CERTIFICATE: 'no_ssl_certificate',
EMAIL_UNVERIFIED: 'email_unverified',
EXCESSIVE_DISK_SPACE: 'excessive_disk_space',
// wpcom builds this one from a literal rather than its own constant, and says "blog".
IS_STAGING_SITE: 'is_staging_blog',
} as const;
export type EligibilityErrorCode = ( typeof EligibilityErrors )[ keyof typeof EligibilityErrors ];
export type BlockingMessage = {
code: string;
message: string;
intent: 'error' | 'info';
supportUrl?: string;
};
export type HoldingMessage = {
code: string;
title: string;
description: string;
supportUrl?: string;
};
type MessageMap< T > = Partial< Record< EligibilityErrorCode, T > >;
let blockingMessages: MessageMap< BlockingMessage > | null = null;
let holdingMessages: MessageMap< HoldingMessage > | null = null;
/**
* Last-resort copy for an error the API sent with no message of its own.
*
* @return The message.
*/
function getGenericBlockingMessage(): string {
return __(
'This site is not currently eligible to activate this feature. Please contact our support team for help.',
'jetpack-mu-wpcom'
);
}
/**
* Errors that stop the transfer outright, shown as a single notice.
*
* Built on first call rather than at module scope so `__()` runs once the locale
* data is loaded, then cached
*
* @return The messages, keyed by error code.
*/
function getBlockingMessages(): MessageMap< BlockingMessage > {
blockingMessages ||= {
[ EligibilityErrors.BLOCKED_ATOMIC_TRANSFER ]: {
code: EligibilityErrors.BLOCKED_ATOMIC_TRANSFER,
message: getGenericBlockingMessage(),
intent: 'error',
},
[ EligibilityErrors.TRANSFER_ALREADY_EXISTS ]: {
code: EligibilityErrors.TRANSFER_ALREADY_EXISTS,
message: __(
'Setup in progress. Just a minute! Please wait until it is finished, then try again.',
'jetpack-mu-wpcom'
),
intent: 'info',
},
[ EligibilityErrors.NO_JETPACK_SITES ]: {
code: EligibilityErrors.NO_JETPACK_SITES,
message: __( 'Try using a different site.', 'jetpack-mu-wpcom' ),
intent: 'error',
},
[ EligibilityErrors.NO_VIP_SITES ]: {
code: EligibilityErrors.NO_VIP_SITES,
message: __( 'Try using a different site.', 'jetpack-mu-wpcom' ),
intent: 'error',
},
[ EligibilityErrors.SITE_GRAYLISTED ]: {
code: EligibilityErrors.SITE_GRAYLISTED,
message: __(
'There’s an ongoing site dispute. Contact us to review your site’s standing and resolve the dispute.',
'jetpack-mu-wpcom'
),
intent: 'error',
supportUrl: 'https://wordpress.com/support/suspended-blogs/',
},
[ EligibilityErrors.NO_SSL_CERTIFICATE ]: {
code: EligibilityErrors.NO_SSL_CERTIFICATE,
message: __(
'Certificate installation in progress. Hold tight! We are setting up a digital certificate to allow secure browsing on your site using "HTTPS".',
'jetpack-mu-wpcom'
),
intent: 'info',
},
};
return blockingMessages;
}
/**
* Errors the reader can clear themselves, listed as steps to take.
*
* @return The messages, keyed by error code.
*/
function getHoldingMessages(): MessageMap< HoldingMessage > {
holdingMessages ||= {
[ EligibilityErrors.NO_BUSINESS_PLAN ]: {
code: EligibilityErrors.NO_BUSINESS_PLAN,
title: sprintf(
/* translators: %s is a WordPress.com plan name, e.g. "Business". */
__( '%s plan required', 'jetpack-mu-wpcom' ),
'Business'
),
description: __(
'You’ll also get to install custom themes, plugins, and have more storage.',
'jetpack-mu-wpcom'
),
},
[ EligibilityErrors.NON_ADMIN_USER ]: {
code: EligibilityErrors.NON_ADMIN_USER,
title: __( 'Site administrator only', 'jetpack-mu-wpcom' ),
description: __( 'Only the site administrators can use this feature.', 'jetpack-mu-wpcom' ),
supportUrl: 'https://wordpress.com/support/user-roles/',
},
[ EligibilityErrors.NOT_RESOLVING_TO_WPCOM ]: {
code: EligibilityErrors.NOT_RESOLVING_TO_WPCOM,
title: __( 'Domain pointing to a different site', 'jetpack-mu-wpcom' ),
description: __(
'Your domain is not properly set up to point to your site. Reset your domain’s A records in the Domains section to fix this.',
'jetpack-mu-wpcom'
),
supportUrl: 'https://wordpress.com/support/move-domain/setting-custom-a-records/',
},
[ EligibilityErrors.EMAIL_UNVERIFIED ]: {
code: EligibilityErrors.EMAIL_UNVERIFIED,
title: __( 'Confirm your email address', 'jetpack-mu-wpcom' ),
description: __(
'Check your email for a message we sent you when you signed up. Click the link inside to confirm your email address. You may have to check your email client’s spam folder.',
'jetpack-mu-wpcom'
),
},
[ EligibilityErrors.EXCESSIVE_DISK_SPACE ]: {
code: EligibilityErrors.EXCESSIVE_DISK_SPACE,
title: __( 'Increase storage space', 'jetpack-mu-wpcom' ),
description: __(
'Your site does not have enough available storage space. Please purchase a plan with additional storage or contact our support team for help.',
'jetpack-mu-wpcom'
),
},
[ EligibilityErrors.IS_STAGING_SITE ]: {
code: EligibilityErrors.IS_STAGING_SITE,
title: __( 'Create a new staging site', 'jetpack-mu-wpcom' ),
description: __(
'This feature cannot be activated for a staging site. Create a new staging site to continue.',
'jetpack-mu-wpcom'
),
},
};
return holdingMessages;
}
/**
* Look a code up without matching inherited `Object.prototype` keys.
*
* @param messages - The message map to search.
* @param code - The error code, which may be any string the API sends.
* @return The message, or undefined.
*/
function lookUp< T >( messages: MessageMap< T >, code: string ): T | undefined {
return Object.hasOwn( messages, code ) ? messages[ code as EligibilityErrorCode ] : undefined;
}
/**
* The first error that stops the transfer outright, if any.
*
* A code with no copy here still has to explain itself, so it falls back to the
* API's own message and then to a generic line — never to an empty modal.
*
* @param errors - Eligibility errors.
* @return The matching message, or null.
*/
export function findFirstBlockingError( errors: TransferError[] ): BlockingMessage | null {
const messages = getBlockingMessages();
const known = errors.find( error => lookUp( messages, error.code ) );
if ( known ) {
return lookUp( messages, known.code ) ?? null;
}
// Holds render as their own list below, so they are not a gap to fill here.
const holds = getHoldingMessages();
const uncovered = errors.find( error => ! lookUp( holds, error.code ) );
if ( ! uncovered ) {
return null;
}
return {
code: uncovered.code,
message: uncovered.message || getGenericBlockingMessage(),
intent: 'error',
};
}
/**
* The errors the reader can clear themselves.
*
* @param errors - Eligibility errors.
* @return The matching messages, in the order the API returned them.
*/
export function findHoldingErrors( errors: TransferError[] ) {
const messages = getHoldingMessages();
return errors.reduce( ( acc: HoldingMessage[], err ) => {
const message = lookUp( messages, err.code );
if ( message ) {
acc.push( message );
}
return acc;
}, [] );
}
/**
* Whether any error stops the transfer outright.
*
* @param errors - Eligibility errors.
* @return Whether a blocking error is present.
*/
export function hasAnyBlockingError( errors: TransferError[] ) {
return findFirstBlockingError( errors ) !== null;
}
/**
* Whether the site needs a plan upgrade before it can be transferred.
*
* @param errors - Eligibility errors.
* @return Whether the plan is the only thing in the way.
*/
export function needsPlanUpgrade( errors: TransferError[] ) {
return errors.some( error => error.code === EligibilityErrors.NO_BUSINESS_PLAN );
}
/**
* Whether the confirmation modal has anything to say before the transfer starts.
*
* @param isEligible - Whether the site passed every transfer check.
* @param errors - Eligibility errors.
* @param warnings - Non-blocking transfer warnings.
* @return Whether the reader has to see the modal first.
*/
export function needsConfirmation(
isEligible: boolean,
errors: TransferError[],
warnings: unknown[]
) {
return ! isEligible || errors.length > 0 || warnings.length > 0;
}
/**
* Whether the reader can start the transfer. The plan is bought inside the
* flow, so a missing one is not a reason to hold them here.
*
* @param isEligible - Whether the site passed every transfer check.
* @param errors - Eligibility errors.
* @return Whether the call to action is actionable.
*/
export function canProceed( isEligible: boolean, errors: TransferError[] ) {
return isEligible || needsPlanUpgrade( errors );
}
|