feat(ST-n1csfo4j): handleAllDone + AlertDialog + Alles-op-done knop in sprint-afronden-dialog
Voegt handleAllDone toe (roept setAllSprintTasksDoneAction aan en zet alle per-story decisions op DONE in de UI), een bevestigende AlertDialog en een 'Alles op done'-knop bovenaan de story-lijst in de sprint-afronden-dialog. Voegt setAllSprintTasksDoneAction ook toe aan actions/sprints.ts omdat die branch nog niet op main staat. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
33c7c03a67
commit
ac944ed5d2
2 changed files with 75 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
updateSprintGoalSchema,
|
||||
} from '@/lib/schemas/sprint'
|
||||
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
||||
import { updateTaskStatusWithStoryPromotion } from '@/lib/tasks-status-update'
|
||||
|
||||
async function getSession() {
|
||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
|
|
@ -272,3 +273,31 @@ export async function completeSprintAction(
|
|||
revalidatePath(`/products/${sprint.product_id}/sprint`)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function setAllSprintTasksDoneAction(
|
||||
sprintId: string,
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { ok: false, error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { ok: false, error: 'Niet beschikbaar in demo-modus' }
|
||||
|
||||
const sprint = await prisma.sprint.findFirst({
|
||||
where: { id: sprintId, product: productAccessFilter(session.userId) },
|
||||
select: { id: true, product_id: true },
|
||||
})
|
||||
if (!sprint) return { ok: false, error: 'Sprint niet gevonden' }
|
||||
|
||||
const tasks = await prisma.task.findMany({
|
||||
where: { sprint_id: sprintId, product_id: sprint.product_id },
|
||||
select: { id: true },
|
||||
})
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
for (const task of tasks) {
|
||||
await updateTaskStatusWithStoryPromotion(task.id, 'DONE', tx)
|
||||
}
|
||||
})
|
||||
|
||||
revalidatePath(`/products/${sprint.product_id}/sprint`)
|
||||
return { ok: true }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,20 @@ export function SprintHeader({ productId, productName, sprint, isDemo, sprintSto
|
|||
})
|
||||
}
|
||||
|
||||
function handleAllDone() {
|
||||
startSettingAllDone(async () => {
|
||||
const result = await setAllSprintTasksDoneAction(sprint.id)
|
||||
if (!result.ok) {
|
||||
toast.error(result.error ?? 'Alles op done mislukt')
|
||||
} else {
|
||||
const allDone: Record<string, 'DONE' | 'OPEN'> = {}
|
||||
sprintStories.forEach(s => { allDone[s.id] = 'DONE' })
|
||||
setDecisions(allDone)
|
||||
}
|
||||
setShowAllDoneConfirm(false)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-4 py-3 border-b border-border bg-surface-container-low shrink-0">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
|
|
@ -220,6 +234,18 @@ export function SprintHeader({ productId, productName, sprint, isDemo, sprintSto
|
|||
<p className="text-sm text-muted-foreground">
|
||||
Geef per story aan wat er mee moet gebeuren:
|
||||
</p>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-status-done/40 text-status-done hover:bg-status-done/10"
|
||||
disabled={isSettingAllDone || isCompleting}
|
||||
onClick={() => setShowAllDoneConfirm(true)}
|
||||
>
|
||||
{isSettingAllDone ? 'Bezig…' : 'Alles op done'}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{sprintStories.map(story => (
|
||||
<div key={story.id} className="flex items-center justify-between gap-3 p-2 bg-surface-container-low rounded-lg">
|
||||
|
|
@ -257,6 +283,26 @@ export function SprintHeader({ productId, productName, sprint, isDemo, sprintSto
|
|||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<AlertDialog open={showAllDoneConfirm} onOpenChange={setShowAllDoneConfirm}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Alles op done zetten?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Alle taken én stories in de sprint — inclusief taken met status
|
||||
REVIEW — worden op DONE gezet. De per-story toggles hieronder
|
||||
worden daarna bijgewerkt. Je kunt daarna nog per story aanpassen
|
||||
vóór je de sprint afrondt.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isSettingAllDone}>Annuleren</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleAllDone} disabled={isSettingAllDone}>
|
||||
{isSettingAllDone ? 'Bezig…' : 'Alles op done'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue