@@ -29,13 +29,14 @@ import (
2929// Model is the onboarding orchestrator.
3030type Model struct {
3131 // Dependencies available from start
32- ctx context.Context
33- theme styles.Theme
34- services api.APIServices
35- prefs preferences.Preferences
36- auth iauth.Auth
37- syncer powersync.Syncer
38- scope log.Scope
32+ ctx context.Context
33+ theme styles.Theme
34+ services api.APIServices
35+ userPrefs preferences.UserPreferences
36+ orgPrefs preferences.OrgPreferences
37+ auth iauth.Auth
38+ syncer powersync.Syncer
39+ scope log.Scope
3940
4041 // Accumulated state from step completions
4142 user * iauth.User
@@ -56,16 +57,20 @@ func New(
5657 ctx context.Context ,
5758 theme styles.Theme ,
5859 services api.APIServices ,
59- prefs preferences.Preferences ,
60+ userPrefs preferences.UserPreferences ,
61+ orgPrefs preferences.OrgPreferences ,
6062 authService iauth.Auth ,
6163 syncer powersync.Syncer ,
6264 scope log.Scope ,
6365) * Model {
6466 if ctx == nil {
6567 panic ("ctx is nil" )
6668 }
67- if prefs == nil {
68- panic ("prefs is nil" )
69+ if userPrefs == nil {
70+ panic ("userPrefs is nil" )
71+ }
72+ if orgPrefs == nil {
73+ panic ("orgPrefs is nil" )
6974 }
7075 if authService == nil {
7176 panic ("authService is nil" )
@@ -77,20 +82,21 @@ func New(
7782 scope = scope .Child ("onboarding" )
7883
7984 return & Model {
80- ctx : ctx ,
81- theme : theme ,
82- services : services ,
83- prefs : prefs ,
84- auth : authService ,
85- syncer : syncer ,
86- scope : scope ,
85+ ctx : ctx ,
86+ theme : theme ,
87+ services : services ,
88+ userPrefs : userPrefs ,
89+ orgPrefs : orgPrefs ,
90+ auth : authService ,
91+ syncer : syncer ,
92+ scope : scope ,
8793 }
8894}
8995
90- // SetPreferences replaces the preferences used by subsequent onboarding steps.
91- // Called by the app when switching to a different org-scoped config .
92- func (m * Model ) SetPreferences (prefs preferences.Preferences ) {
93- m .prefs = prefs
96+ // SetOrgPreferences replaces the org preferences used by subsequent onboarding steps.
97+ // Called by the app when switching to a different organization .
98+ func (m * Model ) SetOrgPreferences (prefs preferences.OrgPreferences ) {
99+ m .orgPrefs = prefs
94100}
95101
96102// Init starts the onboarding flow with auth check.
@@ -105,7 +111,7 @@ func (m *Model) Init() tea.Cmd {
105111// for selection instead of auto-selecting.
106112func (m * Model ) StartFromOrgSelect () tea.Cmd {
107113 m .scope .Info ("onboarding started from org select" )
108- return m .setStep (organizations .NewSelect (m .ctx , m .theme , m .services , m .prefs , m .auth , m .scope ))
114+ return m .setStep (organizations .NewSelect (m .ctx , m .theme , m .services , m .userPrefs , m .auth , m .scope ))
109115}
110116
111117// Update handles messages and orchestrates step transitions.
@@ -125,32 +131,32 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
125131 if msg .NeedsAuth {
126132 return m .setStep (auth .NewAuthenticate (m .ctx , m .theme , m .auth , m .scope ))
127133 }
128- return m .setStep (role .New (m .theme , m .prefs , m .scope ))
134+ return m .setStep (role .New (m .theme , m .userPrefs , m .scope ))
129135
130136 case msgs.Authenticated :
131137 m .scope .Info ("user authenticated" , "user_id" , msg .User .ID )
132138 m .user = & msg .User
133- return m .setStep (role .New (m .theme , m .prefs , m .scope ))
139+ return m .setStep (role .New (m .theme , m .userPrefs , m .scope ))
134140
135141 // Role messages
136142 case msgs.RoleSelected :
137143 m .scope .Info ("role selected" , slog .String ("role" , msg .Role ))
138- return m .setStep (organizations .NewSelect (m .ctx , m .theme , m .services , m .prefs , m .auth , m .scope ))
144+ return m .setStep (organizations .NewSelect (m .ctx , m .theme , m .services , m .userPrefs , m .auth , m .scope ))
139145
140146 // Organization messages
141147 case msgs.OrgSelected :
142148 m .scope .Info ("organization selected" , slog .String ("org_id" , msg .Org .ID .String ()))
143149 m .org = & msg .Org
144- return m .setStep (accounts .NewSelect (m .ctx , m .theme , msg .Org , m .services , m .prefs , m .scope ))
150+ return m .setStep (accounts .NewSelect (m .ctx , m .theme , msg .Org , m .services , m .orgPrefs , m .scope ))
145151
146152 case msgs.NoOrgs :
147153 m .scope .Debug ("no organizations found" )
148- return m .setStep (organizations .NewCreate (m .ctx , m .theme , m .services , m .prefs , m .scope ))
154+ return m .setStep (organizations .NewCreate (m .ctx , m .theme , m .services , m .userPrefs , m .scope ))
149155
150156 case msgs.OrgCreated :
151157 m .scope .Info ("organization created" , slog .String ("org_id" , msg .Org .ID .String ()))
152158 m .org = & msg .Org
153- return m .setStep (accounts .NewSelect (m .ctx , m .theme , msg .Org , m .services , m .prefs , m .scope ))
159+ return m .setStep (accounts .NewSelect (m .ctx , m .theme , msg .Org , m .services , m .orgPrefs , m .scope ))
154160
155161 // Account messages
156162 case msgs.AccountSelected :
@@ -161,7 +167,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
161167
162168 case msgs.NoAccounts :
163169 m .scope .Debug ("no accounts found" )
164- return m .setStep (accounts .NewCreate (m .ctx , m .theme , msg .Org , m .services , m .prefs , m .scope ))
170+ return m .setStep (accounts .NewCreate (m .ctx , m .theme , msg .Org , m .services , m .orgPrefs , m .scope ))
165171
166172 case msgs.AccountCreated :
167173 m .scope .Info ("account created" , slog .String ("account_id" , msg .Account .ID .String ()))
@@ -172,7 +178,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
172178 // Datadog messages
173179 case msgs.DatadogReady :
174180 m .scope .Debug ("datadog ready" )
175- return m .setStep (workspaces .NewSelect (m .ctx , m .theme , * m .account , m .services , m .prefs , m .scope ))
181+ return m .setStep (workspaces .NewSelect (m .ctx , m .theme , * m .account , m .services , m .orgPrefs , m .scope ))
176182
177183 case msgs.DatadogNeeded :
178184 m .scope .Debug ("datadog setup needed" )
@@ -194,7 +200,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
194200
195201 case msgs.DatadogDiscoveryComplete :
196202 m .scope .Info ("datadog discovery complete" )
197- return m .setStep (workspaces .NewSelect (m .ctx , m .theme , * m .account , m .services , m .prefs , m .scope ))
203+ return m .setStep (workspaces .NewSelect (m .ctx , m .theme , * m .account , m .services , m .orgPrefs , m .scope ))
198204
199205 // Workspace messages
200206 case msgs.WorkspaceSelected :
0 commit comments