mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 01:31:13 -05:00
Implement conflict resolution logic
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user