File "cta-action.js"

Full Path: /home/exogold/public_html/wp-content/plugins/extendify/src/Notifications/cta-action.js
File size: 584 bytes
MIME-type: text/x-java
Charset: utf-8

import apiFetch from '@wordpress/api-fetch';

// The feed has no positive marker for an in-place CTA, only the trigger.
const ACTIONS = {
	unpublished: '/extendify/v1/site-visibility/publish',
	'search-engine-block': '/extendify/v1/search-indexing/enable',
};

export const ctaActionFor = (notification) =>
	ACTIONS[notification?.trigger] ?? null;

export const runCtaAction = (path, onClick) => {
	onClick();
	// Reload on failure too: the saved option decides what renders, not this click.
	return apiFetch({ path, method: 'POST' }).finally(() =>
		window.location.reload(),
	);
};