Collection
Hospitality / Revenue & Inventory · v0.3.0Validated
Review nightly rules and apply authorised changes to minimum stay, arrival, departure or stop sell.
Nightly Booking Rules · Preview
Loading widget…
Preparing source code…
Idle
Hospitality / Revenue & Inventory · v0.3.0Validated
Review nightly rules and apply authorised changes to minimum stay, arrival, departure or stop sell.
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 { RestrictionsBoardWidget } from "@lumo/widgets/catalog/hotel-revenue/restrictions-board";
export default function Example() {
return <RestrictionsBoardWidget />;
}Props for integrating the React component in your app.
snapshotRestrictionsBoardSnapshot | null (optional)onAction(action: RestrictionsBoardAction) => void | Promise<void>{
"snapshot": {
"property": "Alder Quay",
"ratePlan": "King · Flexible",
"currency": "EUR",
"revision": "winter-8",
"nights": [
{
"date": "2026-12-12",
"label": "Sat 12",
"rateMinor": 22500,
"editable": true,
"rules": {
"minimumStay": 2,
"closedToArrival": true,
"closedToDeparture": false,
"stopSell": false
}
}
]
}
}"use client";
import { Badge, Button, FormError, Input, SegmentedControl, useScrollShadow, WidgetCard, WidgetDialog } from "@lumo/ui";
import { CalendarCheck, CalendarRange, ChevronRight, CircleMinus, DoorClosed, LogIn, LogOut, Moon } from "lucide-react";
import { useLayoutEffect, useRef, useState } from "react";
import { operationMoney, useOperationSnapshot } from "../../shared/operation-snapshot";
import { OperationOverview } from "../../shared/OperationOverview";
import shared from "../../shared/operations-list.module.css";
import { useWidgetCommand } from "../../shared/use-widget-command";
import { sample } from "./restrictions-board.constants";
import { restrictionsSchema, type RateRestrictions } from "./restrictions-board.schema";
import type { RestrictionsBoardAction, RestrictionsBoardSnapshot } from "./restrictions-board.types";
import styles from "./restrictions-board.module.css";
export type { RateRestrictions } from "./restrictions-board.schema";
export type { RestrictionsBoardAction, RestrictionsBoardSnapshot, RestrictionsNight } from "./restrictions-board.types";
const fields = [
{ key: "closedToArrival", label: "Closed to arrival", short: "No arrivals", Icon: LogIn, tone: "warning" },
{ key: "closedToDeparture", label: "Closed to departure", short: "No departures", Icon: LogOut, tone: "warning" },
{ key: "stopSell", label: "Stop sell", short: "Stop sell", Icon: CircleMinus, tone: "danger" },
] as const;
const filters = [{ value: "all", label: "All nights" }, { value: "restricted", label: "Restricted" }];
const isRestricted = (rules: RateRestrictions | null) =>
!!rules && (rules.minimumStay > 1 || fields.some(({ key }) => rules[key]));
const minimumError = "Enter a whole number from 1 to 365.";
function RuleChips({ rules }: { rules: RateRestrictions | null }) {
if (!rules) return <Badge size="sm" icon={<CalendarRange />}>Unavailable</Badge>;
if (!isRestricted(rules)) return <Badge size="sm" tone="success" icon={<CalendarCheck />}>Open</Badge>;
return <>
{rules.stopSell && <Badge size="sm" tone="danger" icon={<CircleMinus />}>Stop sell</Badge>}
{rules.minimumStay > 1 && <Badge size="sm" tone="info" icon={<Moon />}>{rules.minimumStay} nights min.</Badge>}
{fields.slice(0, 2).map(({ key, short, Icon, tone }) => rules[key]
&& <Badge key={key} size="sm" tone={tone} icon={<Icon />}>{short}</Badge>)}
</>;
}
function RuleEditor({ rules, price, status, onSubmit }: {
rules: RateRestrictions; price: string | null; status: string;
onSubmit: (rules: RateRestrictions) => void;
}) {
const [draft, setDraft] = useState(rules);
const [minimum, setMinimum] = useState(String(rules.minimumStay));
const input = useRef<HTMLInputElement>(null);
const parsed = restrictionsSchema.safeParse({ ...draft, minimumStay: minimum.trim() ? Number(minimum) : Number.NaN });
const canSave = parsed.success && (parsed.data.minimumStay !== rules.minimumStay || fields.some(({ key }) => parsed.data[key] !== rules[key]));
const saving = status === "saving";
return <form className={styles.editor} noValidate onSubmit={event => {
event.preventDefault();
if (!parsed.success) input.current?.focus();
else if (canSave && !saving) onSubmit(parsed.data);
}}>
<div className={styles.editSummary}>
<Input ref={input} label="Minimum stay (nights)" size="sm" type="number" inputMode="numeric" min={1} max={365} step={1}
value={minimum} error={parsed.success ? undefined : minimumError} disabled={saving}
onChange={event => setMinimum(event.currentTarget.value)} />
{price && <div className={styles.rate}><span>Nightly rate</span><strong>{price}</strong></div>}
</div>
<div role="group" aria-label="Booking controls" className={styles.controls}>
{fields.map(({ key, label, Icon }) => <Button key={key} size="xs" type="button"
variant={draft[key] ? "primary" : "secondary"} aria-pressed={draft[key]} disabled={saving}
onClick={() => setDraft(current => ({ ...current, [key]: !current[key] }))}>
<Icon size={14} aria-hidden />{label}
</Button>)}
</div>
{status === "error" && <FormError>Couldn’t apply the restrictions. Try again.</FormError>}
<div className={styles.apply}><Button size="xs" type="submit" disabled={!canSave || saving}>
{saving ? "Applying…" : "Apply restrictions"}
</Button></div>
</form>;
}
export function RestrictionsBoardWidget({ snapshot, onAction }: { index?: number; snapshot?: RestrictionsBoardSnapshot | null;
onAction?: (action: RestrictionsBoardAction) => void | Promise<void> } = {}) {
const { data, action } = useOperationSnapshot(snapshot, sample, onAction, (current, update) => ({
...current, revision: current.revision + "*", nights: current.nights.map(night => night.date === update.date ? { ...night, rules: update.rules } : night),
}));
const [filter, setFilter] = useState("all");
const [open, setOpen] = useState<{ date: string; revision: string }>();
const trigger = useRef<HTMLButtonElement>(null);
const restrictionFilter = useRef<HTMLDivElement>(null);
const scroll = useScrollShadow<HTMLUListElement>();
const command = useWidgetCommand(action);
const night = open && open.revision === data?.revision ? data.nights.find(item => item.date === open.date) : undefined;
const nights = [...(data?.nights ?? [])].sort((a, b) => a.date.localeCompare(b.date));
const restricted = nights.filter(item => isRestricted(item.rules));
const visible = filter === "restricted" ? restricted : nights;
const price = operationMoney(data?.currency ?? "EUR");
const nightlyRate = night?.rateMinor == null ? null : price(night.rateMinor);
if (open && !night) setOpen(undefined);
useLayoutEffect(() => {
if (!night && trigger.current && !trigger.current.isConnected) {
restrictionFilter.current?.querySelector<HTMLButtonElement>('[aria-pressed="true"]')?.focus({ preventScroll: true });
trigger.current = null;
}
}, [night]);
const surface = <WidgetCard title="Nightly Booking Rules" label="Nightly Booking Rules" description={data && `${data.property} · ${data.ratePlan}`}
size="medium" icon={<CalendarRange />} className={`${shared.mediumCard} ${shared.stableCard} ${styles.card}`}>
{data && nights.length > 0 && <div className={`${shared.stack} ${shared.fillStack} ${styles.content}`}>
<div className={styles.summary} ref={restrictionFilter} tabIndex={-1}><OperationOverview metrics={[
{ label: "Restricted", value: `${restricted.length} / ${nights.length}`, tone: restricted.length ? "warning" : undefined, icon: <DoorClosed size={14} aria-hidden /> },
{ label: "Stop sell", value: nights.filter(item => item.rules?.stopSell).length, tone: nights.some(item => item.rules?.stopSell) ? "danger" : undefined, icon: <CircleMinus size={14} aria-hidden /> },
]}>
<SegmentedControl size="sm" label="Night filter" value={filter} options={filters} onValueChange={setFilter} />
</OperationOverview></div>
{visible.length > 0 ? <>
<div className={styles.columns} aria-hidden><span>Night</span><span>Booking rules</span><span>Rate</span></div>
<ul ref={scroll} data-widget-list tabIndex={0} aria-label="Nightly restrictions"
className={`${shared.list} ${shared.fillList} ${styles.nights}`}>
{visible.map(item => <li key={item.date}><button type="button" className={styles.night} aria-haspopup="dialog"
onClick={event => { command.reset(); trigger.current = event.currentTarget; setOpen({ date: item.date, revision: data.revision }); }}>
<time dateTime={item.date}>{item.label}</time><span className={styles.rules}><RuleChips rules={item.rules} /></span>
<span className={styles.nightRate}>{item.rateMinor == null ? "—" : price(item.rateMinor)}<ChevronRight size={13} aria-hidden /></span>
</button></li>)}
</ul>
</> : <p role="status" className={`${shared.muted} ${shared.emptyMessage}`}>No restrictions reported.</p>}
</div>}
{(!data || !nights.length) && <p className={`${shared.muted} ${shared.emptyMessage}`}>{data ? "No nights reported." : "Nightly restrictions unavailable."}</p>}
</WidgetCard>;
return <WidgetDialog className={shared.mediumCard} placement="bottom" dragFromScrollStart open={!!night}
title={night ? `Booking rules · ${night.label}` : "Nightly Booking Rules"} onClose={() => setOpen(undefined)}
returnFocusRef={trigger} surface={surface}>
{night && (night.editable && action && night.rules && open
? <RuleEditor rules={night.rules} price={nightlyRate} status={command.status} onSubmit={rules => {
void command.run({ type: "set-restrictions", date: night.date, revision: open.revision, rules }).then(saved => {
if (saved) setOpen(current => current === open ? undefined : current);
});
}} />
: <div className={styles.editor}>
<div className={styles.rules}><RuleChips rules={night.rules} /></div>
{nightlyRate && <div className={styles.rate}><span>Nightly rate</span><strong>{nightlyRate}</strong></div>}
</div>)}
</WidgetDialog>;
}
lucide-reactmotionreactreact-domzod