Skip to content

Commit

Permalink
MU WPCOM: Fix sharing modal "recommended tags" feature (#39175)
Browse files Browse the repository at this point in the history
* Use correct endpoint for adding tags on new post

* changelog

* Use  with correct route

* Add busy state to button
  • Loading branch information
rafaelgallani authored Sep 9, 2024
1 parent 1662c02 commit 476830b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Use the correct endpoint route for adding suggested tags on new posts.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLocale } from '@automattic/i18n-utils';
import { Button, FormTokenField } from '@wordpress/components';
import { TokenItem } from '@wordpress/components/build-types/form-token-field/types';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { __, _n } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import * as React from 'react';
Expand Down Expand Up @@ -77,6 +77,7 @@ function SuggestedTags( props: SuggestedTagsProps ) {
props.setShouldShowSuggestedTags( false );
};
const { saveTags } = useAddTagsToPost( postId, selectedTags, onAddTagsButtonClick );
const [ isSavingTags, setIsSavingTags ] = useState( false );

useEffect( () => {
if ( origSuggestedTags?.length === 0 ) {
Expand Down Expand Up @@ -119,8 +120,13 @@ function SuggestedTags( props: SuggestedTagsProps ) {
<p>{ __( 'Adding tags can help drive more traffic to your post.', 'jetpack-mu-wpcom' ) }</p>
<Button
className="wpcom-block-editor-post-published-sharing-modal__save-tags"
onClick={ saveTags }
onClick={ async () => {
setIsSavingTags( true );
await saveTags();
setIsSavingTags( false );
} }
variant="primary"
isBusy={ isSavingTags }
>
{ __( 'Add these tags', 'jetpack-mu-wpcom' ) }
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const useAddTagsToPost = ( postId: number, tags: string[], onSaveTags: OnSaveTag
try {
const result: HasAddedTagsResult = await apiFetch( {
method: 'POST',
path: `/wpcom/v2/read/posts/${ postId }/tags/add`,
path: `/wpcom/v2/read/sites/${ window._currentSiteId }/posts/${ postId }/tags/add`,
data: { tags },
} );
addedTags = result.added_tags ?? 0;
Expand Down

0 comments on commit 476830b

Please sign in to comment.