# Delivery details form

> A React Native checkout delivery step for iOS, Android and the web: the shipping country with flags, a courier phone number whose dialling code follows the country until one is typed, the delivery day from tomorrow on, and a time window as a segmented control. One file, built with Patine's CountryPicker, PhoneField, DatePickerField and SegmentedControl.

# Delivery details

The delivery step of a checkout: where it ships, a phone number for the courier that takes the shipping country's code until you type one, the day (from tomorrow), and a two-hour window. **Continue** waits for a valid number.

```tsx live device
import { useMemo, useState } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { addDays, Button, CountryPicker, DatePickerField, Heading, PhoneField, SegmentedControl, Steps, Text, useTheme } from 'patine-ui';
import type { CountryCode, PhoneDetails } from 'patine-ui';

const WINDOWS = ['9–12', '12–15', '15–18', '18–21'].map((label) => ({ label, value: label }));
const STEPS = [{ title: 'Bag' }, { title: 'Delivery' }, { title: 'Payment' }];

export default function DeliveryDetails() {
  const { colors } = useTheme();
  const tomorrow = useMemo(() => {
    const day = addDays(new Date(), 1);
    day.setHours(0, 0, 0, 0);
    return day;
  }, []);
  const [shipTo, setShipTo] = useState<CountryCode | null>('PT');
  const [phone, setPhone] = useState('');
  const [phoneCountry, setPhoneCountry] = useState<CountryCode>('PT');
  const [phoneValid, setPhoneValid] = useState(false);
  const [day, setDay] = useState<Date | null>(() => addDays(tomorrow, 1));
  const [slot, setSlot] = useState('12–15');

  // The phone takes the shipping country's code, until someone types a number.
  const changeShipTo = (code: CountryCode | null) => {
    setShipTo(code);
    if (code && !phone) setPhoneCountry(code);
  };
  const changePhone = (value: string, details: PhoneDetails) => {
    setPhone(value);
    setPhoneValid(details.valid);
  };
  const ready = !!shipTo && phoneValid && !!day;

  return (
    <View style={[styles.screen, { backgroundColor: colors.background }]}>
      <ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
        <Steps steps={STEPS} value={1} />
        <Heading level={3}>Delivery details</Heading>
        <CountryPicker label="Ship to" value={shipTo} onValueChange={changeShipTo} />
        <PhoneField
          label="Phone for the courier"
          value={phone}
          onValueChange={changePhone}
          country={phoneCountry}
          onCountryChange={setPhoneCountry}
          helperText="Only for this delivery"
        />
        <DatePickerField label="Delivery day" value={day} onConfirm={setDay} minDate={tomorrow} />
        <Text weight="medium">Time window</Text>
        <SegmentedControl items={WINDOWS} value={slot} onValueChange={setSlot} accessibilityLabel="Time window" />
      </ScrollView>
      <View style={styles.footer}>
        <Button size="lg" disabled={!ready}>
          {ready ? 'Continue to payment' : 'Add a phone number'}
        </Button>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  screen: { flex: 1 },
  content: { gap: 14, padding: 20 },
  footer: { padding: 16 },
});
```

## Components used

- [CountryPicker](/docs/components/country-picker): where it ships, with flags and search
- [PhoneField](/docs/components/phone-field): controlled `country`, so it can follow the shipping country, and `details.valid`
- [DatePickerField](/docs/components/date-picker#in-a-form-field): the day, from tomorrow with `minDate`
- [SegmentedControl](/docs/components/segmented-control): the time window
- [Steps](/docs/components/steps), [Button](/docs/components/button), [Heading, Text](/docs/components/text)

## How it works

- **A sensible default, not a trap.** Changing the shipping country also changes the phone's code, but only while the phone is empty: someone abroad who types their own number keeps it.
- **Continue says what's missing** until the number is valid, rather than greying out without a word.
