Service Appointment
Appointment summary with rescheduling, cancellation confirmation, and recovery actions supplied by the caller.
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 service-appointmentSource files
Expand a file to read the source the installer copies into your app.
components/blocks/service-appointment/ServiceAppointment.tsx
import { View, type ViewProps } from 'react-native'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Text } from '@/components/ui/text'
import { useAnnouncement } from '@/lib/accessibility'
import { cn } from '@/lib/utils'
export type ServiceAppointmentStatus = 'scheduled' | 'cancelled'
interface ServiceAppointmentLabels {
scheduled: string
cancelled: string
provider: string
when: string
where: string
reschedule: string
cancel: string
cancelTitle: string
cancelDescription: string
keep: string
confirmCancel: string
retry: string
bookAgain: string
}
export interface ServiceAppointmentProps extends Omit<ViewProps, 'children'> {
className?: string
service: string
provider?: string
/** Localized date and time, including a time zone when relevant. */
dateTime: string
location?: string
status?: ServiceAppointmentStatus
pending?: 'reschedule' | 'cancel'
error?: string
labels?: Partial<ServiceAppointmentLabels>
onReschedule?: () => void
onCancel?: () => void
onRetry?: () => void
onBookAgain?: () => void
}
export function ServiceAppointment({
className,
service,
provider,
dateTime,
location,
status = 'scheduled',
pending,
error,
labels,
onReschedule,
onCancel,
onRetry,
onBookAgain,
...props
}: ServiceAppointmentProps) {
const cancelled = status === 'cancelled'
const visibleError = cancelled ? undefined : error
const statusLabel = cancelled ? (labels?.cancelled ?? 'Cancelled') : (labels?.scheduled ?? 'Scheduled')
useAnnouncement(visibleError ?? `${service}. ${statusLabel}. ${dateTime}`)
return (
<View {...props} className={cn('gap-[16px] rounded-lg border border-border bg-card p-[16px]', className)}>
<View className="gap-[8px]">
<View className="items-start">
<Badge variant={cancelled ? 'secondary' : 'success'}>{statusLabel}</Badge>
</View>
<Text size="title" accessibilityRole="header" className="text-card-foreground">
{service}
</Text>
</View>
<View className="gap-[12px]">
{provider ? (
<View className="gap-[4px]">
<Text size="sm" variant="muted">
{labels?.provider ?? 'Provider'}
</Text>
<Text className="text-card-foreground">{provider}</Text>
</View>
) : null}
<View className="gap-[4px]">
<Text size="sm" variant="muted">
{labels?.when ?? 'When'}
</Text>
<Text className="text-card-foreground">{dateTime}</Text>
</View>
{location ? (
<View className="gap-[4px]">
<Text size="sm" variant="muted">
{labels?.where ?? 'Where'}
</Text>
<Text className="text-card-foreground">{location}</Text>
</View>
) : null}
</View>
{visibleError ? (
<View className="gap-[8px] border-t border-border pt-[12px]">
<Text size="sm" accessibilityRole="alert" className="text-destructive">
{visibleError}
</Text>
{onRetry ? (
<Button
variant="outline"
accessibilityLabel={labels?.retry ?? 'Try again'}
disabled={Boolean(pending)}
onPress={() => {
if (!pending) onRetry()
}}
>
{labels?.retry ?? 'Try again'}
</Button>
) : null}
</View>
) : null}
{cancelled ? (
onBookAgain ? (
<Button accessibilityLabel={labels?.bookAgain ?? 'Book another appointment'} onPress={onBookAgain}>
{labels?.bookAgain ?? 'Book another appointment'}
</Button>
) : null
) : onReschedule || onCancel ? (
<View className="gap-[8px]">
{onReschedule ? (
<Button
variant="outline"
accessibilityLabel={labels?.reschedule ?? 'Reschedule'}
disabled={pending === 'cancel'}
loading={pending === 'reschedule'}
onPress={() => {
if (!pending) onReschedule()
}}
>
{labels?.reschedule ?? 'Reschedule'}
</Button>
) : null}
{onCancel ? (
<AlertDialog>
<AlertDialogTrigger
variant="ghost"
accessibilityLabel={labels?.cancel ?? 'Cancel appointment'}
loading={pending === 'cancel'}
disabled={pending === 'reschedule'}
>
{labels?.cancel ?? 'Cancel appointment'}
</AlertDialogTrigger>
<AlertDialogContent
title={labels?.cancelTitle ?? 'Cancel this appointment?'}
description={labels?.cancelDescription ?? 'Your reserved time will be released.'}
>
<AlertDialogCancel variant="outline" accessibilityLabel={labels?.keep ?? 'Keep appointment'}>
{labels?.keep ?? 'Keep appointment'}
</AlertDialogCancel>
<AlertDialogAction
variant="destructive"
accessibilityLabel={labels?.confirmCancel ?? 'Confirm cancellation'}
disabled={Boolean(pending)}
onPress={() => {
if (!pending) onCancel()
}}
>
{labels?.confirmCancel ?? 'Confirm cancellation'}
</AlertDialogAction>
</AlertDialogContent>
</AlertDialog>
) : null}
</View>
) : null}
</View>
)
}
components/blocks/service-appointment/index.ts
export { ServiceAppointment, type ServiceAppointmentProps, type ServiceAppointmentStatus } from './ServiceAppointment'