This commit is contained in:
alorig
2025-11-28 14:21:38 +05:00
parent e360c5fede
commit 8103c20341
2 changed files with 50 additions and 32 deletions

View File

@@ -327,10 +327,10 @@ const tableActionsConfigs: Record<string, TableActionsConfig> = {
icon: <ArrowRightIcon className="w-5 h-5" />, icon: <ArrowRightIcon className="w-5 h-5" />,
variant: 'success', variant: 'success',
shouldShow: (row: any) => { shouldShow: (row: any) => {
// Only show if images are generated and not already published/publishing // Only show if content is completed and not already published to WordPress
return row.status === 'complete' && return row.status === 'published' &&
(!row.wordpress_status || (!row.external_id || !row.external_url) &&
(row.wordpress_status !== 'published' && row.wordpress_status !== 'publishing')); (!row.sync_status || row.sync_status !== 'published');
}, },
}, },
{ {

View File

@@ -13,7 +13,7 @@ import {
generateImages, generateImages,
bulkUpdateImagesStatus, bulkUpdateImagesStatus,
ContentImage, ContentImage,
api, fetchAPI,
} from '../../services/api'; } from '../../services/api';
import { useToast } from '../../components/ui/toast/ToastContainer'; import { useToast } from '../../components/ui/toast/ToastContainer';
import { FileIcon, DownloadIcon, BoltIcon, TaskIcon, ImageIcon, CheckCircleIcon } from '../../icons'; import { FileIcon, DownloadIcon, BoltIcon, TaskIcon, ImageIcon, CheckCircleIcon } from '../../icons';
@@ -208,40 +208,54 @@ export default function Images() {
// Bulk action handler // Bulk action handler
const handleBulkAction = useCallback(async (action: string, ids: string[]) => { const handleBulkAction = useCallback(async (action: string, ids: string[]) => {
if (action === 'bulk_publish_wordpress') { if (action === 'bulk_publish_wordpress') {
// Filter to only publish items that have images generated and are not already published // Filter to only publish items that are ready and not already published
const readyItems = images const readyItems = images
.filter(item => ids.includes(item.content_id.toString())) .filter(item => ids.includes(item.content_id.toString()))
.filter(item => item.status === 'complete' && .filter(item => item.status === 'published' &&
(!item.wordpress_status || (!item.external_id || !item.external_url) &&
(item.wordpress_status !== 'published' && item.wordpress_status !== 'publishing'))); (!item.sync_status || item.sync_status !== 'published'));
if (readyItems.length === 0) { if (readyItems.length === 0) {
toast.warning('No items are ready for WordPress publishing. Items must have generated images and not already be published.'); toast.warning('No items are ready for WordPress publishing. Items must be published and not already synced to WordPress.');
return; return;
} }
try { try {
const response = await api.post('/api/wordpress/bulk-publish/', { let successCount = 0;
content_ids: readyItems.map(item => item.content_id.toString()) let failedCount = 0;
});
if (response.data.success) { // Publish each item individually using the unified publisher API
const results = response.data.data.results; for (const item of readyItems) {
const successCount = results.filter((r: any) => r.success).length; try {
const failedCount = results.filter((r: any) => !r.success).length; const response = await fetchAPI('/v1/publisher/publish/', {
method: 'POST',
if (successCount > 0) { body: JSON.stringify({
toast.success(`Successfully published ${successCount} item(s) to WordPress`); content_id: item.content_id,
destinations: ['wordpress']
})
});
if (response.success) {
successCount++;
} else {
failedCount++;
console.warn(`Failed to publish content ${item.content_id}:`, response.error);
}
} catch (error) {
failedCount++;
console.error(`Error publishing content ${item.content_id}:`, error);
} }
if (failedCount > 0) {
toast.warning(`${failedCount} item(s) failed to publish`);
}
// Reload images to reflect the updated WordPress status
loadImages();
} else {
toast.error(`Bulk publish failed: ${response.data.message}`);
} }
if (successCount > 0) {
toast.success(`Successfully published ${successCount} item(s) to WordPress`);
}
if (failedCount > 0) {
toast.warning(`${failedCount} item(s) failed to publish`);
}
// Reload images to reflect the updated WordPress status
loadImages();
} catch (error: any) { } catch (error: any) {
console.error('Bulk WordPress publish error:', error); console.error('Bulk WordPress publish error:', error);
toast.error(`Failed to bulk publish to WordPress: ${error.message || 'Network error'}`); toast.error(`Failed to bulk publish to WordPress: ${error.message || 'Network error'}`);
@@ -260,16 +274,20 @@ export default function Images() {
} else if (action === 'publish_wordpress') { } else if (action === 'publish_wordpress') {
// Handle WordPress publishing for individual item // Handle WordPress publishing for individual item
try { try {
const response = await api.post('/api/wordpress/publish/', { const response = await fetchAPI('/v1/publisher/publish/', {
content_id: row.content_id.toString() method: 'POST',
body: JSON.stringify({
content_id: row.content_id,
destinations: ['wordpress']
})
}); });
if (response.data.success) { if (response.success) {
toast.success(`Successfully published "${row.content_title}" to WordPress`); toast.success(`Successfully published "${row.content_title}" to WordPress`);
// Reload images to reflect the updated WordPress status // Reload images to reflect the updated WordPress status
loadImages(); loadImages();
} else { } else {
toast.error(`Failed to publish: ${response.data.message}`); toast.error(`Failed to publish: ${response.error || response.message}`);
} }
} catch (error: any) { } catch (error: any) {
console.error('WordPress publish error:', error); console.error('WordPress publish error:', error);