diff --git a/src/pages/ItinerarySummaryPage.tsx b/src/pages/ItinerarySummaryPage.tsx
index b52f9e6..4b69ffb 100644
--- a/src/pages/ItinerarySummaryPage.tsx
+++ b/src/pages/ItinerarySummaryPage.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
import { motion, AnimatePresence } from 'motion/react';
import {
MapPin,
@@ -7,11 +7,12 @@ import {
Share2,
Download,
ChevronRight,
+ Loader2,
} from 'lucide-react';
import { Button } from '../components/ui/button';
import { Card, CardContent } from '../components/ui/card';
import { ImageWithFallback } from '../components/figma/ImageWithFallback';
-import { useCreateMagicItineraryMutation, useGetItineraryDetailsByIdQuery } from '../Redux/services/itinerary.service';
+import { useDownloadItineraryQuery, useGetItineraryDetailsByIdQuery } from '../Redux/services/itinerary.service';
import { toast } from 'sonner';
import { useNavigate, useParams } from 'react-router-dom';
import Navbar from '../components/Navbar';
@@ -26,6 +27,37 @@ const ItinerarySummaryPage = () => {
const { itineraryId } = useParams()
const { data: itineraryDetails, isLoading: itineraryDetailsLoading } = useGetItineraryDetailsByIdQuery(itineraryId);
+ // Download logic using standard query with manual trigger
+ const [shouldDownload, setShouldDownload] = useState(false);
+ const { data: pdfBlob, isFetching: isDownloading, refetch } = useDownloadItineraryQuery
+ (itineraryId!, {
+ skip: !shouldDownload || !itineraryId,
+ });
+
+ useEffect(() => {
+ if (shouldDownload && pdfBlob) {
+ // Create download link
+ const url = window.URL.createObjectURL(pdfBlob);
+ const link = document.createElement('a');
+ link.href = url;
+ link.download = `itinerary-${itineraryId}.pdf`;
+ document.body.appendChild(link);
+ link.click();
+ link.remove();
+ window.URL.revokeObjectURL(url);
+ toast.success('Itinerary downloaded successfully!');
+ setShouldDownload(false); // reset trigger
+ }
+ }, [pdfBlob, shouldDownload, itineraryId]);
+
+ const handleDownloadItinerary = useCallback(() => {
+ if (!itineraryId) {
+ toast.error('Itinerary ID not found');
+ return;
+ }
+ setShouldDownload(true);
+ refetch(); // manually trigger the download query
+ }, [itineraryId, refetch]);
const generatedItinerary = itineraryDetails ?? null;
const days = generatedItinerary?.days ?? [];
@@ -35,305 +67,312 @@ const ItinerarySummaryPage = () => {
return (
-
- {/* Navbar */}
-
-
- {/* Title */}
-
-
- Your
-
-
- {generatedItinerary?.title}
-
-
+
+ {/* Navbar */}
+
+
+ {/* Title */}
+
+
+ Your
+
+
+ {generatedItinerary?.title}
+
+
- {/* Trip Details Card */}
-
- {/* Background Image */}
-
-
-
-
-
Your Trip
-
{generatedItinerary?.city}
+ {/* Trip Details Card */}
+
+ {/* Background Image */}
+
+
+
+
+
Your Trip
+
{generatedItinerary?.city}
+
+
+ {/* Stats Row */}
+
+
+ {generatedItinerary?.totalDays}
+ Days
+
+
+ {generatedItinerary?.totalStops}
+ Stops
+
+
+ {generatedItinerary?.days[0]?.date}
+ Start Date
+
- {/* Stats Row */}
-
-
- {generatedItinerary?.totalDays}
- Days
-
-
- {generatedItinerary?.totalStops}
- Stops
-
-
- {generatedItinerary?.days[0]?.date}
- Start Date
-
-
-
- {/* Share & Download Buttons */}
-
-
-
-
-
- {/* View Toggle */}
-
-
-
-
- {/* Daily View */}
- {viewMode === 'daily' && (
-
- {/* Day Tabs */}
-
- {days?.map((day: any) => (
- setSelectedDayTab(day.dayNumber)}
- className={`px-5 py-2.5 rounded-xl whitespace-nowrap font-poppins text-base transition-all ${selectedDayTab === day.dayNumber
- ? 'text-primary font-semibold bg-primary/10 border border-primary/20'
- : 'text-gray-400 font-medium hover:text-gray-600'
- }`}
- >
- Day {day.dayNumber}
-
- ))}
- {days?.length > 4 && (
-
-
-
+ {isDownloading ? (
+
+ ) : (
+
)}
-
- {/* Activities for selected day */}
- {selectedDayPlan && (
-
-
- {selectedDayPlan?.items?.map((activity: any, actIndex: number) => {
- const activityKey = `day${selectedDayPlan.day}-act${actIndex}`;
-
- return (
-
- {/* Time Label */}
-
- {activity.timeSlot}
-
-
- {/* Activity Card */}
-
-
- {/* Image */}
-
-
-
- {/* TODO: Get Directions Badge redirect it to lat,long */}
-
-
-
- Get Directions
-
-
-
-
- {/* Content */}
-
-
- {activity.title}
-
-
- {activity.locationName}
-
-
- {/* Category Tags */}
-
- {activity.categories?.map((cat: string, ci: number) => (
-
- {cat}
-
- ))}
-
-
- {/* Bullet Points */}
-
-
-
- •
- {activity.description}
-
-
-
-
-
-
-
- );
- })}
-
-
- )}
+ Download
+
- )}
- {/* Summary View */}
- {viewMode === 'summary' && (
-
- {days?.map((day: any, dayIndex: number) => {
- const dayDate = days[0]?.date
- ? new Date(
- new Date(days[0].date).setDate(
- new Date(days[0].date).getDate() + dayIndex
- )
- ).toLocaleDateString('en-AU', {
- day: '2-digit',
- month: '2-digit',
- year: 'numeric',
- })
- : '';
+ {/* View Toggle */}
+
+
+ setViewMode('daily')}
+ className={`px-6 py-2.5 rounded-full font-poppins font-medium text-sm transition-all ${viewMode === 'daily'
+ ? 'bg-white shadow-sm text-gray-900'
+ : 'text-gray-500 hover:text-gray-700'
+ }`}
+ >
+ Daily View
+
+ setViewMode('summary')}
+ className={`px-6 py-2.5 rounded-full font-poppins font-medium text-sm transition-all ${viewMode === 'summary'
+ ? 'bg-white shadow-sm text-gray-900'
+ : 'text-gray-500 hover:text-gray-700'
+ }`}
+ >
+ Summary
+
+
+
- // ✅ Find the matching summary for this day
- const daySummary = summaries.find((s: any) => s.dayNumber === day.dayNumber);
+ {/* Daily View */}
+ {viewMode === 'daily' && (
+
+ {/* Day Tabs */}
+
+ {days?.map((day: any) => (
+ setSelectedDayTab(day.dayNumber)}
+ className={`px-5 py-2.5 rounded-xl whitespace-nowrap font-poppins text-base transition-all ${selectedDayTab === day.dayNumber
+ ? 'text-primary font-semibold bg-primary/10 border border-primary/20'
+ : 'text-gray-400 font-medium hover:text-gray-600'
+ }`}
+ >
+ Day {day.dayNumber}
+
+ ))}
+ {days?.length > 4 && (
+
+
+
+ )}
+
- return (
-
- {/* Day Header */}
-
-
- Day {day.dayNumber}:
-
-
-
- {dayDate}
-
-
-
- {/* Activity List */}
-
- {daySummary?.items?.map((item: any, actIndex: number) => {
- const activityKey = `summary-day${day.dayNumber}-act${actIndex}`;
- const isExpanded = selectedActivity === activityKey;
+ {/* Activities for selected day */}
+ {selectedDayPlan && (
+
+
+ {selectedDayPlan?.items?.map((activity: any, actIndex: number) => {
+ const activityKey = `day${selectedDayPlan.day}-act${actIndex}`;
return (
-
-
- setSelectedActivity(isExpanded ? null : activityKey)
- }
- >
-
- {item.timeSlot}: {item.title}
-
-
-
+
+ {/* Time Label */}
+
+ {activity.timeSlot}
+
-
- {isExpanded && (
-
-
-
- •
-
- {item.description}
-
-
-
+ {/* Activity Card */}
+
+
+ {/* Image */}
+
+
+
+ {/* TODO: Get Directions Badge redirect it to lat,long */}
+
+
- Get directions
+ Get Directions
-
- )}
-
-
+
+
+ {/* Content */}
+
+
+ {activity.title}
+
+
+ {activity.locationName}
+
+
+ {/* Category Tags */}
+
+ {activity.categories?.map((cat: string, ci: number) => (
+
+ {cat}
+
+ ))}
+
+
+ {/* Bullet Points */}
+
+
+
+ •
+ {activity.description}
+
+
+
+
+
+
+
);
})}
-
-
- );
- })}
-
- )}
+
+
+ )}
+
+ )}
- {/* Bottom Action */}
-
- navigate('/create-itinerary')}
- className="w-full font-poppins font-semibold px-8 py-3 rounded-xl bg-primary hover:bg-primary/90 text-white shadow-md shadow-primary/20"
- >
- Create Another Itinerary
-
-
-
-
-
+ {/* Summary View */}
+ {viewMode === 'summary' && (
+
+ {days?.map((day: any, dayIndex: number) => {
+ const dayDate = days[0]?.date
+ ? new Date(
+ new Date(days[0].date).setDate(
+ new Date(days[0].date).getDate() + dayIndex
+ )
+ ).toLocaleDateString('en-AU', {
+ day: '2-digit',
+ month: '2-digit',
+ year: 'numeric',
+ })
+ : '';
+
+ // ✅ Find the matching summary for this day
+ const daySummary = summaries.find((s: any) => s.dayNumber === day.dayNumber);
+
+ return (
+
+ {/* Day Header */}
+
+
+ Day {day.dayNumber}:
+
+
+
+ {dayDate}
+
+
+
+ {/* Activity List */}
+
+ {daySummary?.items?.map((item: any, actIndex: number) => {
+ const activityKey = `summary-day${day.dayNumber}-act${actIndex}`;
+ const isExpanded = selectedActivity === activityKey;
+
+ return (
+
+
+ setSelectedActivity(isExpanded ? null : activityKey)
+ }
+ >
+
+ {item.timeSlot}: {item.title}
+
+
+
+
+
+ {isExpanded && (
+
+
+
+ •
+
+ {item.description}
+
+
+
+
+ Get directions
+
+
+
+ )}
+
+
+ );
+ })}
+
+
+ );
+ })}
+
+ )}
+
+ {/* Bottom Action */}
+
+ navigate('/create-itinerary')}
+ className="w-full font-poppins font-semibold px-8 py-3 rounded-xl bg-primary hover:bg-primary/90 text-white shadow-md shadow-primary/20"
+ >
+ Create Another Itinerary
+
+
+
+
+
);
}