Skip to main content

Overview

The Ai Studio application settings control essential business configuration such as location validation, delivery radius, and reservation management. Settings are stored in Firestore and cached locally for performance.

AppSettings Interface

Application settings are defined by the AppSettings interface:
types.ts
export interface AppSettings {
  location?: {
    lat: number;
    lng: number;
    address?: string;
  };
  deliveryRadius: number; // in meters
  enableLocationValidation: boolean;
}

Configuration Parameters

Location Settings

location
object
The business location coordinates and address
lat
number
required
Latitude coordinate of the business locationExample: 40.7128
lng
number
required
Longitude coordinate of the business locationExample: -74.0060
address
string
Human-readable address stringExample: "123 Main Street, New York, NY"

Delivery Configuration

deliveryRadius
number
required
Maximum delivery distance in meters from the business locationThis value determines the service area for delivery orders. Customer addresses beyond this radius will be rejected.Example: 5000 (5 kilometers)
enableLocationValidation
boolean
required
Enable or disable location-based delivery validationWhen true, customer addresses are validated against the delivery radius. When false, all delivery addresses are accepted.
Disabling location validation may result in orders being placed outside your serviceable area.

Reservation Settings

Reservation-specific settings are managed through the ReservationSettings interface:
types.ts
export interface ReservationSettings {
  duration: number;
  minBookingTime: number;
  initialBlockTime: number;
  extensionBlockTime: number;
  modificationLockTime: number;
  slotInterval: number;
}

Reservation Parameters

duration
number
required
Default duration for each reservation in minutesExample: 120 (2 hours)
minBookingTime
number
required
Minimum advance booking time required in minutesPrevents customers from making last-minute reservations that cannot be fulfilled.Example: 60 (1 hour in advance)
initialBlockTime
number
required
Time in minutes to block a table before the reservation startsAllows for table preparation and ensures availability.Example: 15 (15 minutes before)
extensionBlockTime
number
required
Time in minutes to block a table after the reservation endsProvides buffer time for table turnover and cleaning.Example: 30 (30 minutes after)
modificationLockTime
number
required
Time in minutes before a reservation when modifications are lockedPrevents last-minute changes that could disrupt operations.Example: 30 (30 minutes before)
slotInterval
number
required
Time interval in minutes between available reservation slotsExample: 30 (slots at :00 and :30)

Managing Settings

Retrieving Settings

Fetch the current application settings from Firestore:
import { getSettings } from './services/settingsService';

const settings = await getSettings();

if (settings) {
  console.log('Delivery radius:', settings.deliveryRadius);
  console.log('Location validation:', settings.enableLocationValidation);
  
  if (settings.location) {
    console.log('Business location:', settings.location);
  }
}
The getSettings() function returns null if no settings document exists in Firestore.

Saving Settings

Update application settings:
import { saveSettings } from './services/settingsService';
import type { AppSettings } from './types';

const newSettings: AppSettings = {
  location: {
    lat: 40.7128,
    lng: -74.0060,
    address: '123 Main Street, New York, NY'
  },
  deliveryRadius: 5000, // 5km
  enableLocationValidation: true
};

try {
  await saveSettings(newSettings);
  console.log('Settings saved successfully');
} catch (error) {
  console.error('Failed to save settings:', error);
}
The saveSettings() function uses Firestore’s merge option, so you can update partial settings without overwriting the entire document.

Storage Location

Settings are stored in Firestore at:
Collection: settings
Document ID: general
settingsService.ts
const SETTINGS_COLLECTION = 'settings';
const SETTINGS_DOC_ID = 'general';

Local Storage Management

The settings service provides a utility to clear local storage while preserving specific keys:
import { clearLocalStorage } from './services/settingsService';

// Clear all localStorage except theme settings
clearLocalStorage();
Calling clearLocalStorage() will trigger a page reload to fetch fresh data from Firebase.
The function preserves specific keys (e.g., 'pizzeria-theme') to maintain user preferences across cache clears.

Error Handling

Both getSettings() and saveSettings() include error handling:
  • getSettings(): Returns null on error and logs to console
  • saveSettings(): Throws an error that should be caught by the caller
try {
  const settings = await getSettings();
  if (!settings) {
    // Handle missing settings - initialize with defaults
  }
} catch (error) {
  console.error('Error fetching settings:', error);
}

Best Practices

Ensure latitude is between -90 and 90, and longitude is between -180 and 180.
const isValidLocation = (lat: number, lng: number): boolean => {
  return lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
};
Consider your delivery capabilities when setting the radius. A typical restaurant might use:
  • Urban area: 2000-3000 meters
  • Suburban area: 5000-8000 meters
  • Rural area: 10000+ meters
Balance customer convenience with operational efficiency:
  • duration: 90-120 minutes for typical dining
  • minBookingTime: 60-120 minutes to prepare
  • slotInterval: 15-30 minutes for flexibility

Build docs developers (and LLMs) love