Implement conflict resolution logic

This commit is contained in:
gpt-engineer-app[bot]
2025-09-30 15:14:45 +00:00
parent 40f20e5850
commit 14c399f293
3 changed files with 338 additions and 5 deletions

View File

@@ -6,6 +6,8 @@ import { Label } from '@/components/ui/label';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
import { type DependencyConflict, type SubmissionItemWithDeps } from '@/lib/submissionItemsService';
import { useToast } from '@/hooks/use-toast';
import { useAuth } from '@/hooks/useAuth';
interface ConflictResolutionDialogProps {
open: boolean;
@@ -23,6 +25,8 @@ export function ConflictResolutionDialog({
onResolve,
}: ConflictResolutionDialogProps) {
const [resolutions, setResolutions] = useState<Record<string, string>>({});
const { toast } = useToast();
const { user } = useAuth();
const handleResolutionChange = (itemId: string, action: string) => {
setResolutions(prev => ({ ...prev, [itemId]: action }));
@@ -32,10 +36,44 @@ export function ConflictResolutionDialog({
conflict => resolutions[conflict.itemId]
);
const handleApply = () => {
// TODO: Apply resolutions
onResolve();
onOpenChange(false);
const handleApply = async () => {
if (!user?.id) {
toast({
title: 'Authentication Required',
description: 'You must be logged in to resolve conflicts',
variant: 'destructive',
});
return;
}
const { resolveConflicts } = await import('@/lib/conflictResolutionService');
try {
const result = await resolveConflicts(conflicts, resolutions, items, user.id);
if (!result.success) {
toast({
title: 'Resolution Failed',
description: result.error || 'Failed to resolve conflicts',
variant: 'destructive',
});
return;
}
toast({
title: 'Conflicts Resolved',
description: 'All conflicts have been resolved successfully',
});
onResolve();
onOpenChange(false);
} catch (error: any) {
toast({
title: 'Error',
description: error.message || 'Failed to resolve conflicts',
variant: 'destructive',
});
}
};
return (