mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 23:11:12 -05:00
Fix: Prevent approval with blocking errors
This commit is contained in:
@@ -60,6 +60,7 @@ export function SubmissionReviewManager({
|
||||
const [showWarningConfirmDialog, setShowWarningConfirmDialog] = useState(false);
|
||||
const [validationResults, setValidationResults] = useState<Map<string, ValidationResult>>(new Map());
|
||||
const [userConfirmedWarnings, setUserConfirmedWarnings] = useState(false);
|
||||
const [hasBlockingErrors, setHasBlockingErrors] = useState(false);
|
||||
|
||||
const { toast } = useToast();
|
||||
const { isAdmin, isSuperuser } = useUserRole();
|
||||
@@ -117,6 +118,9 @@ export function SubmissionReviewManager({
|
||||
} else {
|
||||
next.add(itemId);
|
||||
}
|
||||
// Clear blocking errors when selection changes
|
||||
setHasBlockingErrors(false);
|
||||
setValidationResults(new Map());
|
||||
return next;
|
||||
});
|
||||
};
|
||||
@@ -176,6 +180,7 @@ export function SubmissionReviewManager({
|
||||
});
|
||||
|
||||
if (itemsWithBlockingErrors.length > 0 && !userConfirmedWarnings) {
|
||||
setHasBlockingErrors(true);
|
||||
setShowValidationBlockerDialog(true);
|
||||
setLoading(false);
|
||||
return; // Block approval
|
||||
@@ -475,6 +480,29 @@ export function SubmissionReviewManager({
|
||||
onOpenChange={setShowEditDialog}
|
||||
onComplete={handleEditComplete}
|
||||
/>
|
||||
|
||||
<ValidationBlockerDialog
|
||||
open={showValidationBlockerDialog}
|
||||
onClose={() => setShowValidationBlockerDialog(false)}
|
||||
blockingErrors={Array.from(validationResults.values()).flatMap(r => r.blockingErrors)}
|
||||
itemNames={items.filter(i => selectedItemIds.has(i.id)).map(i =>
|
||||
i.item_data?.name || i.item_type.replace('_', ' ')
|
||||
)}
|
||||
/>
|
||||
|
||||
<WarningConfirmDialog
|
||||
open={showWarningConfirmDialog}
|
||||
onClose={() => setShowWarningConfirmDialog(false)}
|
||||
onProceed={() => {
|
||||
setUserConfirmedWarnings(true);
|
||||
setShowWarningConfirmDialog(false);
|
||||
handleApprove();
|
||||
}}
|
||||
warnings={Array.from(validationResults.values()).flatMap(r => r.warnings)}
|
||||
itemNames={items.filter(i => selectedItemIds.has(i.id)).map(i =>
|
||||
i.item_data?.name || i.item_type.replace('_', ' ')
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -532,11 +560,21 @@ export function SubmissionReviewManager({
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
{/* Blocking error alert */}
|
||||
{hasBlockingErrors && (
|
||||
<Alert variant="destructive">
|
||||
<AlertCircle className="w-4 h-4" />
|
||||
<AlertDescription>
|
||||
Cannot approve: Selected items have validation errors that must be fixed first.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{/* Action buttons */}
|
||||
<div className="flex flex-col sm:flex-row gap-2 pt-4 border-t">
|
||||
<Button
|
||||
onClick={handleCheckConflicts}
|
||||
disabled={selectedCount === 0 || loading}
|
||||
disabled={selectedCount === 0 || loading || hasBlockingErrors}
|
||||
className="flex-1"
|
||||
>
|
||||
<CheckCircle2 className="w-4 h-4 mr-2" />
|
||||
|
||||
Reference in New Issue
Block a user