> ## Documentation Index
> Fetch the complete documentation index at: https://docs.traza.com.au/llms.txt
> Use this file to discover all available pages before exploring further.

# Booking Reminders

> Documentation for the booking reminder feature

## Overview

This feature automatically sends reminder emails to customers 48 hours before their confirmed tattoo appointments.

## How It Works

### Scheduled Function

* **Schedule**: Daily at 9:00 AM Sydney time
* **Function**: `scheduled.sendBookingReminders`
* **Logic**: Checks for `CONFIRMED` bookings happening in 2 days and sends reminder emails

### Email Template

* **Template**: `BookingReminderEmail.tsx`
* **Content**: Appointment details, preparation tips, booking management link
* **Style**: Follows existing email template design

### Database Updates

* **New Fields**: Added to `BookingConfirmed` type:
  * `reminderEmailSent?: boolean`
  * `reminderEmailSentAt?: number`

## Implementation Details

### Files Created/Modified

1. **Types**:

   * `types/models/bookings.ts` - Added reminder tracking fields

2. **Email Template**:

   * `functions/emails/templates/BookingReminderEmail.tsx` - New template

3. **Email Function**:

   * `functions/src/email/sendBookingReminder.ts` - Email sending logic

4. **Scheduled Function**:

   * `functions/src/scheduled/sendBookingReminders.ts` - Main scheduled job

5. **Functions Index**:
   * `functions/src/index.ts` - Export new scheduled function

### Dependencies Added

* `date-fns-tz` - For proper timezone handling

## Deployment

### Prerequisites

1. Ensure Mailgun is properly configured
2. Set `FRONTEND_URL` environment variable for booking links
3. Verify Firebase Functions permissions for Pub/Sub

### Deploy Commands

```bash theme={null}
cd functions
npm run build
firebase deploy --only functions:scheduled.sendBookingReminders
```

## Testing

### Local Testing

```bash theme={null}
cd functions
npm run serve
# Use Firebase emulator to test the function
```

### Email Preview

```bash theme={null}
cd functions
npm run email:preview
# Navigate to the BookingReminderEmail template
```

## Monitoring

### Logs

* Check Cloud Functions logs for execution results
* Monitor success/failure rates
* Track email delivery via Mailgun dashboard

### Alerts

Consider setting up Cloud Monitoring alerts for:

* Function execution failures
* High email failure rates
* Function timeout issues

## Configuration

### Timezone

* All operations use Sydney timezone (`Australia/Sydney`)
* Handles DST automatically

### Reminder Timing

* Sends reminders exactly 48 hours before appointments
* Only processes `CONFIRMED` bookings
* Prevents duplicate emails with tracking flags

## Future Enhancements

* Multiple reminder types (24h, 2h before)
* User preference for reminder timing
* SMS reminders
* Artist notification preferences
