Skip to content

Commit bf5b602

Browse files
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.
1 parent 4d12a51 commit bf5b602

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/app/_components/GeneralSettingsModal.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ export function GeneralSettingsModal({ isOpen, onClose }: GeneralSettingsModalPr
885885
value={syncIntervalCron}
886886
onChange={(e) => handleCronChange(e.target.value)}
887887
className="w-full"
888+
autoFocus
889+
onFocus={() => setCronValidationError('')}
888890
/>
889891
{cronValidationError && (
890892
<p className="text-sm text-red-500 mt-1">{cronValidationError}</p>
@@ -896,6 +898,16 @@ export function GeneralSettingsModal({ isOpen, onClose }: GeneralSettingsModalPr
896898
</a>{' '}
897899
for examples
898900
</p>
901+
<div className="mt-2 p-2 bg-muted rounded text-xs">
902+
<p className="font-medium mb-1">Common examples:</p>
903+
<ul className="space-y-1 text-muted-foreground">
904+
<li><code>* * * * *</code> - Every minute</li>
905+
<li><code>0 * * * *</code> - Every hour</li>
906+
<li><code>0 */6 * * *</code> - Every 6 hours</li>
907+
<li><code>0 0 * * *</code> - Every day at midnight</li>
908+
<li><code>0 0 * * 0</code> - Every Sunday at midnight</li>
909+
</ul>
910+
</div>
899911
</div>
900912
)}
901913
</div>

src/app/api/settings/auto-sync/route.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function POST(request: NextRequest) {
7171
);
7272
}
7373

74-
if (!isValidCron(settings.syncIntervalCron)) {
74+
if (!isValidCron(settings.syncIntervalCron, { seconds: false })) {
7575
return NextResponse.json(
7676
{ error: 'Invalid cron expression' },
7777
{ status: 400 }
@@ -158,6 +158,23 @@ export async function POST(request: NextRequest) {
158158
// Write back to .env file
159159
fs.writeFileSync(envPath, envContent);
160160

161+
// Reschedule auto-sync service with new settings
162+
try {
163+
const { AutoSyncService } = await import('../../../../server/services/autoSyncService.js');
164+
const autoSyncService = new AutoSyncService();
165+
166+
if (settings.autoSyncEnabled) {
167+
autoSyncService.scheduleAutoSync();
168+
console.log('Auto-sync rescheduled with new settings');
169+
} else {
170+
autoSyncService.stopAutoSync();
171+
console.log('Auto-sync stopped');
172+
}
173+
} catch (error) {
174+
console.error('Error rescheduling auto-sync service:', error);
175+
// Don't fail the request if rescheduling fails
176+
}
177+
161178
return NextResponse.json({
162179
success: true,
163180
message: 'Auto-sync settings saved successfully'

src/server/services/autoSyncService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ export class AutoSyncService {
191191
cronExpression = intervalMap[settings.syncIntervalPredefined] || '0 * * * *';
192192
}
193193

194-
// Validate cron expression
195-
if (!cronValidator.isValidCron(cronExpression)) {
194+
// Validate cron expression (5-field format for node-cron)
195+
if (!cronValidator.isValidCron(cronExpression, { seconds: false })) {
196196
console.error('Invalid cron expression:', cronExpression);
197197
return;
198198
}

0 commit comments

Comments
 (0)