1
1
import { localized , msg , str } from "@lit/localize" ;
2
2
import type { SlInput , SlInputEvent } from "@shoelace-style/shoelace" ;
3
3
import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js" ;
4
- import { type PropertyValues , type TemplateResult } from "lit" ;
4
+ import { type PropertyValues } from "lit" ;
5
5
import { customElement , property , state } from "lit/decorators.js" ;
6
6
7
7
import type { InviteSuccessDetail } from "@/features/accounts/invite-form" ;
@@ -15,6 +15,11 @@ import type { OrgData } from "@/utils/orgs";
15
15
import slugifyStrict from "@/utils/slugify" ;
16
16
17
17
/**
18
+ * Home page when org is not selected.
19
+ * Currently, only visible to superadmins--redirects to user's org, otherwise
20
+ *
21
+ * TODO Refactor out superadmin UI
22
+ *
18
23
* @fires btrix-update-user-info
19
24
*/
20
25
@localized ( )
@@ -62,57 +67,44 @@ export class Home extends LiteElement {
62
67
this . navTo ( `/orgs/${ this . slug } ` ) ;
63
68
} else if ( changedProperties . has ( "userInfo" ) && this . userInfo ) {
64
69
if ( this . userInfo . isSuperAdmin ) {
65
- void this . fetchOrgs ( ) ;
70
+ if ( this . userInfo . orgs . length ) {
71
+ void this . fetchOrgs ( ) ;
72
+ } else {
73
+ this . isAddingOrg = true ;
74
+ this . isAddOrgFormVisible = true ;
75
+ }
66
76
} else {
67
77
this . navTo ( `/account/settings` ) ;
68
78
}
69
79
}
70
80
}
71
81
72
- async updated (
73
- changedProperties : PropertyValues < this> & Map < string , unknown > ,
74
- ) {
75
- const orgListUpdated = changedProperties . has ( "orgList" ) && this . orgList ;
76
- const userInfoUpdated = changedProperties . has ( "userInfo" ) && this . userInfo ;
77
- if ( orgListUpdated || userInfoUpdated ) {
78
- if ( this . userInfo ?. isSuperAdmin && this . orgList && ! this . orgList . length ) {
79
- this . isAddingOrg = true ;
80
- }
82
+ render ( ) {
83
+ if ( ! this . userInfo || ! this . userInfo . isSuperAdmin ) {
84
+ return ;
81
85
}
82
- }
83
86
84
- render ( ) {
85
- if ( ! this . userInfo || ! this . orgList ) {
87
+ if ( this . userInfo . orgs . length && ! this . orgList ) {
86
88
return html `
87
89
<div class="my-24 flex items-center justify-center text-3xl">
88
90
<sl-spinner></sl-spinner>
89
91
</div>
90
92
` ;
91
93
}
92
94
93
- let title : string | undefined ;
94
- let content : TemplateResult < 1 > | undefined ;
95
-
96
- if ( this . userInfo . isSuperAdmin ) {
97
- title = msg ( "Welcome" ) ;
98
- content = this . renderAdminOrgs ( ) ;
99
- } else {
100
- title = msg ( "Organizations" ) ;
101
- content = this . renderLoggedInNonAdmin ( ) ;
102
- }
103
-
104
95
return html `
105
96
<div class="bg-white">
106
97
<header
107
98
class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4 md:py-8"
108
99
>
109
- <h1 class="text-xl font-medium">${ title } </h1>
100
+ <h1 class="text-xl font-medium">${ msg ( "Welcome" ) } </h1>
110
101
</header>
111
102
<hr />
112
103
</div>
113
104
<main class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4">
114
- ${ content }
105
+ ${ this . renderAdminOrgs ( ) }
115
106
</main>
107
+ ${ this . renderAddOrgDialog ( ) }
116
108
` ;
117
109
}
118
110
@@ -182,8 +174,6 @@ export class Home extends LiteElement {
182
174
</section>
183
175
</div>
184
176
</div>
185
-
186
- ${ this . renderAddOrgDialog ( ) }
187
177
` ;
188
178
}
189
179
@@ -277,24 +267,6 @@ export class Home extends LiteElement {
277
267
` ;
278
268
}
279
269
280
- private renderLoggedInNonAdmin ( ) {
281
- if ( this . orgList && ! this . orgList . length ) {
282
- return html `<div class="rounded-lg border bg-white p-4 md:p-8">
283
- <p class="text-center text-neutral-400">
284
- ${ msg ( "You don't have any organizations." ) }
285
- </p>
286
- </div>` ;
287
- }
288
-
289
- return html `
290
- <btrix-orgs-list
291
- .userInfo=${ this . userInfo }
292
- .orgList=${ this . orgList }
293
- ?skeleton=${ ! this . orgList }
294
- ></btrix-orgs-list>
295
- ` ;
296
- }
297
-
298
270
private renderInvite ( ) {
299
271
return html `
300
272
<btrix-invite-form
@@ -384,9 +356,6 @@ export class Home extends LiteElement {
384
356
// Update user info since orgs are checked against userInfo.orgs
385
357
this . dispatchEvent ( new CustomEvent ( "btrix-update-user-info" ) ) ;
386
358
387
- await this . updateComplete ;
388
- void this . fetchOrgs ( ) ;
389
-
390
359
this . notify ( {
391
360
message : msg ( str `Created new org named "${ params . name } ".` ) ,
392
361
variant : "success" ,
0 commit comments