Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b40672

Browse files
committed
fix profile dropdown
1 parent a42f83c commit 8b40672

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

‎client/packages/lowcoder/src/pages/common/profileDropdown.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
SearchIcon,
1818
} from "lowcoder-design";
1919
import ProfileSettingModal from "pages/setting/profile";
20-
import React, { useEffect, useMemo, useState } from "react";
20+
import React, { useMemo, useState } from "react";
2121
import { useDispatch, useSelector } from "react-redux";
22-
import { createOrgAction, fetchWorkspacesAction, switchOrg } from "redux/reduxActions/orgActions";
22+
import { createOrgAction, switchOrg } from "redux/reduxActions/orgActions";
2323
import styled from "styled-components";
2424
import history from "util/history";
2525
import ProfileImage from "pages/common/profileImage";
@@ -30,7 +30,6 @@ import { showSwitchOrg } from "@lowcoder-ee/pages/common/customerService";
3030
import { checkIsMobile } from "util/commonUtils";
3131
import { selectSystemConfig } from "redux/selectors/configSelectors";
3232
import type { ItemType } from "antd/es/menu/interface";
33-
import { getCurrentOrg, getWorkspaces } from "@lowcoder-ee/redux/selectors/orgSelectors";
3433

3534
const { Item } = Menu;
3635

@@ -220,29 +219,24 @@ type DropDownProps = {
220219
};
221220

222221
export default function ProfileDropdown(props: DropDownProps) {
223-
const { avatarUrl, username, currentOrgId } = props.user;
222+
const { avatarUrl, username, orgs, currentOrgId } = props.user;
224223
const currentOrgRoleId = props.user.orgRoleMap.get(currentOrgId);
225-
const currentOrg = useSelector(getCurrentOrg);
226-
const workspaces = useSelector(getWorkspaces);
224+
const currentOrg = useMemo(
225+
() => props.user.orgs.find((o) => o.id === currentOrgId),
226+
[props.user, currentOrgId]
227+
);
227228
const settingModalVisible = useSelector(isProfileSettingModalVisible);
228229
const sysConfig = useSelector(selectSystemConfig);
229230
const dispatch = useDispatch();
230231
const [searchTerm, setSearchTerm] = useState("");
231232
const [dropdownVisible, setDropdownVisible] = useState(false);
232233

233-
// Load workspaces when dropdown opens
234-
useEffect(() => {
235-
if (dropdownVisible && workspaces.items.length === 0) {
236-
dispatch(fetchWorkspacesAction(1));
237-
}
238-
}, [dropdownVisible]);
239-
// Use workspaces.items instead of props.user.orgs
240234
const filteredOrgs = useMemo(() => {
241-
if (!searchTerm.trim()) return workspaces.items;
242-
return workspaces.items.filter(org =>
235+
if (!searchTerm.trim()) return orgs;
236+
return orgs.filter(org =>
243237
org.name.toLowerCase().includes(searchTerm.toLowerCase())
244238
);
245-
}, [workspaces.items, searchTerm]);
239+
}, [orgs, searchTerm]);
246240

247241
const handleProfileClick = () => {
248242
if (checkIsMobile(window.innerWidth)) {
@@ -272,7 +266,7 @@ export default function ProfileDropdown(props: DropDownProps) {
272266
};
273267

274268
const handleCreateOrg = () => {
275-
dispatch(createOrgAction(workspaces.items));
269+
dispatch(createOrgAction(orgs));
276270
history.push(ORGANIZATION_SETTING);
277271
setDropdownVisible(false);
278272
};
@@ -299,11 +293,11 @@ export default function ProfileDropdown(props: DropDownProps) {
299293
</ProfileSection>
300294

301295
{/* Workspaces Section */}
302-
{workspaces.items.length > 0 && showSwitchOrg(props.user, sysConfig) && (
296+
{orgs && orgs.length > 0 && showSwitchOrg(props.user, sysConfig) && (
303297
<WorkspaceSection>
304298
<SectionHeader>{trans("profile.switchOrg")}</SectionHeader>
305299

306-
{workspaces.items.length > 3 && (
300+
{orgs.length > 3 && (
307301
<SearchContainer>
308302
<StyledSearchInput
309303
placeholder="Search workspaces..."

0 commit comments

Comments
 (0)