proper parentheses

This commit is contained in:
pablodanswer 2024-08-28 10:34:33 -07:00
parent 3112a9df9d
commit 3838908e70
2 changed files with 71 additions and 61 deletions

View File

@ -22,7 +22,7 @@ export const IsPublicGroupSelector = <T extends IsPublicGroupSelectorFormType>({
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 = <T extends IsPublicGroupSelectorFormType>({
)}
{(!formikProps.values.is_public ||
!isAdmin ||
isCurator ||
formikProps.values.groups.length > 0) &&
userGroupsIsLoading ? (
<div className="animate-pulse bg-gray-200 h-8 w-32 rounded"></div>
) : (
userGroups &&
userGroups.length > 0 && (
<>
<div className="flex mt-4 gap-x-2 items-center">
<div className="block font-medium text-base">
Assign group access for this {objectName}
(userGroupsIsLoading ? (
<div className="animate-pulse bg-gray-200 h-8 w-32 rounded"></div>
) : (
userGroups &&
userGroups.length > 0 && (
<>
<div className="flex mt-4 gap-x-2 items-center">
<div className="block font-medium text-base">
Assign group access for this {objectName}
</div>
</div>
</div>
<Text className="mb-3">
{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}
</>
)}
</Text>
<FieldArray
name="groups"
render={(arrayHelpers: ArrayHelpers) => (
<div className="flex gap-2 flex-wrap mb-4">
{userGroups.map((userGroup: UserGroup) => {
const ind = formikProps.values.groups.indexOf(userGroup.id);
let isSelected = ind !== -1;
return (
<div
key={userGroup.id}
className={`
<Text className="mb-3">
{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}
</>
)}
</Text>
<FieldArray
name="groups"
render={(arrayHelpers: ArrayHelpers) => (
<div className="flex gap-2 flex-wrap mb-4">
{userGroups.map((userGroup: UserGroup) => {
const ind = formikProps.values.groups.indexOf(
userGroup.id
);
let isSelected = ind !== -1;
return (
<div
key={userGroup.id}
className={`
px-3
py-1
rounded-lg
@ -134,31 +136,32 @@ export const IsPublicGroupSelector = <T extends IsPublicGroupSelectorFormType>({
cursor-pointer
${isSelected ? "bg-background-strong" : "hover:bg-hover"}
`}
onClick={() => {
if (isSelected) {
arrayHelpers.remove(ind);
} else {
arrayHelpers.push(userGroup.id);
}
}}
>
<div className="my-auto flex">
<FiUsers className="my-auto mr-2" /> {userGroup.name}
onClick={() => {
if (isSelected) {
arrayHelpers.remove(ind);
} else {
arrayHelpers.push(userGroup.id);
}
}}
>
<div className="my-auto flex">
<FiUsers className="my-auto mr-2" />{" "}
{userGroup.name}
</div>
</div>
</div>
);
})}
</div>
)}
/>
<ErrorMessage
name="groups"
component="div"
className="text-error text-sm mt-1"
/>
</>
)
)}
);
})}
</div>
)}
/>
<ErrorMessage
name="groups"
component="div"
className="text-error text-sm mt-1"
/>
</>
)
))}
</div>
);
};

View File

@ -8,6 +8,7 @@ interface UserContextType {
user: User | null;
isLoadingUser: boolean;
isAdmin: boolean;
isCurator: boolean;
refreshUser: () => Promise<void>;
}
@ -17,12 +18,16 @@ export function UserProvider({ children }: { children: React.ReactNode }) {
const [user, setUser] = useState<User | null>(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 (
<UserContext.Provider value={{ user, isLoadingUser, isAdmin, refreshUser }}>
<UserContext.Provider
value={{ user, isLoadingUser, isAdmin, refreshUser, isCurator }}
>
{children}
</UserContext.Provider>
);