Skip to main content

Book a table

Pick how many, which day and what time. The week strip swipes a week at a time and won't let you pick a Monday, when the place is closed, or a day that's already gone. Reserve says exactly what you're booking.

Loading…
import { useMemo, useState } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { addDays, Button, ChipGroup, Heading, Text, useTheme, WeekStrip } from 'patine-ui';

const PARTY_SIZES = Array.from({ length: 8 }, (_, i) => ({ label: i ? `${i + 1} guests` : '1 guest', value: i + 1 }));
const SLOTS = ['18:00', '18:30', '19:00', '19:30', '20:00', '20:30', '21:00'].map((time) => ({ label: time, value: time }));
// Closed on Mondays.
const isClosed = (day: Date) => day.getDay() === 1;

export default function BookATable() {
  const { colors } = useTheme();
  const today = useMemo(() => {
    const day = new Date();
    day.setHours(0, 0, 0, 0);
    return day;
  }, []);
  const [party, setParty] = useState(2);
  const [day, setDay] = useState<Date | null>(() => {
    const first = addDays(today, 2);
    return isClosed(first) ? addDays(first, 1) : first;
  });
  const [slot, setSlot] = useState('20:00');
  const [booking, setBooking] = useState(false);
  const [booked, setBooked] = useState(false);

  const reserve = () => {
    setBooking(true);
    setTimeout(() => {
      setBooking(false);
      setBooked(true);
    }, 1000);
  };

  return (
    <View style={[styles.screen, { backgroundColor: colors.background }]}>
      <ScrollView contentContainerStyle={styles.content}>
        <View style={styles.titles}>
          <Heading level={2}>Book a table</Heading>
          <Text color="textSecondary">Tasca do Rio · closed Mondays</Text>
        </View>
        <Text weight="semibold">How many</Text>
        <ChipGroup items={PARTY_SIZES} value={party} onValueChange={(next) => { setParty(next); setBooked(false); }} accessibilityLabel="Party size" />
        <Text weight="semibold">Day</Text>
        <WeekStrip value={day} onValueChange={(next) => { setDay(next); setBooked(false); }} minDate={today} isDateDisabled={isClosed} dayHeight={40} />
        <Text weight="semibold">Time</Text>
        <ChipGroup items={SLOTS} value={slot} onValueChange={(next) => { setSlot(next); setBooked(false); }} accessibilityLabel="Time" />
      </ScrollView>
      <View style={styles.footer}>
        <Button size="lg" loading={booking} disabled={!day || booked} onPress={reserve}>
          {booked
            ? 'Table booked'
            : `Reserve for ${party} at ${slot}`}
        </Button>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  screen: { flex: 1 },
  content: { gap: 12, padding: 20 },
  titles: { gap: 4, marginBottom: 8 },
  footer: { padding: 16 },
});

Components used​

  • ChipGroup: party size and time, scrolling sideways and bringing the next chip into view on tap
  • WeekStrip: the day, with minDate and isDateDisabled for the closed Mondays
  • Button: loading, then a confirmation
  • Heading, Text

How it works​

  • Closed days can't be picked. isDateDisabled greys out every Monday, and minDate every day before today; the strip skips them when swiping too.
  • The button says what it books. Its label is built from the three picks, so there's no summary to read twice.
  • Any change un-books. Picking again after booking turns the button back into Reserve.