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" />,
variant: 'success',
shouldShow: (row: any) => {
// Only show if images are generated and not already published/publishing
return row.status === 'complete' &&
(!row.wordpress_status ||
(row.wordpress_status !== 'published' && row.wordpress_status !== 'publishing'));
// Only show if content is completed and not already published to WordPress
return row.status === 'published' &&
(!row.external_id || !row.external_url) &&
(!row.sync_status || row.sync_status !== 'published');
},
},
{

View File

@@ -13,7 +13,7 @@ import {
generateImages,
bulkUpdateImagesStatus,
ContentImage,
api,
fetchAPI,
} from '../../services/api';
import { useToast } from '../../components/ui/toast/ToastContainer';
import { FileIcon, DownloadIcon, BoltIcon, TaskIcon, ImageIcon, CheckCircleIcon } from '../../icons';
@@ -208,27 +208,44 @@ export default function Images() {
// Bulk action handler
const handleBulkAction = useCallback(async (action: string, ids: string[]) => {
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
.filter(item => ids.includes(item.content_id.toString()))
.filter(item => item.status === 'complete' &&
(!item.wordpress_status ||
(item.wordpress_status !== 'published' && item.wordpress_status !== 'publishing')));
.filter(item => item.status === 'published' &&
(!item.external_id || !item.external_url) &&
(!item.sync_status || item.sync_status !== 'published'));
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;
}
try {
const response = await api.post('/api/wordpress/bulk-publish/', {
content_ids: readyItems.map(item => item.content_id.toString())
let successCount = 0;
let failedCount = 0;
// Publish each item individually using the unified publisher API
for (const item of readyItems) {
try {
const response = await fetchAPI('/v1/publisher/publish/', {
method: 'POST',
body: JSON.stringify({
content_id: item.content_id,
destinations: ['wordpress']
})
});
if (response.data.success) {
const results = response.data.data.results;
const successCount = results.filter((r: any) => r.success).length;
const failedCount = results.filter((r: any) => !r.success).length;
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 (successCount > 0) {
toast.success(`Successfully published ${successCount} item(s) to WordPress`);
@@ -239,9 +256,6 @@ export default function Images() {
// Reload images to reflect the updated WordPress status
loadImages();
} else {
toast.error(`Bulk publish failed: ${response.data.message}`);
}
} catch (error: any) {
console.error('Bulk WordPress publish error:', 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') {
// Handle WordPress publishing for individual item
try {
const response = await api.post('/api/wordpress/publish/', {
content_id: row.content_id.toString()
const response = await fetchAPI('/v1/publisher/publish/', {
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`);
// Reload images to reflect the updated WordPress status
loadImages();
} else {
toast.error(`Failed to publish: ${response.data.message}`);
toast.error(`Failed to publish: ${response.error || response.message}`);
}
} catch (error: any) {
console.error('WordPress publish error:', error);