ai fucntiosn adn otehr atuoamtion fixes

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-14 23:08:48 +00:00
parent cb2d109593
commit 6bb3dd3df4
11 changed files with 1289 additions and 197 deletions

View File

@@ -85,6 +85,47 @@ const AutomationPage: React.FC = () => {
// Track site ID to avoid duplicate calls when activeSite object reference changes
const siteId = activeSite?.id;
/**
* Calculate time remaining until next scheduled run
* Returns formatted string like "in 5h 23m" or "in 2d 3h"
*/
const getNextRunTime = (config: AutomationConfig): string => {
if (!config.is_enabled || !config.scheduled_time) return '';
const now = new Date();
const [schedHours, schedMinutes] = config.scheduled_time.split(':').map(Number);
// Create next run date
const nextRun = new Date();
nextRun.setUTCHours(schedHours, schedMinutes, 0, 0);
// If scheduled time has passed today, set to tomorrow
if (nextRun <= now) {
if (config.frequency === 'daily') {
nextRun.setUTCDate(nextRun.getUTCDate() + 1);
} else if (config.frequency === 'weekly') {
nextRun.setUTCDate(nextRun.getUTCDate() + 7);
}
}
// Calculate difference in milliseconds
const diff = nextRun.getTime() - now.getTime();
const totalMinutes = Math.floor(diff / (1000 * 60));
const totalHours = Math.floor(totalMinutes / 60);
const days = Math.floor(totalHours / 24);
const remainingHours = totalHours % 24;
const remainingMinutes = totalMinutes % 60;
// Format output
if (days > 0) {
return `in ${days}d ${remainingHours}h`;
} else if (remainingHours > 0) {
return `in ${remainingHours}h ${remainingMinutes}m`;
} else {
return `in ${remainingMinutes}m`;
}
};
useEffect(() => {
if (!siteId) return;
// Reset state when site changes
@@ -547,6 +588,14 @@ const AutomationPage: React.FC = () => {
<div className="text-sm text-white/80">
Last: <span className="font-medium">{config.last_run_at ? new Date(config.last_run_at).toLocaleDateString() : 'Never'}</span>
</div>
{config.is_enabled && (
<>
<div className="h-4 w-px bg-white/25"></div>
<div className="text-sm text-white/90">
Next: <span className="font-medium">{getNextRunTime(config)}</span>
</div>
</>
)}
<div className="h-4 w-px bg-white/25"></div>
<div className="text-sm text-white/90">
<span className="font-medium">Est:</span>{' '}