File tree Expand file tree Collapse file tree 1 file changed +48
-12
lines changed
packages/web-backend/src/Users Expand file tree Collapse file tree 1 file changed +48
-12
lines changed Original file line number Diff line number Diff line change @@ -181,21 +181,57 @@ export class UsersOnboarding extends Effect.Service<UsersOnboarding>()(
181181 skipToDashboard : Effect . fn ( "Onboarding.skipToDashboard" ) ( function * ( ) {
182182 const currentUser = yield * CurrentUser ;
183183
184- yield * db . use ( ( db ) =>
184+ const [ user ] = yield * db . use ( ( db ) =>
185185 db
186- . update ( Db . users )
187- . set ( {
188- name : "Cap" ,
189- onboardingSteps : {
190- welcome : true ,
191- organizationSetup : true ,
192- customDomain : true ,
193- inviteTeam : true ,
194- download : true ,
195- } ,
196- } )
186+ . select ( )
187+ . from ( Db . users )
197188 . where ( Dz . eq ( Db . users . id , currentUser . id ) ) ,
198189 ) ;
190+
191+ const shouldUsePlaceholder = ! user . onboardingSteps ?. welcome ;
192+ const userName = shouldUsePlaceholder ? "Your name" : user . name ;
193+ const orgName = shouldUsePlaceholder
194+ ? "Your Organization"
195+ : `${ user . name } 's organization` ;
196+
197+ yield * db . use ( ( db ) =>
198+ db . transaction ( async ( tx ) => {
199+ await tx
200+ . update ( Db . users )
201+ . set ( {
202+ name : userName ,
203+ onboardingSteps : {
204+ welcome : true ,
205+ organizationSetup : true ,
206+ customDomain : true ,
207+ inviteTeam : true ,
208+ download : true ,
209+ } ,
210+ } )
211+ . where ( Dz . eq ( Db . users . id , currentUser . id ) ) ;
212+
213+ const [ existingOrg ] = await tx
214+ . select ( )
215+ . from ( Db . organizations )
216+ . where (
217+ Dz . eq ( Db . organizations . id , currentUser . activeOrganizationId ) ,
218+ ) ;
219+
220+ if ( ! existingOrg || ! user . onboardingSteps ?. organizationSetup ) {
221+ await tx
222+ . update ( Db . organizations )
223+ . set ( {
224+ name : orgName ,
225+ } )
226+ . where (
227+ Dz . eq (
228+ Db . organizations . id ,
229+ currentUser . activeOrganizationId ,
230+ ) ,
231+ ) ;
232+ }
233+ } ) ,
234+ ) ;
199235 } ) ,
200236 } ;
201237 } ) ,
You can’t perform that action at this time.
0 commit comments