Skip to content

Commit

Permalink
fix urls, translate
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 7, 2025
1 parent b0646aa commit 4fad786
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function load_wpcom_dashboard_widgets() {
}

$layout_response = Client::wpcom_json_api_request_as_blog(
'/sites/' . get_current_blog_id() . '/home/layout',
'/sites/' . get_wpcom_blog_id() . '/home/layout',
'v2',
array(),
null,
Expand Down Expand Up @@ -119,7 +119,6 @@ function enqueue_wpcom_dashboard_widgets( $args = array() ) {
'siteIntent' => get_option( 'site_intent' ),
'sitePlan' => $current_plan,
'hasCustomDomain' => wpcom_site_has_feature( 'custom-domain' ),
'siteId' => get_current_blog_id(),
'tasks' => $args['tasks'],
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,34 @@ const taskMap = {
'home-task-domain-upsell': TaskDomainUpsell,
};

export default ( { tasks } ) => {
export default ( { tasks, ...props } ) => {
const availableTasks = tasks.filter( _task => taskMap[ _task ] );
const [ index, setIndex ] = useState( 0 );
const task = tasks[ index ];
const task = availableTasks[ index ];
const TaskComponent = taskMap[ task ];

return (
<>
<p className="wpcom_general_tasks_widget_buttons">
<button
className="button button-link"
onClick={ () => setIndex( index - 1 ) }
disabled={ index === 0 }
>
{ __( '← Previous', 'jetpack-mu-wpcom' ) }
</button>
{ ' ' }
<button
className="button button-link"
onClick={ () => setIndex( index + 1 ) }
disabled={ index === tasks.length - 1 }
>
{ __( 'Next →', 'jetpack-mu-wpcom' ) }
</button>
</p>
{ TaskComponent ? <TaskComponent /> : <p style={ { minHeight: '180px' } }>[{ task }]</p> }
{ availableTasks.length > 1 && (
<p className="wpcom_general_tasks_widget_buttons">
<button
className="button button-link"
onClick={ () => setIndex( index - 1 ) }
disabled={ index === 0 }
>
{ __( '← Previous', 'jetpack-mu-wpcom' ) }
</button>
{ ' ' }
<button
className="button button-link"
onClick={ () => setIndex( index + 1 ) }
disabled={ index === availableTasks.length - 1 }
>
{ __( 'Next →', 'jetpack-mu-wpcom' ) }
</button>
</p>
) }
<TaskComponent { ...props } />
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
export default () => {
// To do: actually fetch it from the API.
const domain = new URL( window.location.href ).hostname.split( '.' )[ 0 ] + '.com';
import apiFetch from '@wordpress/api-fetch';
import { useState, useEffect, createInterpolateElement } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';

export default ( { siteDomain, sitePlan } ) => {
const [ domains, setDomains ] = useState( [] );
useEffect( () => {
const path = addQueryArgs( `/rest/v1.1/domains/suggestions`, {
query: siteDomain.split( '.' )[ 0 ],
quantity: 1,
vendor: 'domain-upsell',
only_wordpressdotcom: false,
include_dotblogsubdomain: false,
include_wordpressdotcom: false,
} );
apiFetch( { path, global: true } ).then( setDomains );
}, [ siteDomain ] );

if ( domains.length === 0 ) {
return null;
}

const domain = domains[ 0 ].domain_name;
const cart = [ `domain_reg:${ domain }` ];

if ( ! sitePlan || sitePlan.product_slug.includes( 'monthly' ) ) {
cart.push( 'personal' );
}

const getLink = `http://wordpress.com/checkout/${ siteDomain }/${ cart.join( ',' ) }`;
const searchLink = addQueryArgs( `https://wordpress.com/domains/add/${ siteDomain }`, {
domainAndPlanPackage: true,
domain: true,
} );

return (
<>
<h2>Own a domain. Build a site.</h2>
<h2>{ __( 'Own a domain. Build a site.', 'jetpack-mu-wpcom' ) }</h2>
<p>
<strong>{ domain }</strong> is a perfect site address. It’s available, easy to find, share,
and follow. Get it now and claim a corner of the web.
{ createInterpolateElement(
sprintf(
// translators: %s is the domain name.
__(
'<strong>%s</strong> is a perfect site address. It’s available, easy to find, share, and follow. Get it now and claim a corner of the web.',
'jetpack-mu-wpcom'
),
domain
),
{
strong: <strong />,
}
) }
</p>
<p style={ { position: 'relative' } }>
{ /* To do: convert to SVG. */ }
Expand All @@ -26,12 +70,12 @@ export default () => {
/>
</p>
<div>
<a href="https://wordpress.com/domains/register" className="button button-primary">
Get this domain
<a href={ getLink } className="button button-primary">
{ __( 'Get this domain', 'jetpack-mu-wpcom' ) }
</a>
{ ' ' }
<a href="https://wordpress.com/domains/register" className="button button-secondary">
Find other domains
<a href={ searchLink } className="button button-secondary">
{ __( 'Find other domains', 'jetpack-mu-wpcom' ) }
</a>
</div>
</>
Expand Down
27 changes: 27 additions & 0 deletions projects/packages/jetpack-mu-wpcom/src/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,30 @@ function jetpack_mu_wpcom_enqueue_assets( $asset_name, $asset_types = array() )

return $asset_handle;
}

/**
* Returns the WP.com blog ID for the current site.
*
* @return int|false The WP.com blog ID, or false if the site does not have a WP.com blog ID.
*/
function get_wpcom_blog_id() {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
return get_current_blog_id();
}

if ( defined( 'IS_ATOMIC' ) && IS_ATOMIC ) {
/*
* Atomic sites have the WP.com blog ID stored as a Jetpack option. This
* code deliberately doesn't use `Jetpack_Options::get_option` so it
* works even when Jetpack has not been loaded.
*/
$jetpack_options = get_option( 'jetpack_options' );
if ( is_array( $jetpack_options ) && isset( $jetpack_options['id'] ) ) {
return (int) $jetpack_options['id'];
}

return get_current_blog_id();
}

return false;
}

0 comments on commit 4fad786

Please sign in to comment.