From 3838908e702e27abec0da3fa2483f016078ff972 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Wed, 28 Aug 2024 10:34:33 -0700 Subject: [PATCH] proper parentheses --- web/src/components/IsPublicGroupSelector.tsx | 123 ++++++++++--------- web/src/components/user/UserProvider.tsx | 9 +- 2 files changed, 71 insertions(+), 61 deletions(-) diff --git a/web/src/components/IsPublicGroupSelector.tsx b/web/src/components/IsPublicGroupSelector.tsx index b729a4125..6cac27447 100644 --- a/web/src/components/IsPublicGroupSelector.tsx +++ b/web/src/components/IsPublicGroupSelector.tsx @@ -22,7 +22,7 @@ export const IsPublicGroupSelector = ({ enforceGroupSelection?: boolean; }) => { const { data: userGroups, isLoading: userGroupsIsLoading } = useUserGroups(); - const { isAdmin, user, isLoadingUser } = useUser(); + const { isAdmin, user, isLoadingUser, isCurator } = useUser(); const [shouldHideContent, setShouldHideContent] = useState(false); useEffect(() => { @@ -87,43 +87,45 @@ export const IsPublicGroupSelector = ({ )} {(!formikProps.values.is_public || - !isAdmin || + isCurator || formikProps.values.groups.length > 0) && - userGroupsIsLoading ? ( -
- ) : ( - userGroups && - userGroups.length > 0 && ( - <> -
-
- Assign group access for this {objectName} + (userGroupsIsLoading ? ( +
+ ) : ( + userGroups && + userGroups.length > 0 && ( + <> +
+
+ Assign group access for this {objectName} +
-
- - {isAdmin || !enforceGroupSelection ? ( - <> - This {objectName} will be visible/accessible by the groups - selected below - - ) : ( - <> - Curators must select one or more groups to give access to this{" "} - {objectName} - - )} - - ( -
- {userGroups.map((userGroup: UserGroup) => { - const ind = formikProps.values.groups.indexOf(userGroup.id); - let isSelected = ind !== -1; - return ( -
+ {isAdmin || !enforceGroupSelection ? ( + <> + This {objectName} will be visible/accessible by the groups + selected below + + ) : ( + <> + Curators must select one or more groups to give access to + this {objectName} + + )} + + ( +
+ {userGroups.map((userGroup: UserGroup) => { + const ind = formikProps.values.groups.indexOf( + userGroup.id + ); + let isSelected = ind !== -1; + return ( +
({ cursor-pointer ${isSelected ? "bg-background-strong" : "hover:bg-hover"} `} - onClick={() => { - if (isSelected) { - arrayHelpers.remove(ind); - } else { - arrayHelpers.push(userGroup.id); - } - }} - > -
- {userGroup.name} + onClick={() => { + if (isSelected) { + arrayHelpers.remove(ind); + } else { + arrayHelpers.push(userGroup.id); + } + }} + > +
+ {" "} + {userGroup.name} +
-
- ); - })} -
- )} - /> - - - ) - )} + ); + })} +
+ )} + /> + + + ) + ))}
); }; diff --git a/web/src/components/user/UserProvider.tsx b/web/src/components/user/UserProvider.tsx index d2cf0f2c9..67777277c 100644 --- a/web/src/components/user/UserProvider.tsx +++ b/web/src/components/user/UserProvider.tsx @@ -8,6 +8,7 @@ interface UserContextType { user: User | null; isLoadingUser: boolean; isAdmin: boolean; + isCurator: boolean; refreshUser: () => Promise; } @@ -17,12 +18,16 @@ export function UserProvider({ children }: { children: React.ReactNode }) { const [user, setUser] = useState(null); const [isLoadingUser, setIsLoadingUser] = useState(true); const [isAdmin, setIsAdmin] = useState(false); + const [isCurator, setIsCurator] = useState(false); const fetchUser = async () => { try { const user = await getCurrentUser(); setUser(user); setIsAdmin(user?.role === UserRole.ADMIN); + setIsCurator( + user?.role === UserRole.CURATOR || user?.role == UserRole.GLOBAL_CURATOR + ); } catch (error) { console.error("Error fetching current user:", error); } finally { @@ -40,7 +45,9 @@ export function UserProvider({ children }: { children: React.ReactNode }) { }; return ( - + {children} );