Collection
Tour Operator / Tour Bookings · v0.2.0Validated
Review tour options by deadline and inspect held seats before confirming, extending or releasing.
Tour Option Deadlines · Preview
Loading widget…
Preparing source code…
Idle
Tour Operator / Tour Bookings · v0.2.0Validated
Review tour options by deadline and inspect held seats before confirming, extending or releasing.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
import "@lumo/tokens/tokens.css";
import { OptionsExpiringWidget } from "@lumo/widgets/catalog/tour-sales/options-expiring";
export default function Example() {
return <OptionsExpiringWidget />;
}Props for integrating the React component in your app.
snapshotTourOptionsSnapshot | null (optional)onAction(action: TourOptionAction) => void | Promise<void>{
"snapshot": {
"team": "Iberia departures",
"asOf": 1795616400000,
"currency": "EUR",
"options": [
{
"id": "TO-217",
"guest": "Eloïse Henry",
"product": "Madeira ridge walk",
"expiresAt": 1795630800000,
"seats": 3,
"amountMinor": 48000,
"canExtend": true
}
]
}
}"use client";
import { Ticket } from "lucide-react";
import { nonnegativeInteger, operationMoney, relativeWindow, useOperationSnapshot, validTimestamp } from "../../shared/operation-snapshot";
import { WidgetOperations, type OperationRow } from "../../shared/WidgetOperations";
import { tourOptionsDemo } from "./options-expiring.constants";
import type { TourOptionsSnapshot, TourOptionAction } from "./options-expiring.types";
export type { TourOptionsSnapshot, TourOptionAction, TourBookingOption } from "./options-expiring.types";
export function OptionsExpiringWidget({ snapshot, onAction }: {
index?: number; snapshot?: TourOptionsSnapshot | null;
onAction?: (action: TourOptionAction) => void | Promise<void>;
} = {}) {
const { data, action } = useOperationSnapshot(snapshot, tourOptionsDemo, onAction, (state, request) => ({
...state, options: request.type === "extend" ? state.options.map(option => option.id === request.optionId
? { ...option, expiresAt: Math.max(state.asOf, option.expiresAt) + 86_400_000, canExtend: false } : option)
: state.options.filter(option => option.id !== request.optionId),
}));
const money = operationMoney(data?.currency ?? "EUR");
const rank = (time: number) => validTimestamp(time) ? time : Infinity;
const rows = data ? data.options.slice().sort((a, b) => rank(a.expiresAt) - rank(b.expiresAt)).map<OperationRow<TourOptionAction>>(option => {
const valid = validTimestamp(option.expiresAt) && validTimestamp(data.asOf);
const expired = valid && option.expiresAt <= data.asOf;
return {
id: option.id, label: option.guest, caption: option.product, value: relativeWindow(option.expiresAt, data.asOf),
status: expired ? { label: "Expired", tone: "danger" } : valid && option.expiresAt - data.asOf < 21_600_000
? { label: "Due soon", tone: "warning" } : undefined,
details: [["Reference", option.id], ["Departure", option.departureLabel ?? "Not reported"],
["Seats held", nonnegativeInteger(option.seats) ? String(option.seats) : "Unavailable"], ["Quoted total", money(option.amountMinor)]],
actions: [
...(valid && !expired ? [{ label: "Confirm booking", command: { type: "confirm", optionId: option.id },
confirmation: "Confirm this option as a booking?" }] as const : []),
...(valid && !expired && option.canExtend ? [{ label: snapshot === undefined ? "Extend by 24 h" : "Request extension", command: { type: "extend", optionId: option.id } }] as const : []),
{ label: "Release option", command: { type: "release", optionId: option.id }, confirmation: "Release this option and return its seats to inventory?" },
],
};
}) : null;
const expired = data?.options.filter(option => validTimestamp(data.asOf) && validTimestamp(option.expiresAt) && option.expiresAt <= data.asOf).length ?? 0;
return <WidgetOperations title="Options Expiring" description={data?.team} icon={<Ticket />} rows={rows}
onAction={action} empty="No options to review" summary={rows && <><strong>{rows.length}</strong><span>options · {expired} expired</span></>} />;
}
lucide-reactmotionreactreact-dom