diff --git a/apps/api/src/routers/day-entry.ts b/apps/api/src/routers/day-entry.ts index ad30b95..0f66062 100644 --- a/apps/api/src/routers/day-entry.ts +++ b/apps/api/src/routers/day-entry.ts @@ -240,6 +240,46 @@ export const dayEntryRouter = router({ return updated; }), + /** + * Einzelnes ToDo mitten am Tag hinzufügen (auch nach der Reflexion möglich, + * solange der Tageseintrag vom heutigen Berlin-Tag ist). + */ + addTodo: protectedProcedure + .input(DayEntrySchemas.addTodoInput) + .mutation(async ({ ctx, input }) => { + const date = todayIso(); + const entry = ( + await ctx.db + .select() + .from(dayEntry) + .where(and(eq(dayEntry.userId, ctx.user.id), eq(dayEntry.date, date))) + .limit(1) + )[0]; + if (!entry) { + throw new TRPCError({ + code: 'BAD_REQUEST', + message: 'Du bist heute noch nicht locked in.', + }); + } + const existing = await ctx.db + .select({ id: todo.id }) + .from(todo) + .where(eq(todo.dayEntryId, entry.id)); + const [created] = await ctx.db + .insert(todo) + .values({ + dayEntryId: entry.id, + userId: ctx.user.id, + date: entry.date, + title: input.title, + order: existing.length, + bezugKind: input.bezugKind ?? null, + bezugId: input.bezugId ?? null, + }) + .returning(); + return created; + }), + /** * Abend-Reflexion. Setzt Ampel + Trend, optional Blocker. */ diff --git a/apps/web/src/routes/heute.tsx b/apps/web/src/routes/heute.tsx index f90a0c2..dd7ea8c 100644 --- a/apps/web/src/routes/heute.tsx +++ b/apps/web/src/routes/heute.tsx @@ -273,6 +273,42 @@ function TodoRow({ ); } +function AddTodoInline() { + const utils = trpc.useUtils(); + const [title, setTitle] = useState(''); + const add = trpc.dayEntry.addTodo.useMutation({ + onSuccess: async () => { + setTitle(''); + await utils.dayEntry.today.invalidate(); + await utils.dayEntry.todayTeam.invalidate(); + await utils.dashboard.overview.invalidate(); + }, + }); + return ( +
+ ); +} + function EinstempeltView({ todos, entry, @@ -322,6 +358,7 @@ function EinstempeltView({