Skip to content

Commit 5c3b24f

Browse files
authored
Fix newly created org missing from user's org list (#1799)
Resolves #1398 ### Changes - Updates org list in user info state after an org is created - Minor refactor to add `btrix` prefix to custom `update-user-info` event and replace unnecessary `defaultOrg` property
1 parent c5034e8 commit 5c3b24f

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

frontend/src/components/orgs-list.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export class OrgsList extends LiteElement {
1616
@property({ type: Array })
1717
orgList?: OrgData[] = [];
1818

19-
@property({ type: Object })
20-
defaultOrg?: UserOrg;
21-
2219
@property({ type: Boolean })
2320
skeleton? = false;
2421

@@ -30,9 +27,12 @@ export class OrgsList extends LiteElement {
3027
return this.renderSkeleton();
3128
}
3229

30+
const defaultOrg = this.userInfo?.orgs.find((org) => org.default === true);
31+
3332
return html`
3433
<ul class="overflow-hidden rounded-lg border">
35-
${this.orgList?.map(this.renderOrg)} ${this.renderOrgQuotas()}
34+
${this.orgList?.map(this.renderOrg(defaultOrg))}
35+
${this.renderOrgQuotas()}
3636
</ul>
3737
`;
3838
}
@@ -125,9 +125,16 @@ export class OrgsList extends LiteElement {
125125
return stop;
126126
}
127127

