Restaurant Waitlist
Restaurant wait estimate, ready and canceled states with confirm-to-leave and retry actions.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add restaurant-waitlistSource files
Expand a file to read the source the installer copies into your app.
components/blocks/restaurant-waitlist/RestaurantWaitlist.tsx
import { View, type ViewProps } from 'react-native'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
import { Text } from '@/components/ui/text'
import { useAnnouncement } from '@/lib/accessibility'
import { cn } from '@/lib/utils'
export type RestaurantWaitlistStatus = 'queued' | 'ready' | 'cancelled'
type WaitRange = readonly [earliest: number, latest: number]
interface RestaurantWaitlistLabels {
queued: string
ready: string
cancelled: string
estimate: string
estimateUnavailable: string
leave: string
leaveTitle: string
leaveDescription: string
confirmLeave: string
stay: string
retry: string
}
export interface RestaurantWaitlistProps extends Omit<ViewProps, 'children'> {
className?: string
restaurant: string
/** Locale-ready party description, for example "Party of 4". */
party: string
status: RestaurantWaitlistStatus
/** Caller-provided wait estimate bounds in whole minutes. Only visible while queued. */
waitMinutes?: WaitRange
formatWaitRange?: (range: WaitRange) => string
/** Caller-provided check-in direction or deadline. Visible when the table is ready. */
instructions?: string
pending?: 'leave' | 'retry'
error?: string
labels?: Partial<RestaurantWaitlistLabels>
onLeave?: () => void
onRetry?: () => void
}
const numberFormat = new Intl.NumberFormat()
export function RestaurantWaitlist({
className,
restaurant,
party,
status,
waitMinutes,
formatWaitRange,
instructions,
pending,
error,
labels,
onLeave,
onRetry,
...props
}: RestaurantWaitlistProps) {
const [earliest, latest] = waitMinutes ?? []
const validRange =
waitMinutes &&
earliest != null &&
latest != null &&
Number.isSafeInteger(earliest) &&
Number.isSafeInteger(latest) &&
earliest >= 0 &&
latest > earliest
const statusLabel =
status === 'queued'
? (labels?.queued ?? 'On the waitlist')
: status === 'ready'
? (labels?.ready ?? 'Your table is ready')
: (labels?.cancelled ?? 'Waitlist canceled')
const wait =
status !== 'queued'
? undefined
: validRange
? (formatWaitRange?.(waitMinutes) ?? `${numberFormat.format(earliest)}–${numberFormat.format(latest)} min`)
: (labels?.estimateUnavailable ?? 'Wait estimate unavailable')
const visibleError = status === 'cancelled' ? undefined : error
const readyInstructions = status === 'ready' ? instructions : undefined
useAnnouncement(visibleError ?? [restaurant, statusLabel, wait, readyInstructions].filter(Boolean).join('. '))
return (
<View {...props} className={cn('gap-[16px] rounded-lg border border-border bg-card p-[16px]', className)}>
<View className="gap-[4px]">
<Text size="title" accessibilityRole="header" className="text-card-foreground">
{restaurant}
</Text>
<Text variant="muted">{party}</Text>
</View>
<View className="gap-[4px] border-t border-border pt-[16px]">
<Text size={status === 'ready' ? 'xl' : 'default'} className="font-semibold text-card-foreground">
{statusLabel}
</Text>
{wait ? (
<>
{validRange ? (
<Text size="sm" variant="muted">
{labels?.estimate ?? 'Estimated wait'}
</Text>
) : null}
<Text size={validRange ? 'xl' : 'default'} variant={validRange ? 'default' : 'muted'}>
{wait}
</Text>
</>
) : null}
{readyInstructions ? <Text>{readyInstructions}</Text> : null}
</View>
{visibleError ? (
<View className="gap-[8px]">
<Text size="sm" className="text-destructive" accessibilityRole="alert">
{visibleError}
</Text>
{onRetry ? (
<Button
variant="outline"
disabled={pending === 'leave'}
loading={pending === 'retry'}
accessibilityLabel={labels?.retry ?? 'Try again'}
onPress={() => {
if (!pending) onRetry()
}}
>
{labels?.retry ?? 'Try again'}
</Button>
) : null}
</View>
) : null}
{status !== 'cancelled' && onLeave ? (
<AlertDialog>
<AlertDialogTrigger
variant="outline"
disabled={pending === 'retry'}
loading={pending === 'leave'}
accessibilityLabel={labels?.leave ?? 'Leave waitlist'}
>
{labels?.leave ?? 'Leave waitlist'}
</AlertDialogTrigger>
<AlertDialogContent
title={labels?.leaveTitle ?? 'Leave the waitlist?'}
description={labels?.leaveDescription ?? 'Your party will lose its place in line.'}
>
<AlertDialogCancel variant="outline" accessibilityLabel={labels?.stay ?? 'Stay on waitlist'}>
{labels?.stay ?? 'Stay on waitlist'}
</AlertDialogCancel>
<AlertDialogAction
variant="destructive"
disabled={Boolean(pending)}
accessibilityLabel={labels?.confirmLeave ?? 'Leave the line'}
onPress={() => {
if (!pending) onLeave()
}}
>
{labels?.confirmLeave ?? 'Leave the line'}
</AlertDialogAction>
</AlertDialogContent>
</AlertDialog>
) : null}
</View>
)
}
components/blocks/restaurant-waitlist/index.ts
export { RestaurantWaitlist, type RestaurantWaitlistProps, type RestaurantWaitlistStatus } from './RestaurantWaitlist'