Add org switcher with create, switch, and delete

The sidebar org button was inert: clicking it did nothing. Add a real
dropdown menu listing every organization, a "New organization" entry
that re-enters onboarding without resetting the database, and a per-org
delete affordance with inline confirmation. Active org is now persisted
in a single-row app_state table so the snapshot keeps a stable
selection across restarts and the renderer drives switching via two new
IPC channels (setActiveOrganization, deleteOrganization).

- migration 006 adds app_state(id=1, active_org_id, updated_at)
- snapshot resolves active org from app_state with the first-org fallback
- OrganizationService gains setActive + delete + bootstrap upsert
- new OrgSwitcher renderer component keeps Shell.tsx lean
This commit is contained in:
ZacharyZhang-NY committed 2026-05-21 21:30:00 -04:00
1 parent 060fddf852
commit f2ac1be5de
14 files changed
+385 -16

No files matched your search

@@ -34,7 +34,7 @@ export class SnapshotService {
autoApproveHires: toBool(org.autoApproveHires),
reviewDeliverables: toBool(org.reviewDeliverables),
}));
const activeOrgId = organizations[0]?.id ?? null;
const activeOrgId = this.resolveActiveOrgId(organizations.map((org) => org.id));
const agents = list<AppSnapshot["agents"][number]>(this.db, "agents", "created_at asc")
.map((agent) => ({ ...agent, heartbeatEnabled: toBool(agent.heartbeatEnabled) }));
const tasks = list<AppSnapshot["tasks"][number]>(this.db, "tasks", "created_at asc")
@@ -82,4 +82,12 @@ export class SnapshotService {
auditEvents: list<AppSnapshot["auditEvents"][number]>(this.db, "audit_events", "created_at desc").slice(0, 200),
};
}
private resolveActiveOrgId(known: string[]): string | null {
const row = this.db.prepare("select active_org_id from app_state where id = 1")
.get() as { active_org_id: string | null } | undefined;
const stored = row?.active_org_id ?? null;
if (stored && known.includes(stored)) return stored;
return known[0] ?? null;
}
}