128-
private readonly renderOrg = (org: OrgData) => {
128+
private readonly renderOrg = (defaultOrg?: UserOrg) => (org: OrgData) => {
129+
if (!this.userInfo) return;
130+
131+
// There shouldn't really be a case where an org is in the org list but
132+
// not in user info, but disable clicking into the org just in case
133+
const isUserOrg = this.userInfo.orgs.some(({ id }) => id === org.id);
134+
129135
let defaultLabel: TemplateResult | undefined;
130-
if (this.defaultOrg && org.id === this.defaultOrg.id) {
136+
137+
if (defaultOrg && org.id === defaultOrg.id) {
131138
defaultLabel = html`<sl-tag size="small" variant="primary" class="mr-2"
132139
>${msg("Default")}</sl-tag
133140
>`;
@@ -136,9 +143,12 @@ export class OrgsList extends LiteElement {
136143

137144
return html`
138145
<li
139-
class="flex items-center justify-between border-t bg-white p-3 text-primary first:border-t-0 hover:text-indigo-400"
146+
class="${isUserOrg
147+
? ""
148+
: "select-none cursor-not-allowed opacity-50"} flex items-center justify-between border-t bg-white p-3 text-primary first:border-t-0 hover:text-indigo-400"
140149
role="button"
141150
@click=${this.makeOnOrgClick(org)}
151+
aria-disabled="${isUserOrg}"
142152
>
143153
<div class="mr-2 font-medium transition-colors">
144154
${defaultLabel}${org.name}

frontend/src/features/accounts/account-settings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const { PASSWORD_MINLENGTH, PASSWORD_MAXLENGTH, PASSWORD_MIN_SCORE } =
1919
PasswordService;
2020

2121
/**
22-
* @fires update-user-info
22+
* @fires btrix-update-user-info
2323
*/
2424
@localized()
2525
@customElement("btrix-request-verify")
@@ -337,7 +337,7 @@ export class AccountSettings extends LiteElement {
337337
}),
338338
});
339339

340-
this.dispatchEvent(new CustomEvent("update-user-info"));
340+
this.dispatchEvent(new CustomEvent("btrix-update-user-info"));
341341
this.notify({
342342
message: msg("Your name has been updated."),
343343
variant: "success",
@@ -377,7 +377,7 @@ export class AccountSettings extends LiteElement {
377377
}),
378378
});
379379

380-
this.dispatchEvent(new CustomEvent("update-user-info"));
380+
this.dispatchEvent(new CustomEvent("btrix-update-user-info"));
381381
this.notify({
382382
message: msg("Your email has been updated."),
383383
variant: "success",
@@ -417,7 +417,7 @@ export class AccountSettings extends LiteElement {
417417
});
418418

419419
this.isChangingPassword = false;
420-
this.dispatchEvent(new CustomEvent("update-user-info"));
420+
this.dispatchEvent(new CustomEvent("btrix-update-user-info"));
421421
this.notify({
422422
message: msg("Your password has been updated."),
423423
variant: "success",

frontend/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export class App extends LiteElement {
365365
: { slug: "", name: msg("All Organizations") };
366366
if (!selectedOption) {
367367
console.debug(
368-
`Could't find organization with slug ${this.appState.orgSlug}`,
368+
`Couldn't find organization with slug ${this.appState.orgSlug}`,
369369
orgs,
370370
);
371371
return;
@@ -575,7 +575,7 @@ export class App extends LiteElement {
575575
case "home":
576576
return html`<btrix-home
577577
class="w-full md:bg-neutral-50"
578-
@update-user-info=${(e: CustomEvent) => {
578+
@btrix-update-user-info=${(e: CustomEvent) => {
579579
e.stopPropagation();
580580
void this.updateUserInfo();
581581
}}
@@ -601,7 +601,7 @@ export class App extends LiteElement {
601601
.split("/")[0] || "home";
602602
return html`<btrix-org
603603
class="w-full"
604-
@update-user-info=${(e: CustomEvent) => {
604+
@btrix-update-user-info=${(e: CustomEvent) => {
605605
e.stopPropagation();
606606
void this.updateUserInfo();
607607
}}
@@ -619,7 +619,7 @@ export class App extends LiteElement {
619619
case "accountSettings":
620620
return html`<btrix-account-settings
621621
class="mx-auto box-border w-full max-w-screen-desktop p-2 md:py-8"
622-
@update-user-info=${(e: CustomEvent) => {
622+
@btrix-update-user-info=${(e: CustomEvent) => {
623623
e.stopPropagation();
624624
void this.updateUserInfo();
625625
}}

frontend/src/pages/home.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { maxLengthValidator } from "@/utils/form";
1212
import LiteElement, { html } from "@/utils/LiteElement";
1313
import type { OrgData } from "@/utils/orgs";
1414

15+
/**
16+
* @fires btrix-update-user-info
17+
*/
1518
@localized()
1619
@customElement("btrix-home")
1720
export class Home extends LiteElement {
@@ -153,9 +156,6 @@ export class Home extends LiteElement {
153156
<btrix-orgs-list
154157
.userInfo=${this.userInfo}
155158
.orgList=${this.orgList}
156-
.defaultOrg=${this.userInfo?.orgs.find(
157-
(org) => org.default === true,
158-
)}
159159
@update-quotas=${this.onUpdateOrgQuotas}
160160
></btrix-orgs-list>
161161
</section>
@@ -219,8 +219,9 @@ export class Home extends LiteElement {
219219
size="small"
220220
?loading=${this.isSubmittingNewOrg}
221221
?disabled=${this.isSubmittingNewOrg}
222-
>${msg("Create Org")}</sl-button
223222
>
223+
${msg("Create Org")}
224+
</sl-button>
224225
</div>
225226
`
226227
: ""}
@@ -302,7 +303,12 @@ export class Home extends LiteElement {
302303
body: JSON.stringify(params),
303304
});
304305

306+
// Update user info since orgs are checked against userInfo.orgs
307+
this.dispatchEvent(new CustomEvent("btrix-update-user-info"));
308+
309+
await this.updateComplete;
305310
void this.fetchOrgs();
311+
306312
this.notify({
307313
message: msg(str`Created new org named "${params.name}".`),
308314
variant: "success",

frontend/src/pages/org/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const UUID_REGEX =
8080
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
8181

8282
/**
83-
* @fires update-user-info
83+
* @fires btrix-update-user-info
8484
*/
8585
@localized()
8686
@customElement("btrix-org")
@@ -725,7 +725,7 @@ export class Org extends LiteElement {
725725
});
726726

727727
await this.dispatchEvent(
728-
new CustomEvent("update-user-info", { bubbles: true }),
728+
new CustomEvent("btrix-update-user-info", { bubbles: true }),
729729
);
730730
const newSlug = e.detail.slug;
731731
if (newSlug) {

0 commit comments

Comments
 (0)