Skip to content

Commit

Permalink
Fixes org switching
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser authored and mitchelljkotler committed Nov 29, 2023
1 parent e17e804 commit 7ca13f5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 deletions.
95 changes: 50 additions & 45 deletions src/pages/app/AccountNavigation/OrgMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
return orgs;
}
async function changeOrg(id) {
changeActive(id);
getOrgPromise = getOrg(id);
async function changeOrg(org) {
changeActive(org);
getOrgPromise = getOrg(org.id);
}
let getOrgPromise = getOrg(org.id);
Expand All @@ -70,6 +70,9 @@
color: var(--gray);
margin: 0;
}
.medium-width {
min-width: 20rem;
}
</style>

{#await getOrgPromise}
Expand Down Expand Up @@ -102,20 +105,21 @@
</span>
</MenuTitle>
<Menu>
{#if isPremiumOrg(activeOrg)}
<MenuInsert>
<CreditMeter
id="org-credits"
label={$_("authSection.credits.monthlyOrg")}
helpText={$_("authSection.credits.refreshOn", {
values: {
date: formatResetDate(activeOrg.credit_reset_date, $locale),
},
})}
value={activeOrg.monthly_credits}
max={activeOrg.monthly_credit_allowance}
/>
<!-- TODO: Support credit purchases (#342)
<div class="medium-width">
{#if isPremiumOrg(activeOrg)}
<MenuInsert>
<CreditMeter
id="org-credits"
label={$_("authSection.credits.monthlyOrg")}
helpText={$_("authSection.credits.refreshOn", {
values: {
date: formatResetDate(activeOrg.credit_reset_date, $locale),
},
})}
value={activeOrg.monthly_credits}
max={activeOrg.monthly_credit_allowance}
/>
<!-- TODO: Support credit purchases (#342)
<CreditMeter
id="purchased-credits"
label={$_("authSection.credits.purchased")}
Expand All @@ -134,36 +138,37 @@
{$_("authSection.credits.purchaseCreditsAdminOnly")}
</p>
{/if} -->
</MenuInsert>
{:else if isOrgAdmin(user)}
<MenuInsert>
<div class="freeOrg">
<h3 class="heading">
{$_("authSection.premiumUpgrade.orgHeading")}
</h3>
<p class="description">
{$_("authSection.premiumUpgrade.orgDescription")}
</p>
<Button
label={$_("authSection.premiumUpgrade.cta")}
fullWidth={true}
premium={true}
on:click={() => triggerPremiumUpgradeFlow(activeOrg)}
/>
<div class="learnMore">
<Link toUrl="/help/premium" color={true} on:click={close}>
{$_("authSection.premiumUpgrade.docs")}
</Link>
</MenuInsert>
{:else if isOrgAdmin(user)}
<MenuInsert>
<div class="freeOrg">
<h3 class="heading">
{$_("authSection.premiumUpgrade.orgHeading")}
</h3>
<p class="description">
{$_("authSection.premiumUpgrade.orgDescription")}
</p>
<Button
label={$_("authSection.premiumUpgrade.cta")}
fullWidth={true}
premium={true}
on:click={() => triggerPremiumUpgradeFlow(activeOrg)}
/>
<div class="learnMore">
<Link toUrl="/help/premium" color={true} on:click={close}>
{$_("authSection.premiumUpgrade.docs")}
</Link>
</div>
</div>
</div>
</MenuInsert>
{/if}
<OrgMemberList orgId={activeOrg.id} myId={user.id} />
{#await listOrgsPromise then orgOptions}
{#if orgOptions.length > 1}
<OrgPicker {activeOrg} {orgOptions} handleChange={changeOrg} />
</MenuInsert>
{/if}
{/await}
<OrgMemberList orgId={activeOrg.id} myId={user.id} />
{#await listOrgsPromise then orgOptions}
{#if orgOptions.length > 1}
<OrgPicker {activeOrg} {orgOptions} handleChange={changeOrg} />
{/if}
{/await}
</div>
</Menu>
</Dropdown>
{/if}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/app/AccountNavigation/OrgPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
export let activeOrg: Org;
export let loading = false;
export let orgOptions: Org[] = [];
export let handleChange: (id: string) => void = () => {};
export let handleChange: (org: Org) => void = () => {};
</script>

<style>
Expand Down Expand Up @@ -62,7 +62,7 @@
<MenuItem
on:click={() => {
closeDropdown("orgSelect");
handleChange?.(org.id);
handleChange?.(org);
}}
selected={org.id === activeOrg.id}
>
Expand Down

0 comments on commit 7ca13f5

Please sign in to comment.