Add cancel confirmation and cancellable statuses

Introduce a unified CANCELLABLE_STATUSES constant and add confirmation UI for cancelling requests. RequestActionsDropdown and RequestCard now show a ConfirmModal before cancelling and use the shared CANCELLABLE_STATUSES to gate cancel actions. The API route imports the constant to enforce server-side validation and uses Prisma.DbNull for selectedTorrent when withdrawing an awaiting-approval request. Tests updated to expect Prisma.DbNull. Improves UX and centralizes cancel logic to avoid duplicated status lists.
This commit is contained in:
kikootwo
2026-05-15 09:49:42 -04:00
parent 1a9aeb4713
commit b775ccf473
5 changed files with 83 additions and 31 deletions
+4 -3
View File
@@ -4,10 +4,12 @@
*/
import { NextRequest, NextResponse } from 'next/server';
import { Prisma } from '@/generated/prisma/client';
import { requireAuth, AuthenticatedRequest } from '@/lib/middleware/auth';
import { prisma } from '@/lib/db';
import { RMABLogger } from '@/lib/utils/logger';
import { CLIENT_PROTOCOL_MAP, DownloadClientType } from '@/lib/interfaces/download-client.interface';
import { CANCELLABLE_STATUSES } from '@/lib/constants/request-statuses';
const logger = RMABLogger.create('API.RequestById');
@@ -134,8 +136,7 @@ export async function PATCH(
}
if (action === 'cancel') {
const cancellableStatuses = ['pending', 'searching', 'downloading', 'awaiting_search', 'awaiting_approval'];
if (!cancellableStatuses.includes(requestRecord.status)) {
if (!(CANCELLABLE_STATUSES as readonly string[]).includes(requestRecord.status)) {
return NextResponse.json(
{
error: 'ValidationError',
@@ -152,7 +153,7 @@ export async function PATCH(
data: {
status: 'cancelled',
updatedAt: new Date(),
...(isAwaitingApproval && { selectedTorrent: null as any }),
...(isAwaitingApproval && { selectedTorrent: Prisma.DbNull }),
},
include: {
audiobook: true,