From 51c8b87c706d740c47aa9c1c4e17d5b15f941332 Mon Sep 17 00:00:00 2001 From: nickviola Date: Wed, 13 Mar 2024 13:56:58 -0500 Subject: [PATCH] Modify getOrgsURL based on user type to filter in frontend/src/components/OrganizationList/OrganizationList.tsx --- .../OrganizationList/OrganizationList.tsx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/OrganizationList/OrganizationList.tsx b/frontend/src/components/OrganizationList/OrganizationList.tsx index 2af8d919..5b838b96 100644 --- a/frontend/src/components/OrganizationList/OrganizationList.tsx +++ b/frontend/src/components/OrganizationList/OrganizationList.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import EditNoteOutlinedIcon from '@mui/icons-material/EditNoteOutlined'; import { Organization } from 'types'; import { Alert, Box, Button, IconButton, Grid } from '@mui/material'; @@ -17,13 +17,16 @@ export const OrganizationList: React.FC<{ const [dialogOpen, setDialogOpen] = useState(false); const history = useHistory(); const regionId = user?.regionId; - let getOrgsURL: any; - if (user?.userType == 'regionalAdmin') { - getOrgsURL = `/organizations/regionId/${regionId}`; - } else { - getOrgsURL = `/v2/organizations/`; - } + const getOrgsUrl = () => { + if (user?.userType == 'regionalAdmin') { + return `/organizations/regionId/${regionId}`; + } else { + return `/v2/organizations/`; + } + }; + + const orgsUrl = getOrgsUrl() as String; const orgCols: GridColDef[] = [ { field: 'name', headerName: 'Organization', minWidth: 100, flex: 2 }, @@ -69,7 +72,7 @@ export const OrganizationList: React.FC<{ const fetchOrganizations = useCallback(async () => { try { - const rows = await apiGet(getOrgsURL); + const rows = await apiGet(orgsURL); // rows.forEach((obj) => { // // obj.userCount = obj.userRoles.length; // obj.tagNames = obj.tags.map((tag) => tag.name); @@ -78,9 +81,9 @@ export const OrganizationList: React.FC<{ } catch (e) { console.error(e); } - }, [apiGet, getOrgsURL]); + }, [apiGet, orgsURL]); - React.useEffect(() => { + useEffect(() => { if (!parent) fetchOrganizations(); else { setOrganizations(parent.children);