From 3ec6cc14882928c93831598039c153a1c7d0308a Mon Sep 17 00:00:00 2001 From: Leandro Menezes Date: Wed, 9 Oct 2024 14:38:27 -0300 Subject: [PATCH] fixes and code enhancement --- .../src/components/LoggedInUser.tsx | 6 ++++- .../admin/UserDirectory/UserDirectoryRow.tsx | 6 ++--- .../src/components/manager/BudgetList.tsx | 12 +++------ .../src/components/modals/EditUser.tsx | 8 +++--- .../components/modals/TransferOwnership.tsx | 25 ++++++++++++++++--- .../loot-core/src/server/cloud-storage.ts | 1 + packages/loot-core/src/types/models/user.ts | 2 +- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/packages/desktop-client/src/components/LoggedInUser.tsx b/packages/desktop-client/src/components/LoggedInUser.tsx index fe139d6469d..a22d92b113f 100644 --- a/packages/desktop-client/src/components/LoggedInUser.tsx +++ b/packages/desktop-client/src/components/LoggedInUser.tsx @@ -61,8 +61,12 @@ export function LoggedInUser({ useEffect(() => { if (cloudFileId && currentFile) { setIsOwner( - currentFile.usersWithAccess.some(u => u.userId === userData?.userId), + currentFile.usersWithAccess.some( + u => u.userId === userData?.userId && u.owner, + ), ); + } else { + setIsOwner(false); } }, [cloudFileId]); diff --git a/packages/desktop-client/src/components/admin/UserDirectory/UserDirectoryRow.tsx b/packages/desktop-client/src/components/admin/UserDirectory/UserDirectoryRow.tsx index f01bf2bf961..f9b6f40ee54 100644 --- a/packages/desktop-client/src/components/admin/UserDirectory/UserDirectoryRow.tsx +++ b/packages/desktop-client/src/components/admin/UserDirectory/UserDirectoryRow.tsx @@ -41,7 +41,7 @@ export const UserDirectoryRow = memo( onMouseEnter={() => onHover && onHover(user.id)} onMouseLeave={() => onHover && onHover(null)} > - {!user.master && ( + {!user.owner && ( )} - {user.master && ( + {user.owner && ( - + f.userId === file.owner); + const userFound = file.usersWithAccess?.find(f => f.owner); return userFound?.displayName ?? userFound?.userName ?? 'unknown'; } } @@ -304,7 +304,6 @@ function FileItem({ {multiuserEnabled && ( )} @@ -599,14 +598,9 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) { type UserAccessForFileProps = { fileId: string; currentUserId: string; - ownerId?: string; }; -function UserAccessForFile({ - fileId, - currentUserId, - ownerId, -}: UserAccessForFileProps) { +function UserAccessForFile({ fileId, currentUserId }: UserAccessForFileProps) { const allFiles = useSelector(state => state.budgets.allFiles || []); const remoteFiles = allFiles.filter( f => f.state === 'remote' || f.state === 'synced' || f.state === 'detached', @@ -615,7 +609,7 @@ function UserAccessForFile({ const multiuserEnabled = useMultiuserEnabled(); let usersAccess = currentFile?.usersWithAccess ?? []; - usersAccess = usersAccess?.filter(user => user.userId !== ownerId) ?? []; + usersAccess = usersAccess?.filter(user => user.userName !== '') ?? []; const sortedUsersAccess = [...usersAccess].sort((a, b) => { const textA = diff --git a/packages/desktop-client/src/components/modals/EditUser.tsx b/packages/desktop-client/src/components/modals/EditUser.tsx index e5ee758f72a..38768dcb639 100644 --- a/packages/desktop-client/src/components/modals/EditUser.tsx +++ b/packages/desktop-client/src/components/modals/EditUser.tsx @@ -169,9 +169,9 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) { setEnabled(!enabled)} /> @@ -180,7 +180,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) { - {defaultUser.master && ( + {defaultUser.owner && (