diff --git a/frontend/src/components/OrganizationList/OrganizationList.tsx b/frontend/src/components/OrganizationList/OrganizationList.tsx index f958bfcf..8321f388 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'; @@ -16,7 +16,17 @@ export const OrganizationList: React.FC<{ const [organizations, setOrganizations] = useState([]); const [dialogOpen, setDialogOpen] = useState(false); const history = useHistory(); - const getOrgsURL = `/v2/organizations/`; + const regionId = user?.regionId; + + 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 }, @@ -62,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); @@ -71,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);