diff --git a/AddLocationModal.tsx b/AddLocationModal.tsx
index 2bf11d6..82c78fd 100644
--- a/AddLocationModal.tsx
+++ b/AddLocationModal.tsx
@@ -9,20 +9,26 @@ export const AddLocationModal = ({ isOpen, onClose, tourId }: { isOpen: boolean,
latitude: 10.7769,
longitude: 106.7009,
type: 'VISIT',
+ legId: '',
plannedStart: '',
plannedEnd: ''
});
const [isLoading, setIsLoading] = useState(false);
+ const legs = useTourStore(state => state.legs);
const addLocation = useTourStore(state => state.addLocation);
if (!isOpen) return null;
+ // Mặc định chọn chặng đầu nếu chưa chọn
+ const currentLegId = formData.legId || (legs.length > 0 ? legs[0].id : '');
+
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
try {
await addLocation(tourId, {
...formData,
+ legId: currentLegId,
latitude: parseFloat(formData.latitude as any),
longitude: parseFloat(formData.longitude as any),
});
@@ -58,6 +64,15 @@ export const AddLocationModal = ({ isOpen, onClose, tourId }: { isOpen: boolean,
setFormData({...formData, address: e.target.value})} />
+
diff --git a/ItineraryTimeline.tsx b/ItineraryTimeline.tsx
index ec40592..dd42bf2 100644
--- a/ItineraryTimeline.tsx
+++ b/ItineraryTimeline.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import { format, differenceInMinutes, parseISO } from 'date-fns';
-import { CheckCircle2, Circle, Clock, MapPin, AlertCircle, Zap, Navigation, Edit2, Trash2, Plus } from 'lucide-react';
+import { CheckCircle2, Circle, Clock, MapPin, AlertCircle, Zap, Navigation, Edit2, Trash2, Plus, List } from 'lucide-react';
import { useTourStore } from './useTourStore.js';
const TimeVariance = ({ planned, actual }: { planned: string, actual: string | null }) => {
@@ -36,7 +36,7 @@ const formatTravelTime = (minutes: number) => {
};
export const ItineraryTimeline = () => {
- const { currentTour, legs, optimizeRouting, userRole, activeLegId, setActiveLegId, addLeg, updateLeg, deleteLeg } = useTourStore();
+ const { currentTour, legs, optimizeRouting, userRole, activeLegId, setActiveLegId, addLeg, updateLeg, deleteLeg, initializeLegs } = useTourStore();
const toggleComplete = async (locationId: string) => {
// Gọi API PATCH /api/v1/locations/:id để cập nhật trạng thái
@@ -50,6 +50,14 @@ 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);
+ }
+ };
+
const handleEditLeg = async (leg: any) => {
const note = window.prompt("Sửa ghi chú chặng:", leg.note || "");
if (note !== null) {
@@ -86,6 +94,15 @@ export const ItineraryTimeline = () => {
Chặng {leg.sequence}
))}
+ {['OWNER', 'MANAGER'].includes(userRole || '') && (
+
+ )}
{['OWNER', 'MANAGER'].includes(userRole || '') && (