Skip to content

Commit

Permalink
adds comments and refactor semrush request control
Browse files Browse the repository at this point in the history
  • Loading branch information
vraja-pro committed Dec 16, 2024
1 parent c710947 commit 949f269
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/js/src/redux/controls/SEMrushRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import apiFetch from "@wordpress/api-fetch";
import { addQueryArgs } from "@wordpress/url";

/**
* Control for handling SEMrush related keyphrases request.
* Control for handling SEMrush related keyphrases request nd saved the country code to the database.
*
* @param {Object} action The action object.
* @param {string} countryCode The country code to use.
* @param {string} keyphrase The keyphrase to use.
*
* @returns {Promise} The API fetch promise.
* @returns {Promise} The API fetch promise, when resolved,
* contains a list of related keyphrses with their search volumne, trends in recent year, search intent, and difficulty index.
*/
export const NEW_REQUEST = async( action ) => {
const { countryCode, keyphrase } = action;

await apiFetch( {
export const NEW_REQUEST = async( { countryCode, keyphrase } ) => {
// Saves the country code in the database.
apiFetch( {
path: "yoast/v1/semrush/country_code",
method: "POST",
// eslint-disable-next-line camelcase
data: { country_code: countryCode },
} );

const response = await apiFetch( {
return apiFetch( {
path: addQueryArgs(
"/yoast/v1/semrush/related_keyphrases",
{
Expand All @@ -28,6 +29,4 @@ export const NEW_REQUEST = async( action ) => {
}
),
} );

return response;
};

0 comments on commit 949f269

Please sign in to comment.