# Calendar ↔ Task Creation

**Date:** 2026-05-31  
**Status:** Draft  
**Spec:** 109  
**Tier:** All tiers  
**Depends on:** `calendar-module`, `tasks-board-engine`, `calendar-event-detail`, `foundation-auth-rbac`  
**Referenced by:** `calendar-module`, `tasks-board-engine`, `calendar-event-detail`

---

## Overview

Spec 37 (`calendar-module`) shows `tasks` projected onto the calendar via due dates (source='task'). Spec 102 (`calendar-event-detail`) shows read-only task-sourced events. This spec defines the bidirectional flow: creating a task from a calendar event, and creating a calendar event (deadline block) from a task.

---

## Flow 1: Create Task from Calendar Event

On any **manual** calendar event, the detail panel shows **[+ Create task]**:

```
┌──────────────────────────────────────────────────────────────┐
│  Kick-off call — Acme Corp          [Edit] [Delete] [✕]      │
│                                                              │
│  📅  Monday, June 2, 2026   10:00 – 11:00                    │
│                                                              │
│  [+ Create task]                                             │
└──────────────────────────────────────────────────────────────┘
```

Click → mini inline form:

```
│  New task from this event:                                   │
│  Title:   [Prepare kick-off agenda_______________________]   │
│  Assignee:[Dana Levi ▾]  Project: [Website Redesign ▾]      │
│  Due:     [2026-06-02]  (pre-filled from event date)         │
│  [Cancel]  [Create task]                                     │
```

On submit:
- Creates task in the linked project (or without project if none linked)
- Sets `tasks.due_date` to event start date
- Sets `tasks.lead_id = event.lead_id` if present (spec 100 schema delta)
- Does NOT link task to event (tasks are independently managed; event was inspiration, not the artifact)

---

## Flow 2: Create Calendar Block from Task

On any task detail view (spec `tasks-detail-communication`), an option in the `…` menu: **[Block time on calendar]**:

```
┌──────────────────────────────────────────────────────────────┐
│  Block time for: "Implement auth flow"                [✕]    │
│                                                              │
│  Date:    [2026-06-04]                                       │
│  Start:   [09:00]   End:  [11:00]                            │
│  Calendar: ● My calendar   ○ Team calendar                   │
│                                                              │
│  [Cancel]              [Add to calendar]                     │
└──────────────────────────────────────────────────────────────┘
```

Creates a `calendar_events` row:
- `source = 'manual'` (not 'task' — this is a time-block, not the due-date projection)
- `title = "Work on: {task.title}"`
- `project_id = task.project_id`
- No `task_id` link (prevents read-only lock; this is a personal time block, not a system event)

---

## Calendar View: Task Due Date Projection

Spec 37 existing behavior: tasks with `due_date` appear on the calendar as day markers (not time blocks). This spec does NOT change that projection — it only adds the two creation flows above.

Tasks projected onto the calendar:
- Appear at the top of the day column (all-day zone)
- Click → opens task detail in a side panel (not calendar event panel)
- Not editable from calendar; [View task] link opens `/tasks/:id`

---

## "Upcoming Tasks" Sidebar Panel

Optional sidebar toggle on `/calendar` (collapsed by default):

```
┌────────────────────────────────────────────────┐
│  Upcoming tasks (next 7 days)               [✕] │
│                                                 │
│  Today                                          │
│  ☐  Prepare kick-off agenda  · Website Redesign │
│  ☐  Review contract draft    · Acme Corp        │
│                                                 │
│  Tomorrow                                       │
│  ☐  Submit tax filing        · Admin            │
│                                                 │
│  [View all tasks →]                             │
└────────────────────────────────────────────────┘
```

Data from `GET /api/tasks?from=today&to=+7d&status=open`. Checkbox completes task inline (`PATCH /api/tasks/:id`).

---

## API

```
POST /api/calendar/events/:id/tasks
     → create task from event
       body: { title, assignee_id?, project_id?, due_date }
       Returns: { taskId }
       Requires: tasks:write

POST /api/tasks/:id/calendar-block
     → create calendar time-block from task
       body: { date, start_time, end_time }
       Returns: { eventId }
       Requires: calendar:write

GET /api/tasks
    → list tasks (existing endpoint, extended with from/to due_date filter)
      query: { from?, to?, status?, assignee_id?, project_id? }
      Requires: tasks:read
```

---

## Architecture Decisions

| Decision | Choice | Reason |
|----------|--------|--------|
| No task_id on time-block events | Not linked | Time blocks are personal scheduling aids; linking to a task would make them read-only (spec 102 locks task-sourced events); staff need to adjust times freely |
| Task due-date projection unchanged | Not converted to events | Task due dates are task lifecycle data; calendar is a secondary view of them; converting would create schema/status sync complexity |
| Upcoming tasks sidebar | Collapsed by default | Calendar is the primary view; the sidebar is for users who want both at once; most users navigate `/tasks` directly |
