phase 4-6 - with buggy contetn calendar page
This commit is contained in:
@@ -636,8 +636,14 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
const date = new Date(content.scheduled_publish_at);
|
||||
const localDateTime = date.toISOString().slice(0, 16);
|
||||
setScheduleDateTime(localDateTime);
|
||||
} else if (content?.site_status === 'failed') {
|
||||
// Default to tomorrow at 9 AM for failed items without a schedule
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
tomorrow.setHours(9, 0, 0, 0);
|
||||
setScheduleDateTime(tomorrow.toISOString().slice(0, 16));
|
||||
}
|
||||
}, [content?.scheduled_publish_at]);
|
||||
}, [content?.scheduled_publish_at, content?.site_status]);
|
||||
|
||||
// Handler to update schedule
|
||||
const handleUpdateSchedule = async () => {
|
||||
@@ -646,11 +652,22 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
setIsUpdatingSchedule(true);
|
||||
try {
|
||||
const isoDateTime = new Date(scheduleDateTime).toISOString();
|
||||
await fetchAPI(`/v1/writer/content/${content.id}/schedule/`, {
|
||||
|
||||
// Use reschedule endpoint for failed items, schedule endpoint for scheduled items
|
||||
const endpoint = content.site_status === 'failed'
|
||||
? `/v1/writer/content/${content.id}/reschedule/`
|
||||
: `/v1/writer/content/${content.id}/schedule/`;
|
||||
|
||||
const body = content.site_status === 'failed'
|
||||
? JSON.stringify({ scheduled_at: isoDateTime })
|
||||
: JSON.stringify({ scheduled_publish_at: isoDateTime });
|
||||
|
||||
await fetchAPI(endpoint, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ scheduled_publish_at: isoDateTime }),
|
||||
body,
|
||||
});
|
||||
toast.success('Schedule updated successfully');
|
||||
|
||||
toast.success(content.site_status === 'failed' ? 'Content rescheduled successfully' : 'Schedule updated successfully');
|
||||
setIsEditingSchedule(false);
|
||||
// Trigger content refresh by reloading the page
|
||||
window.location.reload();
|
||||
@@ -1180,8 +1197,8 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Schedule Date/Time Editor - Only for scheduled content */}
|
||||
{content.site_status === 'scheduled' && (
|
||||
{/* Schedule Date/Time Editor - For scheduled and failed content */}
|
||||
{(content.site_status === 'scheduled' || content.site_status === 'failed') && (
|
||||
<div className="flex items-center gap-2">
|
||||
{isEditingSchedule ? (
|
||||
<>
|
||||
@@ -1198,7 +1215,7 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
onClick={handleUpdateSchedule}
|
||||
disabled={isUpdatingSchedule || !scheduleDateTime}
|
||||
>
|
||||
{isUpdatingSchedule ? 'Updating...' : 'Update'}
|
||||
{isUpdatingSchedule ? 'Updating...' : content.site_status === 'failed' ? 'Reschedule' : 'Update'}
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
@@ -1206,10 +1223,16 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
tone="neutral"
|
||||
onClick={() => {
|
||||
setIsEditingSchedule(false);
|
||||
// Reset to original value
|
||||
// Reset to original value or tomorrow if failed
|
||||
if (content.scheduled_publish_at) {
|
||||
const date = new Date(content.scheduled_publish_at);
|
||||
setScheduleDateTime(date.toISOString().slice(0, 16));
|
||||
} else if (content.site_status === 'failed') {
|
||||
// Default to tomorrow for failed items
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
tomorrow.setHours(9, 0, 0, 0);
|
||||
setScheduleDateTime(tomorrow.toISOString().slice(0, 16));
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -1219,12 +1242,17 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
) : (
|
||||
<>
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{content.scheduled_publish_at ? formatDate(content.scheduled_publish_at) : ''}
|
||||
{content.site_status === 'failed' && (
|
||||
content.scheduled_publish_at ? `Was scheduled: ${formatDate(content.scheduled_publish_at)}` : 'Not scheduled'
|
||||
)}
|
||||
{content.site_status === 'scheduled' && (
|
||||
content.scheduled_publish_at ? formatDate(content.scheduled_publish_at) : ''
|
||||
)}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setIsEditingSchedule(true)}
|
||||
className="text-brand-600 hover:text-brand-700 dark:text-brand-400 dark:hover:text-brand-300 p-1"
|
||||
title="Edit schedule"
|
||||
title={content.site_status === 'failed' ? 'Reschedule' : 'Edit schedule'}
|
||||
>
|
||||
<PencilIcon className="w-4 h-4" />
|
||||
</button>
|
||||
@@ -1233,6 +1261,15 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Error message for failed items */}
|
||||
{content.site_status === 'failed' && content.site_status_message && (
|
||||
<div className="flex items-center gap-2 px-3 py-1 bg-red-50 dark:bg-red-900/20 rounded border border-red-200 dark:border-red-800">
|
||||
<span className="text-xs text-red-600 dark:text-red-400">
|
||||
{content.site_status_message}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{content.external_url && content.site_status === 'published' && (
|
||||
<a
|
||||
href={content.external_url}
|
||||
|
||||
Reference in New Issue
Block a user