Bổ sung tính năng sửa chữa, cập nhật địa điểm trong chặng

This commit is contained in:
2026-06-14 10:16:09 +07:00
parent ec650fb45d
commit 838aec562f
19 changed files with 285 additions and 45 deletions
+23 -2
View File
@@ -35,8 +35,11 @@ const formatTravelTime = (minutes: number) => {
return mins > 0 ? `${hours} giờ ${mins} phút` : `${hours} giờ`;
};
export const ItineraryTimeline = ({ onAddLocation }: { onAddLocation?: (legId: string) => void }) => {
const { currentTour, legs, optimizeRouting, userRole, addLeg, updateLeg, deleteLeg, initializeLegs } = useTourStore();
export const ItineraryTimeline = ({
onAddLocation,
onEditLocation
}: { onAddLocation?: (legId: string) => void, onEditLocation?: (location: any) => void }) => {
const { currentTour, legs, optimizeRouting, userRole, addLeg, updateLeg, deleteLeg, initializeLegs, deleteLocation } = useTourStore();
const toggleComplete = async (locationId: string) => {
// Gọi API PATCH /api/v1/locations/:id để cập nhật trạng thái
@@ -75,6 +78,14 @@ export const ItineraryTimeline = ({ onAddLocation }: { onAddLocation?: (legId: s
}
};
const handleDeleteLocation = async (id: string) => {
if (window.confirm("Bạn có chắc chắn muốn xóa địa điểm này?")) {
try {
await deleteLocation(id);
} catch (err: any) { alert(err.message); }
}
};
return (
<div className="max-w-2xl mx-auto p-0 bg-gray-50 min-h-screen">
<div className="px-2 pt-4">
@@ -241,6 +252,16 @@ export const ItineraryTimeline = ({ onAddLocation }: { onAddLocation?: (legId: s
Thực tế: {format(parseISO(location.actualStart), 'HH:mm')}
</div>
)}
{['OWNER', 'MANAGER'].includes(userRole || '') && !isStartPoint && !isEndPoint && (
<div className="flex gap-1 mt-2">
<button onClick={() => onEditLocation?.(location)} className="p-1 text-gray-400 hover:text-blue-600 transition-colors">
<Edit2 className="w-3.5 h-3.5" />
</button>
<button onClick={() => handleDeleteLocation(location.id)} className="p-1 text-gray-400 hover:text-red-600 transition-colors">
<Trash2 className="w-3.5 h-3.5" />
</button>
</div>
)}
</div>
</div>