import React from 'react'; import { Modal } from '../ui/modal'; import Button from '../ui/button/Button'; import { ErrorIcon, CalendarIcon, BoltIcon, ExternalLinkIcon } from '../../icons'; import { formatDateTime } from '../../utils/date'; interface Content { id: number; title: string; site_status?: string; scheduled_publish_at?: string | null; site_status_updated_at?: string | null; site_status_message?: string | null; } interface Site { id: number; name: string; platform_type: string; } interface ErrorDetailsModalProps { isOpen: boolean; onClose: () => void; content: Content | null; site: Site | null; onPublishNow: () => void; onReschedule: () => void; onFixSettings: () => void; } const ErrorDetailsModal: React.FC = ({ isOpen, onClose, content, site, onPublishNow, onReschedule, onFixSettings }) => { if (!content || !site) return null; const formatDate = (isoString: string | null) => { if (!isoString) return 'N/A'; try { return formatDateTime(isoString); } catch (error) { return isoString; } }; const errorMessage = content.site_status_message || 'Publishing failed with no error message.'; // Parse error message to provide helpful suggestions const getErrorSuggestion = (error: string) => { const lowerError = error.toLowerCase(); if (lowerError.includes('credential') || lowerError.includes('authentication') || lowerError.includes('403')) { return 'The publishing site returned an authentication error. Please check the API key in Site Settings.'; } else if (lowerError.includes('timeout') || lowerError.includes('network')) { return 'The publishing site did not respond in time. Please check your internet connection and site availability.'; } else if (lowerError.includes('404') || lowerError.includes('not found')) { return 'The publishing endpoint was not found. Please verify the site URL in Site Settings.'; } else if (lowerError.includes('500') || lowerError.includes('server error')) { return 'The publishing site returned a server error. Please try again later or contact site support.'; } else if (lowerError.includes('required field') || lowerError.includes('missing')) { return 'Required fields are missing in the content. Please review and complete all necessary fields.'; } else if (lowerError.includes('rate limit')) { return 'Too many requests were sent to the publishing site. Please wait a few minutes and try again.'; } return null; }; const suggestion = getErrorSuggestion(errorMessage); const platformName = site.platform_type.charAt(0).toUpperCase() + site.platform_type.slice(1); return (
{/* Header */}

Publishing Error Details

Content failed to publish

{/* Content Details */}

Content:

"{content.title}"

Site:

{site.name} ({platformName})

{content.scheduled_publish_at && (

Scheduled:

{formatDate(content.scheduled_publish_at)}

)} {content.site_status_updated_at && (

Failed:

{formatDate(content.site_status_updated_at)}

)}
{/* Error Message */}

Error Message:

{errorMessage}

{/* Suggestion */} {suggestion && (

Suggestion:

{suggestion}

)} {/* Actions */}

Actions:

); }; export default ErrorDetailsModal;