Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/components/publish-site-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ import { useI18n } from '@wordpress/react-i18n';
import { useCallback } from 'react';
import { useSyncSites } from 'src/hooks/sync-sites';
import { useAuth } from 'src/hooks/use-auth';
import { useContentTabs } from 'src/hooks/use-content-tabs';
import { useSiteDetails } from 'src/hooks/use-site-details';
import { generateCheckoutUrl } from 'src/lib/generate-checkout-url';
import { getIpcApi } from 'src/lib/get-ipc-api';
import { ConnectButton } from 'src/modules/sync/components/connect-button';
import { useAppDispatch } from 'src/stores';
import {
connectedSitesActions,
useGetConnectedSitesForLocalSiteQuery,
} from 'src/stores/sync/connected-sites';
import { useGetConnectedSitesForLocalSiteQuery } from 'src/stores/sync/connected-sites';

export const PublishSiteButton = () => {
const { __ } = useI18n();
const dispatch = useAppDispatch();
const { setSelectedTab } = useContentTabs();
const { user, authenticate } = useAuth();
const { user } = useAuth();
const { selectedSite } = useSiteDetails();
const { data: connectedSites = [] } = useGetConnectedSitesForLocalSiteQuery( {
localSiteId: selectedSite?.id,
Expand All @@ -26,12 +21,8 @@ export const PublishSiteButton = () => {
const isAnySiteSyncing = isAnySitePulling || isAnySitePushing;

const handlePublishClick = useCallback( () => {
if ( ! user ) {
authenticate();
}
dispatch( connectedSitesActions.openModal( 'push' ) );
setSelectedTab( 'sync' );
}, [ user, setSelectedTab, dispatch, authenticate ] );
getIpcApi().openURL( generateCheckoutUrl( selectedSite ?? undefined ) );
Comment thread
katinthehatsite marked this conversation as resolved.
}, [ selectedSite ] );

if ( connectedSites.length !== 0 ) return null;

Expand Down
20 changes: 20 additions & 0 deletions src/lib/generate-checkout-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { DEFAULT_CUSTOM_DOMAIN_SUFFIX } from 'common/constants';

export function generateCheckoutUrl( selectedSite?: SiteDetails ): string {
const url = new URL(
'https://wordpress.com/setup/new-hosted-site?ref=studio&section=studio-sync&showDomainStep'
Comment on lines +3 to +5

@sejas sejas Dec 17, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@katinthehatsite, can we pass the section as a parameter? Currently it's hardcoded to &section=studio-sync, but I would like the Publish site button to have a different section in the URL so we can measure the amount of "clicks" on this button.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will adress these comments in a follow up PR 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adressed in #2283

);

if ( ! selectedSite ) {
return url.toString();
}

const suggestedName = selectedSite.customDomain
? selectedSite.customDomain.replace( DEFAULT_CUSTOM_DOMAIN_SUFFIX, '' )
: selectedSite.name;

url.searchParams.set( 'studioSiteId', String( selectedSite.id ) );
url.searchParams.set( 'new', suggestedName );

return url.toString();
}
20 changes: 1 addition & 19 deletions src/modules/sync/components/create-button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { __ } from '@wordpress/i18n';
import { DEFAULT_CUSTOM_DOMAIN_SUFFIX } from 'common/constants';
import { ArrowIcon } from 'src/components/arrow-icon';
import Button, { ButtonVariant } from 'src/components/button';
import offlineIcon from 'src/components/offline-icon';
import { Tooltip } from 'src/components/tooltip';
import { useOffline } from 'src/hooks/use-offline';
import { cx } from 'src/lib/cx';
import { generateCheckoutUrl } from 'src/lib/generate-checkout-url';
Comment thread
katinthehatsite marked this conversation as resolved.
import { getIpcApi } from 'src/lib/get-ipc-api';

interface CreateButtonProps {
Expand All @@ -24,24 +24,6 @@ export const CreateButton = ( {
onClick,
}: CreateButtonProps ) => {
const isOffline = useOffline();
function generateCheckoutUrl( selectedSite?: SiteDetails ): string {
const url = new URL(
'https://wordpress.com/setup/new-hosted-site?ref=studio&section=studio-sync&showDomainStep'
);

if ( ! selectedSite ) {
return url.toString();
}

const suggestedName = selectedSite.customDomain
? selectedSite.customDomain.replace( DEFAULT_CUSTOM_DOMAIN_SUFFIX, '' )
: selectedSite.name;

url.searchParams.set( 'studioSiteId', String( selectedSite.id ) );
url.searchParams.set( 'new', suggestedName );

return url.toString();
}

return (
<Tooltip
Expand Down