From eeab64a0d1f329bb92951cf97f1cc0416e97074d Mon Sep 17 00:00:00 2001 From: sua yoo Date: Wed, 24 Apr 2024 01:50:55 -0700 Subject: [PATCH] Redirect if org with slug doesn't exist (#1740) Resolves https://github.com/webrecorder/browsertrix/issues/1739 Redirect to first user's first org if an org with current slug doesn't exist. --- frontend/src/pages/org/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/org/index.ts b/frontend/src/pages/org/index.ts index ea033ec2..468000d7 100644 --- a/frontend/src/pages/org/index.ts +++ b/frontend/src/pages/org/index.ts @@ -183,10 +183,17 @@ export class Org extends LiteElement { async willUpdate(changedProperties: Map) { if ( - (changedProperties.has("userInfo") && this.userInfo) || - (changedProperties.has("slug") && this.slug) + (changedProperties.has("userInfo") || changedProperties.has("slug")) && + this.userInfo && + this.slug ) { - void this.updateOrg(); + if (this.userOrg) { + void this.updateOrg(); + } else { + // Couldn't find org with slug, redirect to first org + this.navTo(`/orgs/${this.userInfo.orgs[0].slug}`); + return; + } } if (changedProperties.has("openDialogName")) { // Sync URL to create dialog @@ -216,9 +223,6 @@ export class Org extends LiteElement { this.checkStorageQuota(); this.checkExecutionMinutesQuota(); } catch { - // TODO handle 404 - this.org = null; - this.notify({ message: msg("Sorry, couldn't retrieve organization at this time."), variant: "danger", @@ -253,8 +257,7 @@ export class Org extends LiteElement { render() { if (this.org === null) { - // TODO handle 404 and 500s - return ""; + return html``; } if (!this.org || !this.userInfo) {