Flow 1: Work Email Verification
flowchart TD
A[User enters work email in settings] --> B[POST /user/invitation-emails]
B --> C[Expire existing pending requests]
C --> D[Create pending request with token]
D --> E[Send verification email to new work email]
E --> F{User clicks verify link?}
F -->|Yes within 24h| G[GET /app/confirm-work-email/token]
F -->|No or Expired| H[Link expired page shown]
G --> I[Save work_email on user]
I --> J[Sync to HubSpot]
J --> K[Send confirmation to personal email]
K --> L[Show success page]
Flow 2: Calendar Email Preference
flowchart TD
M[User opens email preferences] --> N[Selects: Personal / Work / Both]
N --> O[PUT /api/currentUser/calendarEmailPreference]
O --> P[Preference saved]
Flow 3: Event Join - Calendar Invite Routing
flowchart TD
Q[User joins or RSVPs to event] --> R{Read calendar_email_preference}
R -->|personal| S[Send invite to personal email only]
R -->|work| T{Work email set?}
R -->|both| U{Work email set?}
T -->|Yes| V[Send invite to work email only]
T -->|No| S
U -->|Yes| W[Send invite to both emails]
U -->|No| S
Flow 4: Sequence - Work Email Verification
sequenceDiagram
participant App
participant API
participant DB
participant SES
participant User
App->>API: POST /user/invitation-emails
API->>DB: Expire old pending requests
API->>DB: INSERT work_email_change_requests
API->>SES: Send verification to new work email
API->>App: 201 verification_sent
User->>API: GET /app/confirm-work-email/token
API->>DB: Validate token pending + not expired
API->>DB: UPDATE users SET work_email
API->>DB: UPDATE request SET completed
API->>SES: Send confirmation to personal email
API->>User: HTML success page