feat:add isOwner

This commit is contained in:
DiamondThree 2023-01-12 17:06:54 +08:00
parent ede7a6bdaa
commit 4fe2febda3
5 changed files with 39 additions and 61 deletions

View File

@ -21,9 +21,8 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
const [showLeave, setShowLeave] = useState<boolean>(false); const [showLeave, setShowLeave] = useState<boolean>(false);
const [uploading, setUploading] = useState<boolean>(false); const [uploading, setUploading] = useState<boolean>(false);
const [workspaceName, setWorkspaceName] = useState<string>(workspace.name); const [workspaceName, setWorkspaceName] = useState<string>(workspace.name);
const { currentWorkspace } = useAppState(); const { currentWorkspace, isOwner } = useAppState();
const { updateWorkspace } = useWorkspaceHelper(); const { updateWorkspace } = useWorkspaceHelper();
const isOwner = true;
const handleChangeWorkSpaceName = (newName: string) => { const handleChangeWorkSpaceName = (newName: string) => {
setWorkspaceName(newName); setWorkspaceName(newName);
}; };
@ -72,8 +71,10 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
placeholder="Workspace Name" placeholder="Workspace Name"
maxLength={14} maxLength={14}
minLength={1} minLength={1}
disabled={!isOwner}
onChange={handleChangeWorkSpaceName} onChange={handleChangeWorkSpaceName}
></Input> ></Input>
{isOwner ? (
<TextButton <TextButton
onClick={() => { onClick={() => {
handleUpdateWorkspaceName(); handleUpdateWorkspaceName();
@ -82,6 +83,7 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
> >
</TextButton> </TextButton>
) : null}
</StyledSettingInputContainer> </StyledSettingInputContainer>
<StyledSettingH2 marginTop={20}>Workspace Type</StyledSettingH2> <StyledSettingH2 marginTop={20}>Workspace Type</StyledSettingH2>
<StyledSettingInputContainer> <StyledSettingInputContainer>

View File

@ -1,47 +0,0 @@
import { WorkspaceModal } from '@/components/workspace-modal';
import { getWorkspaces } from '@/hooks/mock-data/mock';
import { useEffect, useState } from 'react';
import { styled } from '@/styles';
import Button from '@/ui/button/Button';
const Page = () => {
const [open, setOpen] = useState<boolean>(false);
useEffect(() => {
const data = getWorkspaces();
if (!data.length) {
setOpen(true);
}
}, []);
return (
<Workspace>
<h1>workspace</h1>
<div>
<Button
onClick={() => {
setOpen(true);
}}
>
View Workspace List
</Button>
</div>
<WorkspaceModal
open={open}
onClose={() => {
setOpen(false);
}}
></WorkspaceModal>
</Workspace>
);
};
export default Page;
const Workspace = styled.div(({ theme }) => {
return {
height: '100vh',
background: theme.colors.pageBackground,
color: '#FFFFFF',
fontSize: '18px',
fontWeight: 500,
};
});

View File

@ -60,7 +60,7 @@ const tabMap: {
]; ];
const WorkspaceSetting = () => { const WorkspaceSetting = () => {
const { currentWorkspace } = useAppState(); const { currentWorkspace, isOwner } = useAppState();
const [activeTab, setActiveTab] = useState<TabNames>(tabMap[0].name); const [activeTab, setActiveTab] = useState<TabNames>(tabMap[0].name);
const handleTabChange = (tab: TabNames) => { const handleTabChange = (tab: TabNames) => {
@ -70,7 +70,20 @@ const WorkspaceSetting = () => {
const activeTabPanelRender = tabMap.find( const activeTabPanelRender = tabMap.find(
tab => tab.name === activeTab tab => tab.name === activeTab
)?.panelRender; )?.panelRender;
let tableArr: {
name: TabNames;
icon: ReactNode;
panelRender: (workspace: WorkspaceUnit) => ReactNode;
}[] = tabMap;
if (!isOwner) {
tableArr = [
{
name: 'general',
icon: <EditIcon />,
panelRender: workspace => <GeneralPage workspace={workspace} />,
},
];
}
return ( return (
<StyledSettingContainer> <StyledSettingContainer>
<StyledSettingSidebar> <StyledSettingSidebar>
@ -78,7 +91,7 @@ const WorkspaceSetting = () => {
Workspace Settings Workspace Settings
</StyledSettingSidebarHeader> </StyledSettingSidebarHeader>
<StyledSettingTabContainer> <StyledSettingTabContainer>
{tabMap.map(({ icon, name }) => { {tableArr.map(({ icon, name }) => {
return ( return (
<WorkspaceSettingTagItem <WorkspaceSettingTagItem
key={name} key={name}

View File

@ -37,6 +37,7 @@ export const AppStateProvider = ({
currentPage: null, currentPage: null,
editor: null, editor: null,
synced: true, synced: true,
isOwner: false,
}); });
}; };
@ -91,7 +92,7 @@ export const AppStateProvider = ({
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>(); const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
loadWorkspace.current = async (workspaceId: string) => { loadWorkspace.current = async (workspaceId: string) => {
const { dataCenter, workspaceList, currentWorkspace } = appState; const { dataCenter, workspaceList, currentWorkspace, user } = appState;
if (!workspaceList.find(v => v.id.toString() === workspaceId)) { if (!workspaceList.find(v => v.id.toString() === workspaceId)) {
return null; return null;
} }
@ -99,6 +100,13 @@ export const AppStateProvider = ({
return currentWorkspace; return currentWorkspace;
} }
const workspace = (await dataCenter.loadWorkspace(workspaceId)) ?? null; const workspace = (await dataCenter.loadWorkspace(workspaceId)) ?? null;
let isOwner;
if (workspace.provider === 'local') {
// isOwner is useful only in the cloud
isOwner = true;
} else {
isOwner = workspace?.owner && user?.id === workspace?.owner?.id;
}
const pageList = const pageList =
(workspace?.blocksuiteWorkspace?.meta.pageMetas as PageMeta[]) ?? []; (workspace?.blocksuiteWorkspace?.meta.pageMetas as PageMeta[]) ?? [];
setAppState({ setAppState({
@ -107,6 +115,7 @@ export const AppStateProvider = ({
pageList: pageList, pageList: pageList,
currentPage: null, currentPage: null,
editor: null, editor: null,
isOwner,
}); });
return workspace; return workspace;

View File

@ -23,6 +23,7 @@ export type AppStateValue = {
currentPage: StorePage | null; currentPage: StorePage | null;
editor?: EditorContainer | null; editor?: EditorContainer | null;
synced: boolean; synced: boolean;
isOwner?: boolean;
}; };
export type AppStateFunction = { export type AppStateFunction = {