feat: implement subscription setting

This commit is contained in:
Steven
2023-09-24 19:44:09 +08:00
parent 46fa546a7d
commit 24fe368974
18 changed files with 381 additions and 169 deletions

View File

@@ -0,0 +1,11 @@
import { PlanType } from "@/types/proto/api/v2/subscription_service";
export const stringifyPlanType = (planType: PlanType) => {
if (planType === PlanType.FREE) {
return "Free";
} else if (planType === PlanType.PRO) {
return "Pro";
} else {
return "Unknown";
}
};

View File

@@ -0,0 +1,29 @@
import { create } from "zustand";
import { workspaceServiceClient } from "@/grpcweb";
import { WorkspaceProfile, WorkspaceSetting } from "@/types/proto/api/v2/workspace_service";
interface WorkspaceState {
profile: WorkspaceProfile;
setting: WorkspaceSetting;
// Workspace related actions.
fetchWorkspaceProfile: () => Promise<WorkspaceProfile>;
fetchWorkspaceSetting: () => Promise<WorkspaceSetting>;
}
const useWorkspaceStore = create<WorkspaceState>()((set) => ({
profile: WorkspaceProfile.fromPartial({}),
setting: WorkspaceSetting.fromPartial({}),
fetchWorkspaceProfile: async () => {
const workspaceProfile = (await workspaceServiceClient.getWorkspaceProfile({})).profile as WorkspaceProfile;
set({ profile: workspaceProfile });
return workspaceProfile;
},
fetchWorkspaceSetting: async () => {
const workspaceSetting = (await workspaceServiceClient.getWorkspaceSetting({})).setting as WorkspaceSetting;
set({ setting: workspaceSetting });
return workspaceSetting;
},
}));
export default useWorkspaceStore;