feat(heute): ToDos mitten am Tag hinzufügen
Nach dem Lock-in konnte man ToDos nur bearbeiten/abhaken, aber keine neuen anlegen. Neuer Endpoint dayEntry.addTodo hängt ein einzelnes ToDo an den heutigen Tageseintrag an (erlaubt solange der Eintrag vom heutigen Berlin-Tag ist, auch nach der Reflexion). Inline-Feld „Neues ToDo hinzufügen" in der EinstempeltView; aktualisiert Heute + Dashboard-Sichten. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bcae44eeb3
commit
68480c1eb1
3 files changed
+85
No files matched your search
@@ -240,6 +240,46 @@ export const dayEntryRouter = router({
|
|||||||
return updated;
|
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.
|
* Abend-Reflexion. Setzt Ampel + Trend, optional Blocker.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
<form
|
||||||
|
className="mt-3 flex items-center gap-2"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const v = title.trim();
|
||||||
|
if (!v) return;
|
||||||
|
add.mutate({ title: v });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={title}
|
||||||
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
|
placeholder="Neues ToDo hinzufügen …"
|
||||||
|
maxLength={200}
|
||||||
|
className="flex-1 rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-3 py-2 text-sm focus:border-[var(--color-ink)] focus:outline-none"
|
||||||
|
/>
|
||||||
|
<Button type="submit" size="sm" variant="secondary" disabled={!title.trim() || add.isPending}>
|
||||||
|
<Plus size={14} /> Hinzufügen
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function EinstempeltView({
|
function EinstempeltView({
|
||||||
todos,
|
todos,
|
||||||
entry,
|
entry,
|
||||||
@@ -322,6 +358,7 @@ function EinstempeltView({
|
|||||||
<TodoRow key={t.id} todo={t} allTodos={todos} />
|
<TodoRow key={t.id} todo={t} allTodos={todos} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
<AddTodoInline />
|
||||||
</Card.Body>
|
</Card.Body>
|
||||||
<Card.Footer className="flex justify-end">
|
<Card.Footer className="flex justify-end">
|
||||||
<Button onClick={() => (location.href = '/reflexion')}>{ctaLabel}</Button>
|
<Button onClick={() => (location.href = '/reflexion')}>{ctaLabel}</Button>
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ export const editTodoTitleInput = z.object({
|
|||||||
});
|
});
|
||||||
export type EditTodoTitleInput = z.infer<typeof editTodoTitleInput>;
|
export type EditTodoTitleInput = z.infer<typeof editTodoTitleInput>;
|
||||||
|
|
||||||
|
// Einzelnes ToDo mitten am Tag zum heutigen Tageseintrag hinzufügen.
|
||||||
|
export const addTodoInput = z.object({
|
||||||
|
title: z.string().min(1).max(200),
|
||||||
|
bezugKind: bezugKindSchema.optional(),
|
||||||
|
bezugId: z.string().uuid().optional(),
|
||||||
|
});
|
||||||
|
export type AddTodoInput = z.infer<typeof addTodoInput>;
|
||||||
|
|
||||||
export const markAbsentInput = z.object({
|
export const markAbsentInput = z.object({
|
||||||
from: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
from: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
||||||
to: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
to: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
||||||
|
|||||||
Reference in new issue
Block a user