fix(frontend): fix routines list crash and AI save redirect
- Make Routine.steps optional in types.ts — list endpoint does not eager-load steps, so the field is absent from the JSON response - Guard routine.steps?.length ?? 0 in routines list page to prevent SSR TypeError when steps is undefined - Move redirect() outside try/catch in suggest save action; SvelteKit redirect throws internally and was being caught, causing a 500 error instead of navigating to the new routine Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
81b1cacc5c
commit
832676bcfa
3 changed files with 5 additions and 3 deletions
|
|
@ -181,7 +181,7 @@ export interface Routine {
|
|||
notes?: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
steps: RoutineStep[];
|
||||
steps?: RoutineStep[];
|
||||
}
|
||||
|
||||
export interface GroomingSchedule {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
<Badge variant={routine.part_of_day === 'am' ? 'default' : 'secondary'}>
|
||||
{routine.part_of_day.toUpperCase()}
|
||||
</Badge>
|
||||
<span class="text-sm">{routine.steps.length} steps</span>
|
||||
<span class="text-sm">{routine.steps?.length ?? 0} steps</span>
|
||||
</div>
|
||||
{#if routine.notes}
|
||||
<span class="text-sm text-muted-foreground truncate max-w-xs">{routine.notes}</span>
|
||||
|
|
|
|||
|
|
@ -74,8 +74,10 @@ export const actions: Actions = {
|
|||
return fail(400, { error: 'Nieprawidłowy format kroków.' });
|
||||
}
|
||||
|
||||
let routineId: string;
|
||||
try {
|
||||
const routine = await createRoutine({ routine_date, part_of_day });
|
||||
routineId = routine.id;
|
||||
for (let i = 0; i < steps.length; i++) {
|
||||
const s = steps[i];
|
||||
await addRoutineStep(routine.id, {
|
||||
|
|
@ -87,10 +89,10 @@ export const actions: Actions = {
|
|||
region: s.region || undefined
|
||||
});
|
||||
}
|
||||
redirect(303, `/routines/${routine.id}`);
|
||||
} catch (e) {
|
||||
return fail(500, { error: (e as Error).message });
|
||||
}
|
||||
redirect(303, `/routines/${routineId}`);
|
||||
},
|
||||
|
||||
saveBatch: async ({ request }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue