Files
classroomio/src/lib/components/Org/Settings/index.svelte
T

95 lines
2.3 KiB
Svelte
Raw Normal View History

2023-05-02 23:55:26 +00:00
<script>
import { page } from '$app/stores';
2023-05-02 23:55:26 +00:00
import { Tabs, Tab, TabContent } from 'carbon-components-svelte';
import Profile from './Profile.svelte';
import LandingpageSettings from './LandingpageSettings.svelte';
2023-05-02 23:55:26 +00:00
// import Account from './Account.svelte';
import OrgSettings from './OrgSettings.svelte';
import { onMount } from 'svelte';
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
2023-09-15 09:22:51 +01:00
import { isOrgAdmin } from '$lib/utils/store/org';
2023-09-26 09:01:53 +00:00
import Integrations from './Integrations.svelte';
let selected = 0;
let query = new URLSearchParams($page.url.search);
let tabKey = query.get('tab') || '';
const tabs = [
{
key: 0,
label: 'Profile',
tabKey: '',
2023-09-15 09:22:51 +01:00
href: $page.url.pathname,
disabled: false
},
{
key: 1,
label: 'Organization',
tabKey: 'org',
2023-09-15 09:22:51 +01:00
href: `${$page.url.pathname}?tab=org`,
disabled: !$isOrgAdmin
},
{
key: 2,
label: 'LandingPage',
tabKey: 'landingpage',
2023-09-15 09:22:51 +01:00
href: `${$page.url.pathname}?tab=landingpage`,
disabled: !$isOrgAdmin
2023-09-26 09:01:53 +00:00
},
{
key: 3,
label: 'Integrations',
tabKey: 'integrations',
href: `${$page.url.pathname}?tab=integrations`,
disabled: false
}
];
function getSelectedByTab(tabKey = '') {
const tab = tabs.find((t) => t.tabKey === tabKey);
return tab ? tab.key : 0;
}
function changeRouteOnTabChange(key = 0) {
const tab = tabs.find((t) => t.key === key);
if (tab) {
return goto(tab.href);
}
}
onMount(() => {
selected = getSelectedByTab(tabKey);
});
$: {
if (browser) {
changeRouteOnTabChange(selected);
}
}
2023-05-02 23:55:26 +00:00
</script>
<Tabs autoWidth bind:selected>
{#each tabs as tab}
2023-09-15 09:22:51 +01:00
<Tab label={tab.label} href={tab.href} disabled={tab.disabled} />
{/each}
2023-05-02 23:55:26 +00:00
<!-- <Tab label="Account" /> -->
<svelte:fragment slot="content">
<TabContent class="w-full p-0">
2023-05-02 23:55:26 +00:00
<Profile />
</TabContent>
<!-- <TabContent>
<Account />
</TabContent> -->
<TabContent class="w-full p-0">
2023-05-02 23:55:26 +00:00
<OrgSettings />
</TabContent>
<TabContent class="w-full p-0">
<LandingpageSettings />
</TabContent>
2023-09-26 09:01:53 +00:00
<TabContent class="w-full p-0">
<Integrations />
</TabContent>
2023-05-02 23:55:26 +00:00
</svelte:fragment>
</Tabs>