Collection
Hospitality / Revenue & Inventory · v0.2.0Validated
See which stay restrictions block room-nights and estimate the gross value of each gap.
Unsellable Night Gaps · Preview
Loading widget…
Preparing source code…
Idle
Hospitality / Revenue & Inventory · v0.2.0Validated
See which stay restrictions block room-nights and estimate the gross value of each gap.
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 { OrphanNightsWidget } from "@lumo/widgets/catalog/hotel-revenue/orphan-nights";
export default function Example() {
return <OrphanNightsWidget />;
}Props for integrating the React component in your app.
snapshotOrphanNightsSnapshot | null (optional)onAction(action: OrphanNightsAction) => void | Promise<void>{
"snapshot": {
"property": "Maison Ardoise",
"currency": "EUR",
"gaps": [
{
"id": "OG-21",
"roomType": "Garden Loft",
"datesLabel": "3–4 Dec",
"rooms": 2,
"nights": 1,
"nightlyRateMinor": 23500,
"reason": "Two-night minimum",
"proposal": {
"type": "minimum-stay",
"proposedNights": 1
}
}
]
}
}"use client";
import { CalendarRange } from "lucide-react";
import { nonnegativeInteger, operationMoney, useOperationSnapshot } from "../../shared/operation-snapshot";
import { WidgetOperations, type OperationRow } from "../../shared/WidgetOperations";
import { gapDemo } from "./orphan-nights.constants";
import type { OrphanNightsSnapshot, OrphanNightsAction, InventoryGap } from "./orphan-nights.types";
export type { OrphanNightsSnapshot, OrphanNightsAction, InventoryGap, GapRestriction } from "./orphan-nights.types";
function roomNights(gap: InventoryGap) {
const count = gap.rooms * gap.nights;
return nonnegativeInteger(gap.rooms) && nonnegativeInteger(gap.nights) && nonnegativeInteger(count) ? count : null;
}
function gross(gap: InventoryGap) {
const count = roomNights(gap);
return count !== null && nonnegativeInteger(gap.nightlyRateMinor) ? count * gap.nightlyRateMinor : null;
}
export function OrphanNightsWidget({ snapshot, onAction }: {
index?: number; snapshot?: OrphanNightsSnapshot | null;
onAction?: (action: OrphanNightsAction) => void | Promise<void>;
} = {}) {
const { data, action } = useOperationSnapshot(snapshot, gapDemo, onAction, (state, request) => ({
...state, gaps: state.gaps.filter(gap => gap.id !== request.gapId),
}));
const money = operationMoney(data?.currency ?? "EUR");
const gaps = data?.gaps.slice().sort((a, b) => (gross(b) ?? -1) - (gross(a) ?? -1));
const totalNights = gaps?.reduce((sum, gap) => sum + (roomNights(gap) ?? 0), 0) ?? 0;
const knownNights = gaps?.filter(gap => roomNights(gap) !== null).length ?? 0;
const rows = gaps?.map<OperationRow<OrphanNightsAction>>(gap => {
const proposal = gap.proposal;
const label = proposal?.type === "closed-to-arrival" ? "Open to arrivals"
: proposal && nonnegativeInteger(proposal.proposedNights) && proposal.proposedNights > 0
&& proposal.proposedNights <= gap.nights ? `Set minimum to ${proposal.proposedNights} ${proposal.proposedNights === 1 ? "night" : "nights"}` : undefined;
return {
id: gap.id, label: gap.roomType, caption: gap.datesLabel, value: money(gross(gap)),
details: [["Restriction", gap.reason], ["Room-nights", String(roomNights(gap) ?? "Unavailable")],
["Estimated gross at supplied rate", money(gross(gap))]],
actions: proposal && label ? [{ label, command: { type: "apply-restriction", gapId: gap.id, proposal },
confirmation: `Apply only to ${gap.roomType} for ${gap.datesLabel}?` }] : [],
};
}) ?? null;
return <WidgetOperations title="Orphan Nights" description={data?.property} icon={<CalendarRange />} rows={rows}
onAction={action} empty="No blocked gaps" summary={gaps?.length ? <><strong>{knownNights ? totalNights : "Unavailable"}</strong>
<span>{knownNights < gaps.length ? "reported room-nights" : "blocked room-nights"} · estimated gross by gap</span></> : null} />;
}
lucide-reactmotionreactreact-dom