38980-vm/app-9w9pd00g5j41/DUPLICATE_PLACE_FIX.md
2026-03-04 18:25:09 +00:00

2.1 KiB
Raw Permalink Blame History

Duplicate Place Prevention Fix

Problem

The same place could be added multiple times to the same trip day in the Explore page. When a user clicked "Add to Trip" for a place that was already in their active day's plan, it would create a duplicate entry.

Solution Implemented

Added a duplicate check in Explore.tsxhandleAddToTrip function before inserting a new place into trip_places table.

Changes Made

File: src/pages/Explore.tsx

Location: Lines 223-239 (new duplicate check added)

Implementation:

// 4. Aynı place'in bu günde zaten var olup olmadığını kontrol et
const { data: exists } = await (supabase as any)
  .from('trip_places')
  .select('id')
  .eq('trip_day_id', activeDayId)
  .eq('place_id', place.id)
  .maybeSingle();

if (exists) {
  toast({
    title: 'Zaten Eklendi',
    description: 'Bu yer bugünün planında zaten mevcut.',
    variant: 'destructive',
  });
  navigate(`/planner?trip_id=${tripId}`);
  return;
}

How It Works

  1. Before Insert: Query trip_places table to check if a record already exists with the same trip_day_id and place_id
  2. If Duplicate Found:
    • Show error toast: "Zaten Eklendi - Bu yer bugünün planında zaten mevcut."
    • Navigate to planner page
    • Prevent insert operation
  3. If No Duplicate: Continue with normal insert flow

Benefits

Prevents duplicate places in the same trip day
Provides clear user feedback when attempting to add duplicate
Maintains data integrity in trip_places table
Improves user experience by preventing confusion

Testing Checklist

  • Try adding the same place twice to a trip day
  • Verify error toast appears with correct message
  • Confirm navigation to planner page occurs
  • Verify no duplicate entry in database
  • Test with different places to ensure normal flow works
  • src/pages/Explore.tsx - Main implementation
  • Database table: trip_places (composite key: trip_day_id + place_id)

Status: Implemented and Lint Passed
Date: 2026-02-02