chore: tweak feature matrix

This commit is contained in:
Steven
2024-08-12 21:29:57 +08:00
parent 00e2a6fd96
commit 7c31fd444c
13 changed files with 176 additions and 198 deletions

View File

@ -2,6 +2,14 @@ import { create } from "zustand";
import { workspaceServiceClient } from "@/grpcweb";
import { WorkspaceProfile, WorkspaceSetting } from "@/types/proto/api/v1/workspace_service";
export enum FeatureType {
SSO = "ysh.slash.sso",
AdvancedAnalytics = "ysh.slash.advanced-analytics",
UnlimitedAccounts = "ysh.slash.unlimited-accounts",
UnlimitedCollections = "ysh.slash.unlimited-collections",
CustomeBranding = "ysh.slash.custom-branding",
}
interface WorkspaceState {
profile: WorkspaceProfile;
setting: WorkspaceSetting;
@ -9,6 +17,7 @@ interface WorkspaceState {
// Workspace related actions.
fetchWorkspaceProfile: () => Promise<WorkspaceProfile>;
fetchWorkspaceSetting: () => Promise<WorkspaceSetting>;
checkFeatureAvailable: (feature: FeatureType) => boolean;
}
const useWorkspaceStore = create<WorkspaceState>()((set, get) => ({
@ -17,6 +26,7 @@ const useWorkspaceStore = create<WorkspaceState>()((set, get) => ({
fetchWorkspaceProfile: async () => {
const workspaceProfile = (await workspaceServiceClient.getWorkspaceProfile({})).profile as WorkspaceProfile;
set({ ...get(), profile: workspaceProfile });
console.log("workspaceProfile", workspaceProfile);
return workspaceProfile;
},
fetchWorkspaceSetting: async () => {
@ -24,6 +34,9 @@ const useWorkspaceStore = create<WorkspaceState>()((set, get) => ({
set({ ...get(), setting: workspaceSetting });
return workspaceSetting;
},
checkFeatureAvailable: (feature: FeatureType): boolean => {
return get().profile.features.includes(feature);
},
}));
export default useWorkspaceStore;