Add ability to end a run as victory or defeat
Add End Run button to run dashboard with a confirmation modal offering Victory/Defeat choice. Backend auto-sets completedAt timestamp and validates only active runs can be ended. Ended runs show a completion banner with date and duration, rename team to "Final Team", and hide encounter logging and status change interactions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { getRuns, getRun, createRun, updateRun, deleteRun } from '../api/runs'
|
||||
import type { CreateRunInput, UpdateRunInput } from '../types/game'
|
||||
|
||||
@@ -30,9 +31,14 @@ export function useUpdateRun(id: number) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (data: UpdateRunInput) => updateRun(id, data),
|
||||
onSuccess: () => {
|
||||
onSuccess: (_result, data) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['runs'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['runs', id] })
|
||||
if (data.status === 'completed') toast.success('Run marked as completed!')
|
||||
else if (data.status === 'failed') toast.success('Run marked as failed')
|
||||
else toast.success('Run updated')
|
||||
},
|
||||
onError: (err) => toast.error(`Failed to update run: ${err.message}`),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user