@elevasis/ui 2.65.0 → 2.66.0
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/app/index.d.ts +6 -0
- package/dist/app/index.js +5 -5
- package/dist/auth/index.d.ts +12 -5
- package/dist/auth/index.js +5 -5
- package/dist/charts/index.js +5 -5
- package/dist/{chunk-ZTWA5H77.js → chunk-6ZAP3FOA.js} +0 -1
- package/dist/{chunk-3WVZRN37.js → chunk-ANNM5R7S.js} +235 -365
- package/dist/chunk-L7BZZ4SI.js +56 -0
- package/dist/chunk-P45GQ3ZW.js +104 -0
- package/dist/{chunk-EIXSQONC.js → chunk-RT4KRGZT.js} +37 -59
- package/dist/components/index.d.ts +240 -209
- package/dist/components/index.js +5 -5
- package/dist/components/navigation/index.js +5 -5
- package/dist/execution/index.d.ts +115 -104
- package/dist/features/auth/index.d.ts +39 -8
- package/dist/features/auth/index.js +14 -9
- package/dist/features/clients/index.js +5 -5
- package/dist/features/crm/index.js +5 -5
- package/dist/features/dashboard/index.js +5 -5
- package/dist/features/delivery/index.js +5 -5
- package/dist/features/knowledge/index.js +5 -5
- package/dist/features/lead-gen/index.js +5 -5
- package/dist/features/monitoring/index.js +5 -5
- package/dist/features/monitoring/requests/index.js +6 -6
- package/dist/features/notes/index.js +2 -2
- package/dist/features/operations/index.d.ts +141 -105
- package/dist/features/operations/index.js +5 -5
- package/dist/features/settings/index.d.ts +1 -0
- package/dist/features/settings/index.js +5 -5
- package/dist/hooks/access/index.js +5 -5
- package/dist/hooks/delivery/index.js +5 -5
- package/dist/hooks/index.d.ts +284 -162
- package/dist/hooks/index.js +5 -5
- package/dist/hooks/operations/command-view/utils/transformCommandViewData.d.ts +0 -2
- package/dist/hooks/operations/command-view/utils/transformCommandViewData.js +1 -1
- package/dist/hooks/published.d.ts +284 -162
- package/dist/hooks/published.js +5 -5
- package/dist/index.d.ts +374 -236
- package/dist/index.js +5 -5
- package/dist/initialization/index.d.ts +61 -28
- package/dist/initialization/index.js +3 -3
- package/dist/knowledge/index.js +9 -9
- package/dist/{knowledge-search-index-JOPRYZN6.js → knowledge-search-index-6EZNBNSR.js} +4 -4
- package/dist/layout/index.js +5 -5
- package/dist/organization/index.d.ts +49 -4
- package/dist/organization/index.js +5 -5
- package/dist/profile/index.d.ts +23 -2
- package/dist/profile/index.js +1 -1
- package/dist/provider/index.js +5 -5
- package/dist/provider/published.js +5 -5
- package/dist/types/index.d.ts +330 -271
- package/package.json +3 -3
- package/dist/chunk-LO7GWG24.js +0 -75
- package/dist/chunk-T4LA4RY2.js +0 -56
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { computeInitializationState } from './chunk-P45GQ3ZW.js';
|
|
2
|
+
import { useUserProfile } from './chunk-RT4KRGZT.js';
|
|
3
|
+
import { useAuthContext } from './chunk-BRJ3QZ4E.js';
|
|
4
|
+
import { useMemo, useCallback } from 'react';
|
|
5
|
+
|
|
6
|
+
function createUseAppInitialization(useOrgInitialization) {
|
|
7
|
+
return function useAppInitialization() {
|
|
8
|
+
const { user, isLoading: authLoading } = useAuthContext();
|
|
9
|
+
const { profile, loading: profileLoading, error: profileError, refetch } = useUserProfile();
|
|
10
|
+
const {
|
|
11
|
+
isInitializing: orgInitializing,
|
|
12
|
+
isLoading: orgLoading,
|
|
13
|
+
error: orgErrorMsg,
|
|
14
|
+
currentOrganization,
|
|
15
|
+
memberships,
|
|
16
|
+
retry: orgRetry
|
|
17
|
+
} = useOrgInitialization();
|
|
18
|
+
const state = useMemo(
|
|
19
|
+
() => computeInitializationState({
|
|
20
|
+
user,
|
|
21
|
+
authLoading,
|
|
22
|
+
profile,
|
|
23
|
+
profileLoading,
|
|
24
|
+
profileError,
|
|
25
|
+
orgInitializing,
|
|
26
|
+
orgLoading,
|
|
27
|
+
hasCurrentOrganization: !!currentOrganization,
|
|
28
|
+
orgErrorMessage: orgErrorMsg,
|
|
29
|
+
membershipsCount: memberships.length
|
|
30
|
+
}),
|
|
31
|
+
[
|
|
32
|
+
user,
|
|
33
|
+
authLoading,
|
|
34
|
+
profile,
|
|
35
|
+
profileLoading,
|
|
36
|
+
profileError,
|
|
37
|
+
orgInitializing,
|
|
38
|
+
orgLoading,
|
|
39
|
+
currentOrganization,
|
|
40
|
+
orgErrorMsg,
|
|
41
|
+
memberships.length
|
|
42
|
+
]
|
|
43
|
+
);
|
|
44
|
+
const retry = useCallback(() => {
|
|
45
|
+
if (profileError && refetch) {
|
|
46
|
+
refetch();
|
|
47
|
+
}
|
|
48
|
+
if (orgErrorMsg && orgRetry) {
|
|
49
|
+
orgRetry();
|
|
50
|
+
}
|
|
51
|
+
}, [profileError, refetch, orgErrorMsg, orgRetry]);
|
|
52
|
+
return { ...state, retry };
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { createUseAppInitialization };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useOrganization } from './chunk-DD3CCMCZ.js';
|
|
2
|
+
import { useProfile } from './chunk-RT4KRGZT.js';
|
|
3
|
+
import { useAuthContext } from './chunk-BRJ3QZ4E.js';
|
|
4
|
+
import { createContext, useContext, useMemo, useCallback, createElement } from 'react';
|
|
5
|
+
|
|
6
|
+
// src/initialization/computeInitializationState.ts
|
|
7
|
+
function computeInitializationState(input) {
|
|
8
|
+
const {
|
|
9
|
+
user,
|
|
10
|
+
authLoading,
|
|
11
|
+
profile,
|
|
12
|
+
profileLoading,
|
|
13
|
+
profileError,
|
|
14
|
+
orgInitializing,
|
|
15
|
+
orgLoading,
|
|
16
|
+
hasCurrentOrganization,
|
|
17
|
+
orgErrorMessage,
|
|
18
|
+
membershipsCount
|
|
19
|
+
} = input;
|
|
20
|
+
const isInitializing = authLoading || profileLoading || orgInitializing || orgLoading;
|
|
21
|
+
const userReady = !authLoading && !profileLoading && !!user && !!profile && !profileError;
|
|
22
|
+
const organizationReady = userReady && !orgInitializing && !orgLoading && hasCurrentOrganization && !orgErrorMessage;
|
|
23
|
+
const allReady = organizationReady;
|
|
24
|
+
let error = null;
|
|
25
|
+
if (profileError) {
|
|
26
|
+
error = {
|
|
27
|
+
layer: "profile",
|
|
28
|
+
message: "Failed to load user profile",
|
|
29
|
+
originalError: profileError
|
|
30
|
+
};
|
|
31
|
+
} else if (orgErrorMessage) {
|
|
32
|
+
error = {
|
|
33
|
+
layer: "organization",
|
|
34
|
+
message: orgErrorMessage,
|
|
35
|
+
originalError: new Error(orgErrorMessage)
|
|
36
|
+
};
|
|
37
|
+
} else if (userReady && !orgInitializing && !orgLoading && !hasCurrentOrganization && membershipsCount > 0) {
|
|
38
|
+
error = {
|
|
39
|
+
layer: "organization",
|
|
40
|
+
message: "No organization membership found. Please contact your administrator for an invitation."
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return { userReady, organizationReady, allReady, isInitializing, error, profile };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/initialization/InitializationProvider.tsx
|
|
47
|
+
var InitializationContext = createContext(null);
|
|
48
|
+
function useInitialization() {
|
|
49
|
+
const ctx = useContext(InitializationContext);
|
|
50
|
+
if (!ctx) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"useInitialization must be used within an InitializationProvider. Wrap your app (or the relevant subtree) with <InitializationProvider>."
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return ctx;
|
|
56
|
+
}
|
|
57
|
+
function InitializationProvider({ children }) {
|
|
58
|
+
const { user, isLoading: authLoading } = useAuthContext();
|
|
59
|
+
const { profile, loading: profileLoading, error: profileError, refetch } = useProfile();
|
|
60
|
+
const {
|
|
61
|
+
isInitializing: orgInitializing,
|
|
62
|
+
isOrgRefreshing: orgLoading,
|
|
63
|
+
error: orgErrorMsg,
|
|
64
|
+
currentWorkOSOrganizationId,
|
|
65
|
+
memberships,
|
|
66
|
+
retry: orgRetry
|
|
67
|
+
} = useOrganization();
|
|
68
|
+
const state = useMemo(
|
|
69
|
+
() => computeInitializationState({
|
|
70
|
+
user,
|
|
71
|
+
authLoading,
|
|
72
|
+
profile,
|
|
73
|
+
profileLoading,
|
|
74
|
+
profileError,
|
|
75
|
+
orgInitializing,
|
|
76
|
+
orgLoading,
|
|
77
|
+
hasCurrentOrganization: !!currentWorkOSOrganizationId,
|
|
78
|
+
orgErrorMessage: orgErrorMsg,
|
|
79
|
+
membershipsCount: memberships.length
|
|
80
|
+
}),
|
|
81
|
+
[
|
|
82
|
+
user,
|
|
83
|
+
authLoading,
|
|
84
|
+
profile,
|
|
85
|
+
profileLoading,
|
|
86
|
+
profileError,
|
|
87
|
+
orgInitializing,
|
|
88
|
+
orgLoading,
|
|
89
|
+
currentWorkOSOrganizationId,
|
|
90
|
+
orgErrorMsg,
|
|
91
|
+
memberships.length
|
|
92
|
+
]
|
|
93
|
+
);
|
|
94
|
+
const retry = useCallback(async () => {
|
|
95
|
+
if (profileError && refetch) {
|
|
96
|
+
await refetch();
|
|
97
|
+
}
|
|
98
|
+
await orgRetry();
|
|
99
|
+
}, [profileError, refetch, orgRetry]);
|
|
100
|
+
const value = useMemo(() => ({ ...state, retry }), [state, retry]);
|
|
101
|
+
return createElement(InitializationContext.Provider, { value }, children);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { InitializationContext, InitializationProvider, computeInitializationState, useInitialization };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ElevasisServiceContext } from './chunk-BI5VDO2K.js';
|
|
2
2
|
import { useAuthContext } from './chunk-BRJ3QZ4E.js';
|
|
3
|
-
import { createContext, useContext,
|
|
3
|
+
import { createContext, useContext, createElement } from 'react';
|
|
4
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
5
|
|
|
5
6
|
// src/profile/services/UserProfileService.ts
|
|
6
7
|
var UserProfileService = class {
|
|
@@ -65,6 +66,7 @@ var UserProfileService = class {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
};
|
|
69
|
+
var USER_PROFILE_QUERY_KEY = ["profile", "me"];
|
|
68
70
|
var useUserProfile = (options) => {
|
|
69
71
|
const { user, isLoading: authLoading } = useAuthContext();
|
|
70
72
|
const serviceCtx = useContext(ElevasisServiceContext);
|
|
@@ -74,66 +76,42 @@ var useUserProfile = (options) => {
|
|
|
74
76
|
"useUserProfile: no apiRequest available. Either pass it via options or use within ElevasisServiceProvider."
|
|
75
77
|
);
|
|
76
78
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.warn("Failed to sync user profile");
|
|
93
|
-
}
|
|
94
|
-
} catch (err) {
|
|
95
|
-
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
96
|
-
if (options?.onError) {
|
|
97
|
-
options.onError(
|
|
98
|
-
{
|
|
99
|
-
phase: "profile-sync",
|
|
100
|
-
userId: user?.id
|
|
101
|
-
},
|
|
102
|
-
error2
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
setError(error2);
|
|
106
|
-
console.error("User profile sync failed:", error2);
|
|
107
|
-
} finally {
|
|
108
|
-
setLoading(false);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
if (!authLoading) {
|
|
113
|
-
if (user) {
|
|
114
|
-
syncAndFetchProfile();
|
|
115
|
-
} else {
|
|
116
|
-
setProfile(null);
|
|
117
|
-
setLoading(false);
|
|
118
|
-
setError(null);
|
|
79
|
+
const query = useQuery({
|
|
80
|
+
queryKey: USER_PROFILE_QUERY_KEY,
|
|
81
|
+
queryFn: async () => {
|
|
82
|
+
try {
|
|
83
|
+
const profileService = new UserProfileService(apiRequest);
|
|
84
|
+
const syncedProfile = await profileService.syncUserProfile();
|
|
85
|
+
if (!syncedProfile) {
|
|
86
|
+
throw new Error("Failed to sync user profile");
|
|
87
|
+
}
|
|
88
|
+
return syncedProfile;
|
|
89
|
+
} catch (err) {
|
|
90
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
91
|
+
options?.onError?.({ phase: "profile-sync", userId: user?.id }, error2);
|
|
92
|
+
console.error("User profile sync failed:", error2);
|
|
93
|
+
throw error2;
|
|
119
94
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
95
|
+
},
|
|
96
|
+
// Enabled only once auth has resolved to a real user. When the user signs
|
|
97
|
+
// out, `enabled` flips false and `profile` below resolves to null.
|
|
98
|
+
enabled: !!user && !authLoading,
|
|
99
|
+
// The profile only changes in response to explicit mutations this hook's
|
|
100
|
+
// consumers already know about (onboarding completion, account edits),
|
|
101
|
+
// each of which calls refetch()/invalidateQueries itself. Without this,
|
|
102
|
+
// every new mount of a second/third consumer would kick off a background
|
|
103
|
+
// refetch under a host app's default staleTime, reintroducing the
|
|
104
|
+
// multiple-sync-calls problem this hook exists to fix.
|
|
105
|
+
staleTime: Infinity,
|
|
106
|
+
retry: false
|
|
107
|
+
});
|
|
108
|
+
const profile = query.data ?? null;
|
|
109
|
+
const loading = authLoading || !!user && !profile && !query.isError;
|
|
110
|
+
const error = query.error ?? null;
|
|
122
111
|
const refetch = async () => {
|
|
123
|
-
await
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
profile,
|
|
127
|
-
// Treat as loading whenever a user is present but profile hasn't synced yet.
|
|
128
|
-
// Prevents a render window after re-login where `loading` is still false
|
|
129
|
-
// (from a prior logout) while `user` has just become defined and the sync
|
|
130
|
-
// effect has not yet fired. Without this, ProtectedRoute briefly sees
|
|
131
|
-
// !isInitializing && !userReady, marks the user unauthenticated, and
|
|
132
|
-
// bounces back to /auth-redirect in a loop.
|
|
133
|
-
loading: loading || authLoading || !!user && !profile && !error,
|
|
134
|
-
error,
|
|
135
|
-
refetch
|
|
112
|
+
await query.refetch();
|
|
136
113
|
};
|
|
114
|
+
return { profile, loading, error, refetch };
|
|
137
115
|
};
|
|
138
116
|
var ProfileContext = createContext(null);
|
|
139
117
|
function useProfile() {
|
|
@@ -150,4 +128,4 @@ function ProfileProvider({ apiRequest, children }) {
|
|
|
150
128
|
return createElement(ProfileContext.Provider, { value }, children);
|
|
151
129
|
}
|
|
152
130
|
|
|
153
|
-
export { ProfileProvider, UserProfileService, useProfile, useUserProfile };
|
|
131
|
+
export { ProfileProvider, USER_PROFILE_QUERY_KEY, UserProfileService, useProfile, useUserProfile };
|