diff --git a/packages/app/src/pages/workspace/[workspaceId]/setting.tsx b/packages/app/src/pages/workspace/[workspaceId]/setting.tsx
index 8a2eb21296..48255cab35 100644
--- a/packages/app/src/pages/workspace/[workspaceId]/setting.tsx
+++ b/packages/app/src/pages/workspace/[workspaceId]/setting.tsx
@@ -13,7 +13,7 @@ import {
PublishIcon,
CloudInsyncIcon,
} from '@blocksuite/icons';
-import { ReactElement, useEffect, useState } from 'react';
+import { ReactElement, ReactNode, useState } from 'react';
import {
GeneralPage,
MembersPage,
@@ -23,132 +23,82 @@ import {
} from '@/components/workspace-setting';
import { useAppState } from '@/providers/app-state-provider';
import WorkspaceLayout from '@/components/workspace-layout';
+import { WorkspaceInfo } from '@affine/datacenter';
-enum ActiveTab {
- 'general' = 'general',
- 'members' = 'members',
- 'publish' = 'publish',
- 'sync' = 'sync',
- 'export' = 'export',
-}
+type TabNames = 'general' | 'members' | 'publish' | 'sync' | 'export';
-type SettingTabProps = {
- activeTab: ActiveTab;
- onTabChange?: (tab: ActiveTab) => void;
-};
+const tabMap: {
+ name: TabNames;
+ icon: ReactNode;
+ panelRender: (workspace: WorkspaceInfo) => ReactNode;
+}[] = [
+ {
+ name: 'general',
+ icon: ,
+ panelRender: workspace => ,
+ },
+ {
+ name: 'members',
+ icon: ,
+ panelRender: workspace => ,
+ },
+ {
+ name: 'publish',
+ icon: ,
+ panelRender: workspace => ,
+ },
+ {
+ name: 'sync',
+ icon: ,
+ panelRender: workspace => ,
+ },
+ {
+ name: 'export',
+ icon: ,
+ panelRender: workspace => ,
+ },
+];
-type WorkspaceSettingProps = {
- isShow: boolean;
- onClose?: () => void;
-};
+const WorkspaceSetting = () => {
+ const { currentMetaWorkSpace } = useAppState();
-const WorkspaceSettingTab = ({ activeTab, onTabChange }: SettingTabProps) => {
- return (
-
- {
- onTabChange && onTabChange(ActiveTab.general);
- }}
- >
-
-
-
- General
-
-
- {
- onTabChange && onTabChange(ActiveTab.sync);
- }}
- >
-
-
-
- Sync
-
-
- {
- onTabChange && onTabChange(ActiveTab.members);
- }}
- >
-
-
-
- Collaboration
-
- {
- onTabChange && onTabChange(ActiveTab.publish);
- }}
- >
-
-
-
- Publish
-
-
- {
- onTabChange && onTabChange(ActiveTab.export);
- }}
- >
-
-
-
- Export
-
-
- );
-};
-
-const WorkspaceSetting = ({ isShow, onClose }: WorkspaceSettingProps) => {
- // const { workspaces } = useAppState();
- const [activeTab, setActiveTab] = useState(ActiveTab.general);
- const handleTabChange = (tab: ActiveTab) => {
+ const [activeTab, setActiveTab] = useState(tabMap[0].name);
+ const handleTabChange = (tab: TabNames) => {
setActiveTab(tab);
};
- const { currentMetaWorkSpace } = useAppState();
- useEffect(() => {
- // reset tab when modal is closed
- if (!isShow) {
- setActiveTab(ActiveTab.general);
- }
- }, [isShow]);
+ const activeTabPanelRender = tabMap.find(
+ tab => tab.name === activeTab
+ )?.panelRender;
+
return (
Workspace Settings
-
+
+ {tabMap.map(({ icon, name }) => {
+ return (
+ {
+ handleTabChange(name);
+ }}
+ >
+
+ {icon}
+
+ {name}
+
+ );
+ })}
+
- {activeTab === ActiveTab.general && currentMetaWorkSpace && (
-
- )}
- {activeTab === ActiveTab.sync && currentMetaWorkSpace && (
-
- )}
- {activeTab === ActiveTab.members && currentMetaWorkSpace && (
-
- )}
- {activeTab === ActiveTab.publish && currentMetaWorkSpace && (
-
- )}
- {activeTab === ActiveTab.export && currentMetaWorkSpace && (
-
- )}
+ {currentMetaWorkSpace && activeTabPanelRender?.(currentMetaWorkSpace)}
);