fix: Custom cron input and auto-sync rescheduling
- Fixed custom cron input field to be properly editable with autoFocus - Added helpful cron examples and better validation feedback - Fixed cron validation to work with 5-field expressions (node-cron format) - Added auto-sync rescheduling when settings are saved via API route - Improved user experience with better error handling and examples The custom cron input now works properly and auto-sync will reschedule immediately when settings are saved, including custom cron expressions.
This commit is contained in:
@@ -885,6 +885,8 @@ export function GeneralSettingsModal({ isOpen, onClose }: GeneralSettingsModalPr
|
|||||||
value={syncIntervalCron}
|
value={syncIntervalCron}
|
||||||
onChange={(e) => handleCronChange(e.target.value)}
|
onChange={(e) => handleCronChange(e.target.value)}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
autoFocus
|
||||||
|
onFocus={() => setCronValidationError('')}
|
||||||
/>
|
/>
|
||||||
{cronValidationError && (
|
{cronValidationError && (
|
||||||
<p className="text-sm text-red-500 mt-1">{cronValidationError}</p>
|
<p className="text-sm text-red-500 mt-1">{cronValidationError}</p>
|
||||||
@@ -896,6 +898,16 @@ export function GeneralSettingsModal({ isOpen, onClose }: GeneralSettingsModalPr
|
|||||||
</a>{' '}
|
</a>{' '}
|
||||||
for examples
|
for examples
|
||||||
</p>
|
</p>
|
||||||
|
<div className="mt-2 p-2 bg-muted rounded text-xs">
|
||||||
|
<p className="font-medium mb-1">Common examples:</p>
|
||||||
|
<ul className="space-y-1 text-muted-foreground">
|
||||||
|
<li>• <code>* * * * *</code> - Every minute</li>
|
||||||
|
<li>• <code>0 * * * *</code> - Every hour</li>
|
||||||
|
<li>• <code>0 */6 * * *</code> - Every 6 hours</li>
|
||||||
|
<li>• <code>0 0 * * *</code> - Every day at midnight</li>
|
||||||
|
<li>• <code>0 0 * * 0</code> - Every Sunday at midnight</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export async function POST(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidCron(settings.syncIntervalCron)) {
|
if (!isValidCron(settings.syncIntervalCron, { seconds: false })) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Invalid cron expression' },
|
{ error: 'Invalid cron expression' },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@@ -158,6 +158,23 @@ export async function POST(request: NextRequest) {
|
|||||||
// Write back to .env file
|
// Write back to .env file
|
||||||
fs.writeFileSync(envPath, envContent);
|
fs.writeFileSync(envPath, envContent);
|
||||||
|
|
||||||
|
// Reschedule auto-sync service with new settings
|
||||||
|
try {
|
||||||
|
const { AutoSyncService } = await import('../../../../server/services/autoSyncService.js');
|
||||||
|
const autoSyncService = new AutoSyncService();
|
||||||
|
|
||||||
|
if (settings.autoSyncEnabled) {
|
||||||
|
autoSyncService.scheduleAutoSync();
|
||||||
|
console.log('Auto-sync rescheduled with new settings');
|
||||||
|
} else {
|
||||||
|
autoSyncService.stopAutoSync();
|
||||||
|
console.log('Auto-sync stopped');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error rescheduling auto-sync service:', error);
|
||||||
|
// Don't fail the request if rescheduling fails
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Auto-sync settings saved successfully'
|
message: 'Auto-sync settings saved successfully'
|
||||||
|
|||||||
@@ -191,8 +191,8 @@ export class AutoSyncService {
|
|||||||
cronExpression = intervalMap[settings.syncIntervalPredefined] || '0 * * * *';
|
cronExpression = intervalMap[settings.syncIntervalPredefined] || '0 * * * *';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate cron expression
|
// Validate cron expression (5-field format for node-cron)
|
||||||
if (!cronValidator.isValidCron(cronExpression)) {
|
if (!cronValidator.isValidCron(cronExpression, { seconds: false })) {
|
||||||
console.error('Invalid cron expression:', cronExpression);
|
console.error('Invalid cron expression:', cronExpression);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user