mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-04 12:26:19 +00:00
feat: implement subscription setting
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import { TypedUseSelectorHook, useSelector } from "react-redux";
|
||||
import shortcutReducer from "./modules/shortcut";
|
||||
import workspaceReducer from "./modules/workspace";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
workspace: workspaceReducer,
|
||||
shortcut: shortcutReducer,
|
||||
},
|
||||
});
|
||||
|
@ -1,20 +0,0 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { WorkspaceProfile } from "@/types/proto/api/v2/workspace_service";
|
||||
|
||||
type State = {
|
||||
workspaceProfile: WorkspaceProfile;
|
||||
};
|
||||
|
||||
const workspaceSlice = createSlice({
|
||||
name: "workspace",
|
||||
initialState: {} as State,
|
||||
reducers: {
|
||||
setWorkspaceState: (_, action: PayloadAction<State>) => {
|
||||
return action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setWorkspaceState } = workspaceSlice.actions;
|
||||
|
||||
export default workspaceSlice.reducer;
|
11
frontend/web/src/stores/v1/subscription.ts
Normal file
11
frontend/web/src/stores/v1/subscription.ts
Normal 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";
|
||||
}
|
||||
};
|
29
frontend/web/src/stores/v1/workspace.ts
Normal file
29
frontend/web/src/stores/v1/workspace.ts
Normal 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;
|
Reference in New Issue
Block a user