feat: Implement WordPress publishing and unpublishing actions

- Added conditional visibility for table actions based on content state (published/draft).
- Introduced `publishContent` and `unpublishContent` API functions for handling WordPress integration.
- Updated `Content` component to manage publish/unpublish actions with appropriate error handling and success notifications.
- Refactored `PostEditor` to remove deprecated SEO fields and consolidate taxonomy management.
- Enhanced `TablePageTemplate` to filter row actions based on visibility conditions.
- Updated backend API to support publishing and unpublishing content with proper status updates and external references.
This commit is contained in:
alorig
2025-11-26 01:24:58 +05:00
parent ba842d8332
commit 53ea0c34ce
13 changed files with 1249 additions and 417 deletions

View File

@@ -10,6 +10,8 @@ import {
Content as ContentType,
ContentFilters,
generateImagePrompts,
publishContent,
unpublishContent,
} from '../../services/api';
import { optimizerApi } from '../../api/optimizer.api';
import { useNavigate } from 'react-router';
@@ -162,7 +164,41 @@ export default function Content() {
const navigate = useNavigate();
const handleRowAction = useCallback(async (action: string, row: ContentType) => {
if (action === 'generate_image_prompts') {
if (action === 'publish') {
try {
// Check if already published
if (row.external_id) {
toast.warning('Content is already published to WordPress');
return;
}
const result = await publishContent(row.id);
toast.success(`Content published successfully! View at: ${result.external_url}`);
loadContent(); // Reload to show updated external_id
} catch (error: any) {
toast.error(`Failed to publish content: ${error.message}`);
}
} else if (action === 'view_on_wordpress') {
if (row.external_url) {
window.open(row.external_url, '_blank');
} else {
toast.warning('WordPress URL not available');
}
} else if (action === 'unpublish') {
try {
// Check if not published
if (!row.external_id) {
toast.warning('Content is not currently published');
return;
}
await unpublishContent(row.id);
toast.success('Content unpublished successfully');
loadContent(); // Reload to show cleared external_id
} catch (error: any) {
toast.error(`Failed to unpublish content: ${error.message}`);
}
} else if (action === 'generate_image_prompts') {
try {
const result = await generateImagePrompts([row.id]);
if (result.success) {