@hyvor/design 1.1.23 → 1.1.24-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/HyvorBar/HyvorBar.svelte +23 -16
- package/dist/components/HyvorBar/HyvorBar.svelte.d.ts +2 -0
- package/dist/components/HyvorBar/Notice/BarLicense.svelte +2 -4
- package/dist/components/HyvorBar/Organization/BarOrganization.svelte +111 -0
- package/dist/components/HyvorBar/Organization/BarOrganization.svelte.d.ts +7 -0
- package/dist/components/HyvorBar/Organization/OrgsList.svelte +70 -0
- package/dist/components/HyvorBar/Organization/OrgsList.svelte.d.ts +7 -0
- package/dist/components/HyvorBar/bar.d.ts +18 -1
- package/dist/components/HyvorBar/bar.js +56 -22
- package/package.json +1 -1
|
@@ -3,11 +3,19 @@
|
|
|
3
3
|
import { onMount } from 'svelte';
|
|
4
4
|
import BarProducts, { PRODUCTS } from './BarProducts.svelte';
|
|
5
5
|
import BarSupport from './BarSupport.svelte';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
barUser,
|
|
8
|
+
initBar,
|
|
9
|
+
setInstanceAndProduct,
|
|
10
|
+
type BarConfig,
|
|
11
|
+
type BarUser as BarUserType
|
|
12
|
+
} from './bar.js';
|
|
7
13
|
import BarUpdates from './BarUpdates.svelte';
|
|
8
14
|
import IconCaretDownFill from '@hyvor/icons/IconCaretDownFill';
|
|
9
15
|
import BarNotice from './Notice/BarNotice.svelte';
|
|
10
16
|
import BarLicense from './Notice/BarLicense.svelte';
|
|
17
|
+
import BarOrganization from './Organization/BarOrganization.svelte';
|
|
18
|
+
import { type BarOrganization as BarOrganizationType } from './bar.js';
|
|
11
19
|
|
|
12
20
|
interface Props {
|
|
13
21
|
instance?: string;
|
|
@@ -27,16 +35,18 @@
|
|
|
27
35
|
authOverride?: {
|
|
28
36
|
user: BarUserType | null;
|
|
29
37
|
logoutUrl: string;
|
|
30
|
-
}
|
|
38
|
+
};
|
|
39
|
+
onOrganizationSwitch?: (org: BarOrganizationType) => void;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
let {
|
|
34
|
-
instance = 'https://hyvor.com',
|
|
35
|
-
product,
|
|
43
|
+
instance = 'https://hyvor.com',
|
|
44
|
+
product,
|
|
36
45
|
logo = `${instance}/api/public/logo/${product}.svg`,
|
|
37
46
|
config = {},
|
|
38
47
|
cloud = true,
|
|
39
|
-
authOverride = undefined
|
|
48
|
+
authOverride = undefined,
|
|
49
|
+
onOrganizationSwitch = () => {}
|
|
40
50
|
}: Props = $props();
|
|
41
51
|
|
|
42
52
|
let mobileShow = $state(false);
|
|
@@ -61,15 +71,15 @@
|
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
73
|
|
|
74
|
+
if (authOverride) {
|
|
75
|
+
barUser.set(authOverride.user);
|
|
76
|
+
}
|
|
77
|
+
|
|
64
78
|
onMount(() => {
|
|
65
79
|
setInstanceAndProduct(instance, product);
|
|
66
80
|
|
|
67
81
|
if (cloud) {
|
|
68
82
|
initBar();
|
|
69
|
-
} else {
|
|
70
|
-
if (authOverride) {
|
|
71
|
-
barUser.set(authOverride.user);
|
|
72
|
-
}
|
|
73
83
|
}
|
|
74
84
|
});
|
|
75
85
|
|
|
@@ -87,16 +97,12 @@
|
|
|
87
97
|
<div class="inner hds-box">
|
|
88
98
|
<div class="left">
|
|
89
99
|
<a class="logo" href="/">
|
|
90
|
-
<img
|
|
91
|
-
src={logo}
|
|
92
|
-
alt={product}
|
|
93
|
-
width="20"
|
|
94
|
-
height="20"
|
|
95
|
-
/>
|
|
100
|
+
<img src={logo} alt={product} width="20" height="20" />
|
|
96
101
|
<span class="name">
|
|
97
102
|
{getName()}
|
|
98
103
|
</span>
|
|
99
104
|
</a>
|
|
105
|
+
<BarOrganization onSwitch={onOrganizationSwitch} />
|
|
100
106
|
<BarLicense name={getName()} />
|
|
101
107
|
</div>
|
|
102
108
|
<div class="right">
|
|
@@ -132,7 +138,7 @@
|
|
|
132
138
|
z-index: 100;
|
|
133
139
|
}
|
|
134
140
|
.inner {
|
|
135
|
-
padding:
|
|
141
|
+
padding: 0px 29px;
|
|
136
142
|
display: flex;
|
|
137
143
|
align-items: center;
|
|
138
144
|
border-top-left-radius: 0;
|
|
@@ -143,6 +149,7 @@
|
|
|
143
149
|
display: flex;
|
|
144
150
|
align-items: center;
|
|
145
151
|
flex: 1;
|
|
152
|
+
height: 100%;
|
|
146
153
|
}
|
|
147
154
|
.logo {
|
|
148
155
|
display: flex;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type BarConfig, type BarUser as BarUserType } from './bar.js';
|
|
2
|
+
import { type BarOrganization as BarOrganizationType } from './bar.js';
|
|
2
3
|
interface Props {
|
|
3
4
|
instance?: string;
|
|
4
5
|
product: string;
|
|
@@ -13,6 +14,7 @@ interface Props {
|
|
|
13
14
|
user: BarUserType | null;
|
|
14
15
|
logoutUrl: string;
|
|
15
16
|
};
|
|
17
|
+
onOrganizationSwitch?: (org: BarOrganizationType) => void;
|
|
16
18
|
}
|
|
17
19
|
declare const HyvorBar: import("svelte").Component<Props, {}, "">;
|
|
18
20
|
type HyvorBar = ReturnType<typeof HyvorBar>;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
return daysDiff(endsAt);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function remainingCancelAtDAys(cancelAt: number | undefined | null)
|
|
25
|
+
function remainingCancelAtDAys(cancelAt: number | undefined | null): null | number {
|
|
26
26
|
if (!cancelAt) {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
@@ -36,9 +36,7 @@
|
|
|
36
36
|
{#if $barLicense}
|
|
37
37
|
<a class="wrap" href="/console/billing">
|
|
38
38
|
{#if $barLicense.type === 'subscription'}
|
|
39
|
-
<Tooltip
|
|
40
|
-
position="bottom"
|
|
41
|
-
>
|
|
39
|
+
<Tooltip position="bottom">
|
|
42
40
|
{#snippet tooltip()}
|
|
43
41
|
Your current subscription plan for {name}. Click to manage it.
|
|
44
42
|
{/snippet}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Dropdown from '../../Dropdown/Dropdown.svelte';
|
|
3
|
+
import Tooltip from '../../Tooltip/Tooltip.svelte';
|
|
4
|
+
import {
|
|
5
|
+
barOrganizationDropdownOpen,
|
|
6
|
+
barUser,
|
|
7
|
+
switchOrganization,
|
|
8
|
+
type BarOrganization
|
|
9
|
+
} from '../bar.js';
|
|
10
|
+
import IconChevronExpand from '@hyvor/icons/IconChevronExpand';
|
|
11
|
+
import OrgsList from './OrgsList.svelte';
|
|
12
|
+
import toast from '../../Toast/toast.js';
|
|
13
|
+
|
|
14
|
+
let disableTooltip = $state(true);
|
|
15
|
+
let switching = $state(false);
|
|
16
|
+
|
|
17
|
+
let props: {
|
|
18
|
+
onSwitch: (org: BarOrganization) => void;
|
|
19
|
+
} = $props();
|
|
20
|
+
|
|
21
|
+
async function handleSwitch(org: BarOrganization) {
|
|
22
|
+
barOrganizationDropdownOpen.set(false);
|
|
23
|
+
switching = true;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await switchOrganization(org);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
toast.error('Failed to switch organization.');
|
|
29
|
+
switching = false;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
switching = false;
|
|
34
|
+
props.onSwitch(org);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
barOrganizationDropdownOpen.subscribe((value) => {
|
|
38
|
+
disableTooltip = true;
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
{#if $barUser}
|
|
43
|
+
<Tooltip position="bottom" text="Switch Organization" disabled={disableTooltip}>
|
|
44
|
+
<span class="wrap">
|
|
45
|
+
<Dropdown
|
|
46
|
+
bind:show={$barOrganizationDropdownOpen}
|
|
47
|
+
align="center"
|
|
48
|
+
width={275}
|
|
49
|
+
contentPadding={0}
|
|
50
|
+
>
|
|
51
|
+
{#snippet trigger()}
|
|
52
|
+
<button>
|
|
53
|
+
{#if switching}
|
|
54
|
+
<span class="switching">Switching...</span>
|
|
55
|
+
{:else}
|
|
56
|
+
{$barUser.current_organization_name}
|
|
57
|
+
{/if}
|
|
58
|
+
<IconChevronExpand size={12} />
|
|
59
|
+
</button>
|
|
60
|
+
{/snippet}
|
|
61
|
+
{#snippet content()}
|
|
62
|
+
<OrgsList onSwitch={handleSwitch} />
|
|
63
|
+
{/snippet}
|
|
64
|
+
</Dropdown>
|
|
65
|
+
</span>
|
|
66
|
+
</Tooltip>
|
|
67
|
+
{/if}
|
|
68
|
+
|
|
69
|
+
<style>
|
|
70
|
+
.wrap {
|
|
71
|
+
height: 100%;
|
|
72
|
+
margin-left: 20px;
|
|
73
|
+
margin-right: 20px;
|
|
74
|
+
display: inline-flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
}
|
|
77
|
+
button {
|
|
78
|
+
height: 100%;
|
|
79
|
+
padding: 0 15px;
|
|
80
|
+
font-size: 14px;
|
|
81
|
+
height: 24px;
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
transition: 0.2s background-color;
|
|
84
|
+
border: 1px solid var(--border);
|
|
85
|
+
border-top: none;
|
|
86
|
+
border-bottom: none;
|
|
87
|
+
}
|
|
88
|
+
button:hover {
|
|
89
|
+
background-color: var(--hover);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.wrap :global(.dropdown),
|
|
93
|
+
.wrap :global(.trigger) {
|
|
94
|
+
display: inline-block;
|
|
95
|
+
height: 100%;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.switching {
|
|
99
|
+
opacity: 0.4;
|
|
100
|
+
animation: switching-pulse 1.5s infinite;
|
|
101
|
+
}
|
|
102
|
+
@keyframes switching-pulse {
|
|
103
|
+
0%,
|
|
104
|
+
100% {
|
|
105
|
+
opacity: 0.4;
|
|
106
|
+
}
|
|
107
|
+
50% {
|
|
108
|
+
opacity: 0.8;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type BarOrganization } from '../bar.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
onSwitch: (org: BarOrganization) => void;
|
|
4
|
+
};
|
|
5
|
+
declare const BarOrganization: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type BarOrganization = ReturnType<typeof BarOrganization>;
|
|
7
|
+
export default BarOrganization;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import IconMessage from '../../IconMessage/IconMessage.svelte';
|
|
3
|
+
import Loader from '../../Loader/Loader.svelte';
|
|
4
|
+
import { onMount } from 'svelte';
|
|
5
|
+
import { barOrganizations, getMyOrganizations, type BarOrganization } from '../bar.js';
|
|
6
|
+
import ActionList from '../../ActionList/ActionList.svelte';
|
|
7
|
+
import ActionListItem from '../../ActionList/ActionListItem.svelte';
|
|
8
|
+
|
|
9
|
+
let loading = $state(true);
|
|
10
|
+
let error = $state('');
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
onSwitch
|
|
14
|
+
}: {
|
|
15
|
+
onSwitch: (org: BarOrganization) => void;
|
|
16
|
+
} = $props();
|
|
17
|
+
|
|
18
|
+
onMount(() => {
|
|
19
|
+
if ($barOrganizations.length > 0) {
|
|
20
|
+
loading = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
getMyOrganizations()
|
|
24
|
+
.then((data) => {
|
|
25
|
+
barOrganizations.set(data);
|
|
26
|
+
})
|
|
27
|
+
.catch((err) => {
|
|
28
|
+
error = 'Failed to load organizations.';
|
|
29
|
+
})
|
|
30
|
+
.finally(() => {
|
|
31
|
+
loading = false;
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#if loading}
|
|
37
|
+
<Loader padding={40} block size="small" />
|
|
38
|
+
{:else if error}
|
|
39
|
+
<IconMessage error iconSize={30}>
|
|
40
|
+
{error}
|
|
41
|
+
</IconMessage>
|
|
42
|
+
{:else}
|
|
43
|
+
<div class="list-wrap">
|
|
44
|
+
<ActionList>
|
|
45
|
+
{#each $barOrganizations as org}
|
|
46
|
+
<ActionListItem on:select={() => onSwitch(org)}>
|
|
47
|
+
{org.name}
|
|
48
|
+
{#snippet end()}
|
|
49
|
+
<span class="role">
|
|
50
|
+
{org.role.toUpperCase()}
|
|
51
|
+
</span>
|
|
52
|
+
{/snippet}
|
|
53
|
+
</ActionListItem>
|
|
54
|
+
{/each}
|
|
55
|
+
</ActionList>
|
|
56
|
+
</div>
|
|
57
|
+
{/if}
|
|
58
|
+
|
|
59
|
+
<style>
|
|
60
|
+
.role {
|
|
61
|
+
font-size: 10px;
|
|
62
|
+
color: var(--text-light);
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
}
|
|
65
|
+
.list-wrap {
|
|
66
|
+
max-height: 300px;
|
|
67
|
+
overflow-y: auto;
|
|
68
|
+
padding: 10px;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type BarOrganization } from '../bar.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
onSwitch: (org: BarOrganization) => void;
|
|
4
|
+
};
|
|
5
|
+
declare const OrgsList: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type OrgsList = ReturnType<typeof OrgsList>;
|
|
7
|
+
export default OrgsList;
|
|
@@ -10,6 +10,12 @@ export interface BarUser {
|
|
|
10
10
|
username?: string | null;
|
|
11
11
|
email: string;
|
|
12
12
|
picture_url: string | null;
|
|
13
|
+
current_organization_name: string;
|
|
14
|
+
}
|
|
15
|
+
export interface BarOrganization {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
role: 'admin' | 'billing' | 'manager' | 'member';
|
|
13
19
|
}
|
|
14
20
|
export interface BarUpdate {
|
|
15
21
|
id: number;
|
|
@@ -33,8 +39,15 @@ export declare const barUser: import("svelte/store").Writable<BarUser | null>;
|
|
|
33
39
|
export declare const barUnreadUpdates: import("svelte/store").Writable<number>;
|
|
34
40
|
export declare const barLicense: import("svelte/store").Writable<BarResolvedLicense | null>;
|
|
35
41
|
export declare const barHasFailedInvoices: import("svelte/store").Writable<boolean>;
|
|
42
|
+
export declare const barOrganizationDropdownOpen: import("svelte/store").Writable<boolean>;
|
|
43
|
+
export declare const barOrganizations: import("svelte/store").Writable<BarOrganization[]>;
|
|
36
44
|
export declare function setInstanceAndProduct(instance_: string, product_: string): void;
|
|
37
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @throws Error if initialization fails
|
|
47
|
+
*/
|
|
48
|
+
export declare function initBar(): Promise<void>;
|
|
49
|
+
export declare function getMyOrganizations(): Promise<BarOrganization[]>;
|
|
50
|
+
export declare function switchOrganization(org: BarOrganization): Promise<void>;
|
|
38
51
|
export declare class UnreadUpdatesTimeLocalStorage {
|
|
39
52
|
static KEY: string;
|
|
40
53
|
static get(): number | null;
|
|
@@ -48,4 +61,8 @@ export declare const bar: {
|
|
|
48
61
|
* This is useful to create after, for example, a user creates a new blog
|
|
49
62
|
*/
|
|
50
63
|
reload: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Open the org selector dropdown from the outside world
|
|
66
|
+
*/
|
|
67
|
+
openOrganizationDropdown: () => void;
|
|
51
68
|
};
|
|
@@ -6,39 +6,69 @@ export const barUser = writable(null);
|
|
|
6
6
|
export const barUnreadUpdates = writable(0);
|
|
7
7
|
export const barLicense = writable(null);
|
|
8
8
|
export const barHasFailedInvoices = writable(false);
|
|
9
|
+
export const barOrganizationDropdownOpen = writable(false);
|
|
10
|
+
export const barOrganizations = writable([]);
|
|
9
11
|
export function setInstanceAndProduct(instance_, product_) {
|
|
10
12
|
instance = instance_;
|
|
11
13
|
product = product_;
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @throws Error if initialization fails
|
|
17
|
+
*/
|
|
18
|
+
export async function initBar() {
|
|
14
19
|
const query = new URLSearchParams();
|
|
15
20
|
query.set('product', product);
|
|
16
21
|
const lastUnreadTime = UnreadUpdatesTimeLocalStorage.get();
|
|
17
22
|
if (lastUnreadTime) {
|
|
18
23
|
query.set('last_read_updates_at', lastUnreadTime.toString());
|
|
19
24
|
}
|
|
20
|
-
fetch(instance + '/api/public/bar?' + query.toString(), {
|
|
25
|
+
const response = await fetch(instance + '/api/public/bar?' + query.toString(), {
|
|
21
26
|
credentials: 'include'
|
|
22
|
-
})
|
|
23
|
-
.then((response) => response.json())
|
|
24
|
-
.then((data) => {
|
|
25
|
-
barUser.set(data.user);
|
|
26
|
-
barUnreadUpdates.set(data.updates.unread);
|
|
27
|
-
barLicense.set(data.billing.license);
|
|
28
|
-
barHasFailedInvoices.set(data.billing.has_failed_invoices);
|
|
29
|
-
if (lastUnreadTime === null) {
|
|
30
|
-
UnreadUpdatesTimeLocalStorage.setNow();
|
|
31
|
-
}
|
|
32
|
-
if (data.user && track.ready()) {
|
|
33
|
-
track.identify(data.user.id.toString(), {
|
|
34
|
-
name: data.user.name ?? undefined,
|
|
35
|
-
avatar: data.user.picture_url ?? undefined,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
.catch((error) => {
|
|
40
|
-
console.error('Error:', error);
|
|
41
27
|
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error('Failed to initialize bar');
|
|
30
|
+
}
|
|
31
|
+
const data = await response.json();
|
|
32
|
+
barUser.set(data.user);
|
|
33
|
+
barUnreadUpdates.set(data.updates.unread);
|
|
34
|
+
barLicense.set(data.billing.license);
|
|
35
|
+
barHasFailedInvoices.set(data.billing.has_failed_invoices);
|
|
36
|
+
if (lastUnreadTime === null) {
|
|
37
|
+
UnreadUpdatesTimeLocalStorage.setNow();
|
|
38
|
+
}
|
|
39
|
+
if (data.user && track.ready()) {
|
|
40
|
+
track.identify(data.user.id.toString(), {
|
|
41
|
+
name: data.user.name ?? undefined,
|
|
42
|
+
avatar: data.user.picture_url ?? undefined,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export async function getMyOrganizations() {
|
|
47
|
+
/* return [
|
|
48
|
+
{ id: 1, name: 'Org 1', role: 'admin' },
|
|
49
|
+
{ id: 2, name: 'Org 2', role: 'member' },
|
|
50
|
+
{ id: 3, name: 'Org 3', role: 'billing' },
|
|
51
|
+
{ id: 4, name: 'Org 4', role: 'manager' },
|
|
52
|
+
] */
|
|
53
|
+
const response = await fetch(instance + '/api/public/bar/myorgs', {
|
|
54
|
+
credentials: 'include'
|
|
55
|
+
});
|
|
56
|
+
const data = await response.json();
|
|
57
|
+
return data.organizations;
|
|
58
|
+
}
|
|
59
|
+
export async function switchOrganization(org) {
|
|
60
|
+
const response = await fetch(instance + '/api/public/bar/switch-org', {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
credentials: 'include',
|
|
63
|
+
headers: {
|
|
64
|
+
'Content-Type': 'application/json'
|
|
65
|
+
},
|
|
66
|
+
body: JSON.stringify({ organization_id: org.id })
|
|
67
|
+
});
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error('Failed to switch organization');
|
|
70
|
+
}
|
|
71
|
+
await initBar();
|
|
42
72
|
}
|
|
43
73
|
export class UnreadUpdatesTimeLocalStorage {
|
|
44
74
|
static KEY = 'unread_updates';
|
|
@@ -98,5 +128,9 @@ export const bar = {
|
|
|
98
128
|
*/
|
|
99
129
|
reload: () => {
|
|
100
130
|
initBar();
|
|
101
|
-
}
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Open the org selector dropdown from the outside world
|
|
134
|
+
*/
|
|
135
|
+
openOrganizationDropdown: () => barOrganizationDropdownOpen.set(true)
|
|
102
136
|
};
|
package/package.json
CHANGED