From 55f0a8e7751bbf4493262210cfd32cbb70f0edc0 Mon Sep 17 00:00:00 2001 From: 3dtours Date: Mon, 15 Jun 2026 19:42:45 +0700 Subject: [PATCH] =?UTF-8?q?S=E1=BB=ADa=20l=E1=BB=97i=20kh=C3=B4ng=20th?= =?UTF-8?q?=E1=BB=83=20khai=20b=C3=A1o=20s=E1=BB=91=20l=C6=B0=E1=BB=A3ng?= =?UTF-8?q?=20ch=E1=BA=B7ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/ItineraryTimeline.tsx | 60 +++++++++++++++++-- frontend/src/pages/TourDetailPage.tsx | 9 +-- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/ItineraryTimeline.tsx b/frontend/src/components/ItineraryTimeline.tsx index a1615bb..1186e7f 100644 --- a/frontend/src/components/ItineraryTimeline.tsx +++ b/frontend/src/components/ItineraryTimeline.tsx @@ -1,6 +1,6 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { format, differenceInMinutes, parseISO } from 'date-fns'; -import { CheckCircle2, Circle, Clock, MapPin, AlertCircle, Zap, Navigation, Edit2, Trash2, Plus, List } from 'lucide-react'; +import { CheckCircle2, Circle, Clock, MapPin, AlertCircle, Zap, Navigation, Edit2, Trash2, Plus, List, X } from 'lucide-react'; import { useTourStore } from '@/store/useTourStore'; import { ConfirmModal } from '@/components/ConfirmModal'; @@ -52,6 +52,8 @@ export const ItineraryTimeline = ({ const deleteLocation = useTourStore(state => state.deleteLocation); const [confirmState, setConfirmState] = useState<{ open: boolean; title?: string; message?: string; onConfirm?: () => void }>({ open: false }); + const [isLegCountModalOpen, setIsLegCountModalOpen] = useState(false); + const [tempLegCount, setTempLegCount] = useState(3); const toggleComplete = async (locationId: string) => { // Gọi API PATCH /api/v1/locations/:id để cập nhật trạng thái @@ -66,11 +68,15 @@ export const ItineraryTimeline = ({ }; const handleDeclareLegs = async () => { - const countStr = window.prompt("Chuyến đi này bạn muốn chia làm bao nhiêu chặng?", "3"); - const count = parseInt(countStr || "0"); - if (count > 0 && currentTour) { - await initializeLegs(currentTour.id, count); + setTempLegCount(legs.length > 0 ? legs.length : 3); + setIsLegCountModalOpen(true); + }; + + const confirmDeclareLegs = async () => { + if (tempLegCount > 0 && tempLegCount <= 20 && currentTour) { + await initializeLegs(currentTour.id, tempLegCount); } + setIsLegCountModalOpen(false); }; const handleEditLeg = async (leg: any) => { @@ -371,6 +377,48 @@ export const ItineraryTimeline = ({ onConfirm={() => confirmState.onConfirm?.()} onCancel={() => setConfirmState({ open: false })} /> + + {/* Modal Khai báo số chặng (Popover) */} + {isLegCountModalOpen && ( +
+
setIsLegCountModalOpen(false)} /> +
+
+

Số chặng lộ trình

+ +
+ +

+ Bạn muốn chia chuyến đi này thành bao nhiêu chặng nhỏ? (Tối đa 20 chặng) +

+ +
+ + {tempLegCount} + +
+ + +
+
+ )}
); }; \ No newline at end of file diff --git a/frontend/src/pages/TourDetailPage.tsx b/frontend/src/pages/TourDetailPage.tsx index 978cadb..2d3b4a7 100644 --- a/frontend/src/pages/TourDetailPage.tsx +++ b/frontend/src/pages/TourDetailPage.tsx @@ -241,14 +241,7 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => { } }, [publicTours, currentTour, fetchTour]); - // Hàm xử lý khai báo số chặng - const handleDeclareLegs = async () => { - const countStr = window.prompt("Chuyến đi này bạn muốn chia làm bao nhiêu chặng?", "3"); - const count = parseInt(countStr || "0"); - if (count > 0 && currentTour) { - await initializeLegs(currentTour.id, count); - } - }; + // Hàm xử lý các hành động từ Context Menu của bản đồ const handleMapAction = async (action: string, latlng: L.LatLng) => {