Wire Buy button on Schedule details page (Angular flight-actions parity)

This commit is contained in:
2026-04-20 19:32:56 +03:00
parent cf93b28699
commit a4923599b9
@@ -9,8 +9,10 @@
*/
import type { FC } from "react";
import { useCallback } from "react";
import { Link } from "@modern-js/runtime/router";
import { useTranslation } from "@/i18n/provider.js";
import { localeToLanguage, normalizeLocaleParam, DEFAULT_LANGUAGE } from "@/i18n/resolver.js";
import { FlightCard } from "@/ui/flights/FlightCard.js";
import { FlightListSkeleton } from "@/ui/flights/FlightListSkeleton.js";
import { SeoHead } from "@/ui/seo/SeoHead.js";
@@ -78,6 +80,31 @@ export const ScheduleDetailsPage: FC<ScheduleDetailsPageProps> = ({
const pageTabs = <PageTabs viewType="schedule" />;
const scheduleHref = `/${locale}/schedule`;
// `Купить` button — opens Aeroflot's booking flow in a new tab.
// Mirrors BoardDetailsHeader's BuyTicketButton / Schedule search page.
const language =
localeToLanguage(normalizeLocaleParam(locale) ?? "ru-ru") ?? DEFAULT_LANGUAGE;
const handleBuy = useCallback(
(flight: ISimpleFlight) => {
const legs = flight.routeType === "Direct" ? [flight.leg] : flight.legs;
const firstLeg = legs[0];
const lastLeg = legs[legs.length - 1];
if (!firstLeg || !lastLeg) return;
const dep = firstLeg.departure.scheduled.airportCode;
const arr = lastLeg.arrival.scheduled.airportCode;
const depUtc = firstLeg.departure.times.scheduledDeparture.utc;
const depDate = new Date(depUtc);
const yyyy = depDate.getFullYear().toString();
const mm = (depDate.getMonth() + 1).toString().padStart(2, "0");
const dd = depDate.getDate().toString().padStart(2, "0");
const url = `https://www.aeroflot.ru/sb/app/${language}-${language}#/search?adults=1&cabin=economy&children=0&infants=0&routes=${dep}.${yyyy}${mm}${dd}.${arr}&autosearch=Y`;
if (typeof window !== "undefined") {
window.open(url, "_blank", "noopener,noreferrer");
}
},
[language],
);
const backLink = (
<Link
to={scheduleHref}
@@ -148,7 +175,10 @@ export const ScheduleDetailsPage: FC<ScheduleDetailsPageProps> = ({
// body for each, separated by a transit caption — close to Angular's
// `schedule-flight-details-view` for the connecting case.
const renderBody = (flight: typeof flights[number]) => (
<ScheduleFlightBody flight={flight as unknown as ISimpleFlight} />
<ScheduleFlightBody
flight={flight as unknown as ISimpleFlight}
onBuy={() => handleBuy(flight as unknown as ISimpleFlight)}
/>
);
return (