departureselection
Version:
A reusable departure selection component for travel booking applications
96 lines (95 loc) • 2.73 kB
TypeScript
export interface DepartureSelectionProps {
initialData?: {
departure: Service[];
return: Service[];
};
onComplete: (data: {
selectedDepartureId: number | null;
selectedReturnId: number | null;
departureService: Service | null;
returnService: Service | null;
date: string;
totalCost: number;
}) => void;
onBack?: () => void;
uiConfig?: UIConfig;
selectedOutboundId?: number | null;
selectedReturnId?: number | null;
currentContext?: 'outbound' | 'return';
onDateSelect?: (data: DateSelectEvent) => void;
onServiceSelect?: (data: ServiceSelectEvent) => void;
onContextChange?: (data: ContextChangeEvent) => void;
isLoading?: boolean;
loadingContext?: 'outbound' | 'return' | 'both';
}
export interface UIConfig {
continueToReturnText: string;
finalContinueText: string;
backToOutboundText: string;
backText: string;
outboundTitle: string;
returnTitle: string;
pageTitle: string;
pageSubtitle: string;
outboundButtonMode: 'continue' | 'complete';
}
export interface DateSelectEvent {
date: string;
previousDate: string;
context: 'outbound' | 'return';
}
export interface ServiceSelectEvent {
serviceId: number;
context: 'outbound' | 'return';
service: Service;
}
export interface ContextChangeEvent {
previousContext: 'outbound' | 'return';
nextContext: 'outbound' | 'return';
selectedOutboundId: number | null;
selectedReturnId: number | null;
}
export interface Pat {
pat_type_name: string;
pat_sub_type_name: string;
pat_sub_type_plural: string;
count: number;
price: number;
descriptor: string;
}
export interface Flag {
flag_name: string;
flag_url: string;
}
export interface Service {
service_id: number;
can_accept: string;
resource_name: string;
route_name: string;
departing_from: string;
travelling_to: string;
departure_time: string;
arrival_time: string;
departure_date: string;
total_cost: number;
pats: Pat[];
flags: Flag[];
}
export interface DepartureSelections {
selectedDepartureId: number | null;
selectedReturnId: number | null;
departureService: Service | null;
returnService: Service | null;
date: string;
totalCost: number;
}
export interface DepartureStore {
selections: Record<string, DepartureSelections>;
setSelections: (instanceId: string, selections: DepartureSelections) => void;
getSelections: (instanceId: string) => DepartureSelections;
clearSelections: (instanceId: string) => void;
}
export interface LoadingState {
isLoading: boolean;
context: 'outbound' | 'return' | 'both';
}